function init(ids, pageval, main_auc_ids, key)
{
	refreshID=setInterval("setAuctionsvalues('"+ids+"','"+pageval+"','"+main_auc_ids+"','"+key+"')",1000);
}


function setAuctionsvalues(index_auctions, page_name, main_auc_ids)
{
        var auctions = '';
        $('.timer_info').each(function(){
            var auctionId    = $(this).attr('id');
            auctions = auctions + auctionId + '#' + $('#'+auctionId).html() + '#'+$(this).attr('title')+'|';
        });
        $('.timer_info').each(function(){
            var id    = $(this).attr('id');
            enddate = $('#'+id).html();
            curdate=$(this).attr('title');//alert(enddate);
            updateClock (enddate,curdate,'pauction_'+id);
        });

        $.post(baseUrl+'auction_data.php', { all_auctions: auctions , mainAucId: main_auc_ids, pg_name: page_name} , function(data)
        {
             //splitting the values
             auctions=data.split('|');
             for(i=0;i<=auctions.length;i++)
             {

                     if(auctions[i] != undefined)
                     {
                            auc_det=auctions[i].split("#");
                            if(auc_det[1]=="no_update")
                            {
if($.trim($('#item_price_'+$.trim(auc_det[2])).html())!= $.trim(auc_det[3]) && $.trim($('#item_price_'+$.trim(auc_det[2])).html())!='0.00')
{
        runEffect('#item_price1_'+$.trim(auc_det[2]));
}
                                    //alert(auc_det);
                                    $('#item_price_'+$.trim(auc_det[2])).html(auc_det[3]);   //for fixed $ 1.00 auction
                                    $('#bidder_name_'+$.trim(auc_det[2])).html(auc_det[4]);
                                    $('#item_timer_'+$.trim(auc_det[2])).html(auc_det[5]);
                                    //$('#'+$.trim(auc_det[2])).html(auc_det[6]);

                                    //timer gone red at last 10 sec
                                    if(auc_det[5]<'00:00:10')
                                            $('#item_timer_'+$.trim(auc_det[2])).css({color:"#FF0000"});

                                   if(auc_det[5]=="Paused")
                                        $('#pauseAuction_'+$.trim(auc_det[2])).hide();
                                   else $('#pauseAuction_'+$.trim(auc_det[2])).show();
                                   if(auc_det[5]=="Ended" && auc_det[2]!=main_auc_ids)
                                            $('#bid_btn_'+$.trim(auc_det[2])).html("<img src='"+baseUrl+"images/sold_1.jpg'>");

                            }
                            else
                            {
                                    if(auc_det[7]=="Ended")
                                            product_time="Ended";
                                    else if(auc_det[7]=="Paused")
                                            product_time="Paused";
                                    else
                                            product_time=auc_det[7];

                                    //animate bidder name
                                    $('#item_timer_'+$.trim(auc_det[0])).html(product_time);
                                    if(auc_det[7]!='Ended')
                                    {
                                            //runEffect('#pauction_'+$.trim(auc_det[0]));
                                            runEffect('#item_price1_'+$.trim(auc_det[0]));
                                    }
//alert($.trim(auc_det[1]))
if($.trim($('#item_price_'+$.trim(auc_det[0])).html())!= $.trim(auc_det[1]) && product_time!='Ended')
{
      runEffect('#item_price1_'+$.trim(auc_det[0]));
}
                                    $('#'+$.trim(auc_det[0])).html(auc_det[11]);
                                    $('#item_price_'+$.trim(auc_det[0])).html(auc_det[2]);
                                    $('#bidder_name_'+$.trim(auc_det[0])).html(auc_det[1]);

                                    if(auc_det[7]<'00:00:10')
                                            $('#item_timer_'+$.trim(auc_det[0])).css({color:"#CC0000"});


                                    if(auc_det[7]=="Ended")
                                            $('#bid_btn_'+$.trim(auc_det[0])).html("<img src='"+baseUrl+"images/sold_1.jpg'>");
                                    if(auc_det[5]=="Paused")
                                            $('#pauseAuction_'+$.trim(auc_det[2])).hide();
                                    else $('#pauseAuction_'+$.trim(auc_det[2])).show();

                                    if(auc_det[0]==main_auc_ids)
                                    {
                                            $('#auc_price_'+$.trim(auc_det[0])).html(auc_det[2]);
                                            $('#saving_'+$.trim(auc_det[0])).html(auc_det[5]);
                                            $('#total_price_'+$.trim(auc_det[0])).html(auc_det[10]);
                                            if(auc_det[8]){$('#bidhistory_'+$.trim(auc_det[0])).html(auc_det[8]);}
                                    }

                            }// end else for data not update

                     }
                 }
          });
    }


function place_bid(auc_id,user_id,bid_type,page_name)
{
	//alert("a:"+auc_id+",u"+user_id+",bt:"+bid_type+",p:"+page_name);
	if(user_id == undefined || user_id == null || user_id == '')
	{document.location.href=baseUrl+'member/signin';}
	else
	{
                $.post(baseUrl+"ajax_bidding_process", {aid: auc_id, bidType: bid_type,uid:user_id, page:page_name} , function(data)
	      	{
			//alert(data);
                        if($.trim(data)=="recharge")
                        {
                                $('#bid_error_'+auc_id).show();
                                $('#bid_error_'+auc_id).html("Insufficient Credits");
                                setTimeout("hideDive5Sec('bid_error_"+auc_id+"')", 3000);
                        }
                        else if($.trim(data)=="already_winner")
                        {
                                //alert(data);
                                $('#bid_error_'+auc_id).show();
                                $('#bid_error_'+auc_id).html("You are the current winner");
                                setTimeout("hideDive5Sec('bid_error_"+auc_id+"')", 3000);
                        }
                        else
                        {
                                //alert(data);
                                if(data=="Ended")
                                {
                                        $('#item_timer_'+$.trim(auc_id)).html("Ended");  //ended
                                        $('#bid_now_bttn_'+$.trim(auc_id)).html("<img src='"+baseUrl+"images/sold_1.jpg'>");  //Sold
                                }
                                else
                                {

                                        auctions=data.split('#');

                                         $('#item_price_'+$.trim(auctions[0])).html(auctions[1]);
                                         $('#bidder_name_'+$.trim(auctions[0])).html(auctions[2]);
                                         $('#user_bid_balance').html(auctions[3]);

                                }
                        }

                 });
	}
}


function book_bidbutler(form)
{
	var uid=form.uid.value;
	var aid=form.aid.value;
	var no_bid=form.no_bids.value;
	var job=form.job.value;
	var bidButler_id=form.bidbuttler_id.value;
	//alert('uid='+uid+'aid='+aid+'no_bid='+no_bid+'job='+job);
	//alert('uid'+uid+'aid'+aid+'b_from'+b_from+'b_to'+b_to+"no_bid"+no_bid+"job"+job+"bidButler_id"+bidButler_id);

	 if (uid == '' || uid == undefined || uid == null)
	 {return false;}
	 else if(aid == '' || aid == undefined || aid == null)
	 {return false;}


	$.post(baseUrl+"book_bidbutler", { user_id: uid, auc_id: aid, no_bids: no_bid, action:job,bidButtlerId:bidButler_id } , function(data)
        {
                butler_msg=data.split('#');
                if($.trim(butler_msg[0])=="error")
                {
                        // alert(data);
                        $('#bidbutller_msg').html(butler_msg[1]);
                        $('#bid_butler_erro').show();
                }
                if($.trim(butler_msg[0])=="success")
                {
                        $('#bidbutller_msg').html(butler_msg[1]);
                        $('#bid_butler_erro').show();
                        bidbutlerHistory(aid,uid);
                         $('#book_autobid').hide();
                         $('#bookbutleroverview').show();
                }
          });

	return false;
}


function bidbutlerHistory(aid,uid)
{

        $.post(baseUrl+"ajax_bidbutler_overview", {user_id: uid, auc_id: aid} , function(data)
        {
                 //alert(data);
                if (data != '' || data != undefined || data != null)
                {
                        $('#bookbutleroverview').html(data);
                }
        });

}


function ajaxPopup(auc_id,remind_time)
{

        $.post(baseUrl+"ajax_auction_data/get_pop_up", {auction:auc_id, reminder:remind_time} , function(data)
        {
                document.getElementById("Panel_Dialogs").innerHTML = data;
                document.getElementById("background_Dialogs").style.display = 'inline';
                document.getElementById("Panel_Dialogs").style.visibility = 'hidden';
                document.getElementById("Panel_Dialogs").style.display = 'inline';

                var centerLeft		= 0
                var centerTop		= 0

                var centerLeft = getScrollX() + (getWinWidth() / 2) - (document.getElementById('Dialog_Paneel').clientWidth / 2);
                var centerTop =	getScrollY() + (getWinHeight() / 2) - (document.getElementById('Dialog_Paneel').clientHeight / 2);

                if (centerLeft < 0) { centerLeft = 0 }
                if (centerTop < 0) { centerTop = 0 }

                document.getElementById("Dialog_Paneel").style.left = (centerLeft) + 'px';
                document.getElementById("Dialog_Paneel").style.top = (centerTop) + 'px';
                document.getElementById("Panel_Dialogs").style.visibility = 'visible'

                // FIX voor IE6 waardoor onderliggende formulier elementen niet doorslaan
                document.getElementById("background_Frame_Dialogs").style.left = (centerLeft) + 'px';
                document.getElementById("background_Frame_Dialogs").style.top = (centerTop) + 'px';
                document.getElementById("background_Frame_Dialogs").style.width = (document.getElementById('Dialog_Paneel').clientWidth+2) + 'px';
                document.getElementById("background_Frame_Dialogs").style.height = (document.getElementById('Dialog_Paneel').clientHeight+2) + 'px';
                document.getElementById("background_Frame_Dialogs").style.display = 'inline'
      });
}


// returns height of window
function getWinHeight() {
	var winHt = 0;
	if (window.innerHeight) winHt = window.innerHeight-18;
	else if (document.documentElement && document.documentElement.clientHeight)
		winHt = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		winHt = document.body.clientHeight;
	return winHt;
}

// returns height of window
function getWinWidth() {
	var winWd = 0;
	if (window.innerWidth) winWd = window.innerWidth-18;
	else if (document.documentElement && document.documentElement.clientWidth)
		winWd = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		winWd = document.body.clientWidth;
	return winWd;
}

// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop)
		sy = document.body.scrollTop;
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// returns amount of vertical scroll
function getScrollX() {
	var sx = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		sx = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft)
		sx = document.body.scrollLeft;
	else if (window.pageXOffset)
		sx = window.pageXOffset;
	else if (window.scrollX)
		sx = window.scrollX;
	return sx;
}

function ajaxClosePopup() {
        $("#background_Dialogs").fadeOut(200);
        document.getElementById("Panel_Dialogs").innerHTML = '';
	//document.getElementById("background_Dialogs").style.display = 'none'
	document.getElementById("Panel_Dialogs").style.display = 'none'
	document.getElementById("background_Frame_Dialogs").style.display = 'none'

}

function delete_bidbutler(bidButtlerId)
{

        if(confirm("Are you sure to stop?"))
        {

        $.post(baseUrl+"ajax_bidbutler_overview/delete_bidbutler", {buttlerId: bidButtlerId} , function(data)
        {
                    butler_msg=data.split('#');

                    if($.trim(butler_msg[0])=="success")
                    {
                            $('#bookbutleroverview').html(butler_msg[1]);
                            $('#bookbutleroverview').show();
                    }
        });
        }
	else{return false}
}


//run the currently selected effect
function runEffect(id)
{
	$(id).effect("highlight",{color:"#FFD93F"},500,callback);
}

//callback function to bring a hidden box back
function callback(){
	setTimeout(function(){
		$("#effect:hidden").removeAttr('style').hide().fadeIn();
	}, 100);
}

function hideDive5Sec(divid)
{
	$('#'+divid).hide();
}

function auctionWatchlist(id)
{
        $.post(baseUrl+"ajaxauctiondata/add_to_watchlist", {auction_id: id} , function(data)
        {
                    watch_msg=data.split('<|>');
                    $.colorbox({initialWidth:"600px", initialHeight: "120px", width:"600px", height:"120px", html:watch_msg[1]});

        });
    
}

function subscription()
{
        id = $("#subscribe_email").val();
        $.post(baseUrl+"ajaxauctiondata/newsletter", {email: id} , function(data)
        {
                    subscribe_msg=data.split('<|>');
                    $.colorbox({initialWidth:"600px", initialHeight: "120px", width:"600px", height:"120px", html:subscribe_msg[1]});

        });

}
