
// ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------
// This software is copyright ? 2006 onwards by soniktechnologies.in
// Sonik Technologies Pvt Ltd - technical internet software security strategy consultants
// 
// Intellectual property rights and copyright title are vested with Sonik Technologies.
// Title to copyright in this software and any associated documentation will at all times //remain
// with the copyright holder.
// 
// This source file may contain confidential information or data and may be Legally //Privileged.
// Reproduction is not authorised without prior written agreement from the copyright holder.
// 
// Originally developed by Nischal Soni  (nischal.soni@gmail.com).
// www.soniktechnologies.in
// ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ ------

var doc = null;

var Extend_timer = new Array(); 
var Extend_status = new Array();
var Old_Bidcounter = new Array();
var Auction_ids=0;
var Product_id=0;
var Pagename='';
var Timer_color="";  
	
var Flashing_timer=0;
var Lang_path="";
var SITE_URL="";  
var end="";
var SESS_ID=0;

function ajax() {
	// Make a new XMLHttp object

    if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
}

function Update_Bid_Detail()
{	
	 var doc=null;
	 	 if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
	
	
	doc.open('GET', "./timer_location.php?section=update_bid&Runngin_list="+Auction_ids+"&Product_id="+Product_id, true); 	
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');        
  
	doc.onreadystatechange = function() { 
			
	if(doc.readyState == 4)
		{
		if(doc.status == 200)
			{ 
			if(doc.responseText!='')
				{
				var arraylist=doc.responseText.split("|@|");
				for(var l=0;l<arraylist.length;l++)
					{
						var arraylist1=arraylist[l].split("**");
						var pro_id =(parseInt(arraylist1[0]));
						
						if(Extend_status[pro_id]!=arraylist1[1])
							Update_status(pro_id);
					
						if(Old_Bidcounter[pro_id]!=parseInt(arraylist1[2]))
							{
							Old_Bidcounter[pro_id]=parseInt(arraylist1[2]);
							
							if(SESS_ID!='0')
								Update_credits();								
								
							Update_Auction_Detail(pro_id);
							
							
							if(Product_id!=0 && pro_id==Product_id)
								Update_bid_table();
					
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 10);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 70);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 130);	
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 200);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 270);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 330);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 400);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 470);
							setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = ""', 530);
						
							}	
						}
		
		}}}}; 
		
	 setTimeout('Update_Bid_Detail()', 3000); 
     doc.send(null);
}


function Run_timer()
{
	if(Auction_ids!='0')
		{
		var arraylist=Auction_ids.split(",");
			
		for(l=0;l<arraylist.length;l++)
		{	 
			var pro_id =(parseInt(arraylist[l]));
			
				
			if(Extend_timer[pro_id]>0)
				{
					
				if(Extend_status[pro_id]=="E")
					{
						
						
		if(Extend_timer[pro_id]<=Flashing_timer)	
		document.getElementById('counter_index_div_'+pro_id).innerHTML="<font color='"+Timer_color+"'>"+calc_counter_from_time_short(Extend_timer[pro_id])+"</font>";
		else	
		document.getElementById('counter_index_div_'+pro_id).innerHTML = "<font color='#560000'>" + calc_counter_from_time_short(Extend_timer[pro_id]) + "</font>";			
					}
				else if(Extend_status[pro_id]=="N")
					document.getElementById('counter_index_div_'+pro_id).innerHTML = '' + calc_counter_from_time(Extend_timer[pro_id]);
				else if(Extend_status[pro_id]=="P")
					{
					document.getElementById('bid_btn_'+pro_id).innerHTML = "<a><b>Pause</b></a>";
					}
				else if(Extend_status[pro_id]=="S")	
					{
							Extend_status[pro_id]='Y';
					document.getElementById('counter_index_div_'+pro_id).innerHTML = "<font size='2'><b>Waiting..</b></font>";
							setTimeout('Expire_extend_bid('+pro_id+')', 5000);	
					}	
				}
			else
				{
				if(Extend_status[pro_id]=="N")	
					{
					Extend_status[pro_id]='E';		
					Expire_home_bid(pro_id);
					}
				else if(Extend_status[pro_id]=='E')
					{
					
					document.getElementById('counter_index_div_'+pro_id).innerHTML = "<font size='2'><b>Waiting..</b></font>";
					setTimeout('Expire_extend_bid('+pro_id+')', 5000);
					}
				else if(Extend_status[pro_id]=="P")
					{
					document.getElementById('bid_btn_'+pro_id).innerHTML = "<a><div>Pause</div></a>";
					}
				}
				Extend_timer[pro_id]=(Extend_timer[pro_id]-1);	
			}
		}
		setTimeout('Run_timer();', 950); 
	}

function Run_timer_Product()
{
		
	if(Auction_ids!='0')
		{
		var arraylist=Auction_ids.split(",");
			
		for(l=0;l<arraylist.length;l++)
		{	 
			var pro_id =(parseInt(arraylist[l]));
		
			if(Extend_timer[pro_id]>0)
				{
				if(Extend_status[pro_id]=="E")
					{
						
					if(Extend_timer[pro_id]<=Flashing_timer)
						{
						if(Product_id==Extend_timer[pro_id])
						document.getElementById('flashing_index_div_'+pro_id).innerHTML = '<img src="images/'+Lang_path+'/blink.gif" boder="0">';
				
		document.getElementById('counter_index_div_'+pro_id).innerHTML="<font color='"+Timer_color+"'>"+calc_counter_from_time_short(Extend_timer[pro_id])+"</font>";
						}
					else
						{
							if(Product_id==Extend_timer[pro_id])
							document.getElementById('flashing_index_div_'+pro_id).innerHTML = '';	
				document.getElementById('counter_index_div_'+pro_id).innerHTML = "<font color='#560000'>" + calc_counter_from_time_short(Extend_timer[pro_id]) + "</font>";				}
					}
				else if(Extend_status[pro_id]=="N")
				document.getElementById('counter_index_div_'+pro_id).innerHTML = '' + calc_counter_from_time(Extend_timer[pro_id]);
				else if(Extend_status[pro_id]=="P")
						{
						
							document.getElementById('bid_btn_'+pro_id).innerHTML = "<a><div>Pause</div></a>";
							document.getElementById('counter_index_div_'+pro_id).innerHTML = "<b>--:--:--</b>";
						}
				else if(Extend_status[pro_id]=="S")	
					{
							Extend_status[pro_id]='Y';
					document.getElementById('counter_index_div_'+pro_id).innerHTML = "<font size='2'><b>Waiting..</b></font>";
							setTimeout('Expire_extend_bid('+pro_id+')', 5000);	
					}
					}
				else
					{
					if(Extend_status[pro_id]=="N")	
						{
						Extend_status[pro_id]='E';	
						Expire_home_bid(pro_id);
				    	
						}
					else if(Extend_status[pro_id]=='E')
						{
							
								document.getElementById('flashing_index_div_'+pro_id).innerHTML = '';
							
							
							document.getElementById('counter_index_div_'+pro_id).innerHTML = "<font size='2'><b>Waiting..</b></font>";
							setTimeout('Expire_extend_bid('+pro_id+')', 5000);
						}
					else if(Extend_status[pro_id]=="P")
						{
						
							document.getElementById('bid_btn_'+pro_id).innerHTML = "<a><div>Pause</div></a>";
							document.getElementById('counter_index_div_'+pro_id).innerHTML = "<b>--:--:--</b>";
						
						}	
					
					}
					Extend_timer[pro_id]=(Extend_timer[pro_id]-1);	
			}
		}
		setTimeout('Run_timer_Product();', 950); 
	}

function Update_status(Pro_id)
{
	var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer_location.php?section=update_status&Auction_ids="+Auction_ids+"&Pro_id="+Pro_id+"&Product_id="+Product_id, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
						var Main_array=doc.responseText.split("**");	
						
						
						Extend_timer[Pro_id] = parseInt(Main_array[1]);		
							
						
						
					//	Extend_status[Pro_id]=Main_array[2];	
						
						
						if(Main_array[0]!="")	
							{
							if(Main_array[2]!='S')	
								document.getElementById('bid_btn_'+Pro_id).innerHTML = Main_array[0];	
							}
						
					}
				}
			}
	    };
	doc.send(null);
}

function Update_timer()
{
		var doc=null;
	
	if (window.XMLHttpRequest) {
    	try {
            doc = new XMLHttpRequest();
    	    } catch(e)  {}
	    } else if (window.ActiveXObject) {
    	    try {
        	    doc = new ActiveXObject('Msxml2.XMLHTTP');
		        } catch(e)  {
        	try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
		        } catch(e)  {}
	        }
  		}
		
	doc.open('GET', "./timer_location.php?section=update_timer&Runngin_list="+Auction_ids, true);
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		
	doc.onreadystatechange = function()
	   	{ 
		if(doc.readyState == 4)
			{
			if(doc.status == 200)
				{
				if(doc.responseText!=0)
					{
		  			var arraylist=doc.responseText.split("|@|");
						
					for(l=0;l<arraylist.length;l++)
						{	
						var Main_array=arraylist[l].split("**");
						var pro_id =(parseInt(Main_array[0]));
						Extend_timer[pro_id] = parseInt(Main_array[1]);
						
						
						if(Extend_status[pro_id]!=Main_array[2])
							{
								Update_status(Pro_id);	
								Extend_status[pro_id]=Main_array[2];
								
							}} 
					}
		}
				}
		  };
		 setTimeout('Update_timer();', 10000);  
     doc.send(null);
}	

function Update_Auction_Detail(Pro_id)
{	
	 var doc=null;
	 	 if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }
	
 doc.open('GET', "./timer_location.php?section=update_auction_details&Pro_id="+Pro_id+"&product_id="+Product_id, true); 	
	doc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');        
   
	doc.onreadystatechange = function() { 
			
	if(doc.readyState == 4)
		{
		if(doc.status == 200)
			{ 
			if(doc.responseText!='')
				{
				var arraylist=doc.responseText.split("**");
				
				document.getElementById('winner_index_div_'+Pro_id).innerHTML = arraylist[0];
				if(Product_id!=0 && Pro_id==Product_id)
				document.getElementById('winner_logo_index_div_'+Pro_id).innerHTML = arraylist[3];
				document.getElementById('price_index_div_'+Pro_id).innerHTML = arraylist[1];	
				Extend_timer[Pro_id] = parseInt(arraylist[2]);		
				
				
		}}}}; 

	 
     doc.send(null);
}

function Valid_username(login){
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location1.php?section=username&login="+login, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}
function CheckAvail(id_region){
		var avail=document.getElementById(id_region).value;
		
		ajax();
	    if (doc){
	       doc.open("GET", "./location1.php?section=tutoring&avail="+avail, false);
	       doc.send(null);
			if(doc.responseText==1) 
				{
				alert(document.getElementById('username_already_exist').innerHTML+"\n");
				return false;
				}
			else if(doc.responseText==2)
			 {
				alert(document.getElementById('this_username_available').innerHTML+"\n");
				return false; 
			 }
			else if(doc.responseText==3)
			 {
				alert(document.getElementById('please_enter_username').innerHTML+"\n");
				return false; 
			 } 
			else
			return true;
			 
		}	
	
	}
function CheckEmail(id_region){

		var emailadd=document.getElementById(id_region).value;
		
		ajax();
	    if (doc){
	       doc.open("GET", "./location1.php?section=availmail&emailadd="+emailadd, false);
	       doc.send(null);
	    	// Write the response to the div
			
			if(doc.responseText==1) 
				{
				alert(document.getElementById('email_already_exist').innerHTML+"\n");
				return false;
				}
		else if(doc.responseText==2)
			 {
				alert(document.getElementById('this_email_available').innerHTML+"\n");
				return false; 
			 }
			else if(doc.responseText==3)
			 {
				alert(document.getElementById('please_enter_email').innerHTML+"\n");
				return false; 
			 } 
			else
			return true;
	    }	
	
	}	


function Valid_mobile(tel){
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location1.php?section=mobile&tel="+tel, false); 
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_mobile(tel){
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location1.php?section=edit_mobile&tel="+tel, false); 
	       doc.send(null);
		  
	      return  doc.responseText;
	    }
}

function Edit_Valid_username(login){
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location1.php?section=edit_username&login="+login, false); 
	       doc.send(null);
		  
	      return  doc.responseText;
	    }
}



function Valid_email(email){
		
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location1.php?section=email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function Edit_Valid_email(email){
		
    	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location1.php?section=edit_email&email="+email, false);   
	       doc.send(null);
	      return  doc.responseText;
	    }
}

function bid_list(item_id,table_type)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location.php?section=bid_list_table&item_id="+item_id+"&table_type="+table_type, false);   
	       doc.send(null);
 			 var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="bidlist")
			document.getElementById('bidlist_table_div').innerHTML = mainarraylist[0];
			
			if(table_type=='B')
				Update_bid_table();
	    }
}

function bidbutler_list(item_id,table_type)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	   if (doc){
	       doc.open("GET", "./location.php?section=book_bidbutler_table&item_id="+item_id+"&table_type="+table_type, false);   
	       doc.send(null);
 			 var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="book_bidbulter")
			document.getElementById('book_bidbutler_table_div').innerHTML =  mainarraylist[0];

	    }
}

function get_info_drop_dowm(promotion_id){

		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location1.php?section=promotion&promotion_id=" + promotion_id, false);
	       doc.send(null);
	    	// Write the response to the div	    	
	       document.getElementById('info_div').innerHTML = doc.responseText;
	    }	
	}
	
function Update_bid_table(){
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location.php?section=update_bid_table&product_id="+Product_id, false);
		   doc.send(null);
    	// Write the response to the div

	       var mainarraylist=doc.responseText.split("|**|");
		   if(mainarraylist[2]=="BidHistory")
		   {
			   if(mainarraylist[0]==0)
					 document.getElementById('bid_table_div1').innerHTML = "There are not bid for this item.";
				else
	             document.getElementById('bid_table_div1').innerHTML = mainarraylist[0];
				 
				var arraylist3=mainarraylist[1].split("*@*");
				
					//if(arraylist3[6]=="L")
						//document.getElementById("bid_from").value = arraylist3[7];
						
					if(arraylist3[5]=="Y" || arraylist3[6]=="L")
					{
						
						document.getElementById('auction_key_div_'+Product_id).innerHTML = arraylist3[4];
						document.getElementById('place_mybid_div_'+Product_id).innerHTML = arraylist3[2];
						
						if(arraylist3[3]=='$0.00')
							document.getElementById('place_bid_div_'+Product_id).innerHTML = "Free";
						else
							document.getElementById('place_bid_div_'+Product_id).innerHTML = arraylist3[3];
					}
						
					document.getElementById('price_index1_div_'+Product_id).innerHTML = arraylist3[0];
					document.getElementById('price_save_div_'+Product_id).innerHTML = arraylist3[1];
					
		   }
		}
	}


function Update_session()
	{
		ajax();
	   if (doc){
	       doc.open("GET", "./location1.php?section=update_session", false);   
	       doc.send(null);
			}
			
		setTimeout('Update_session();', 20000);  	
	}


function Expire_home_bid(pro_id) {
    ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	
	    if (doc){
	       doc.open("GET", "./location.php?section=expire_bid&expire_bid_id="+pro_id, false);
 			doc.send(null);
			var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="expire_bid_time")
				{
				Extend_timer[pro_id] = parseInt(mainarraylist[0]);	
				}
			}
}	

function Expire_extend_bid(pro_id) {
  			
  var doc=null;
	 	 if (window.XMLHttpRequest) {
        try {
            doc = new XMLHttpRequest();
        } catch(e)  {}
    } else if (window.ActiveXObject) {
        try {
            doc = new ActiveXObject('Msxml2.XMLHTTP');
        } catch(e)  {
          try {
              doc = new ActiveXObject('Microsoft.XMLHTTP');
          } catch(e)  {}
        }
    }

	  
	   doc.open('GET', "./location.php?section=expire_extend&expire_extend_id="+pro_id, true);
        doc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');        
       doc.onreadystatechange = function()
	   	{ 
	
	 	  if (doc.readyState == 4)
		  	{
				
	           if (doc.status == 200)
				{  
				
				if(doc.responseText!='')
					{
				var arraylist=doc.responseText.split("**");
				var pro_id =(parseInt(arraylist[1]));
				var Status=trim(arraylist[0]);
				
				if(Status=="S")
					{
					Extend_status[pro_id]='Y';
				
					document.getElementById('counter_index_div_'+pro_id).innerHTML = '<font color="#560000"><b>END</b></font>' ;
					document.getElementById('bid_btn_'+pro_id).innerHTML = "<div><a><font color='#fff'><b>SOLD</b></font></a></div>";
					
					if(pro_id==Product_id)	
					{
						Congratulation_auction(pro_id); 
						Show_buy_auction(pro_id);
					}						
						 setTimeout('window.location.reload();', 30000);					
					}
				else if(Status=="C")
					{
						Extend_status[pro_id]='Y';
					document.getElementById('counter_index_div_'+pro_id).innerHTML = '<font color="#560000"><b>Cancelled</b></font>' ;
					if(pro_id==Product_id)	
					document.getElementById('bid_btn_'+pro_id).innerHTML = "<div style='background:url(../images/front/big_bid_btn.gif) center no-repeat;  width:200px;height:52px; font-size:14px;'>RESERVE NOT MET<br/> ALL KEYS RETURNED</div>";
					else
						document.getElementById('bid_btn_'+pro_id).innerHTML = "<div style='color:#fff; font-size:9px;'>RESERVE NOT MET</div>";
				
				document.getElementById('winner_index_div_'+pro_id).innerHTML = "No Winner";
				
					setTimeout('window.location.reload();', 30000);	
					
					}
				else
					{
					Extend_status[pro_id]='E';		
					Extend_timer[pro_id] = (parseInt(arraylist[2]));	
					}
					}
				}
			}
		}
			doc.send(null);
				
}	

function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function Start_auction() {
    ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location1.php?section=start_auction", false);
		   	doc.send(null);
			}
}


function add_to_watchlist(item_id){

	ajax();
	    if (doc){
	       doc.open("GET", "./location1.php?section=add_to_watchlist&item_id=" + item_id, false);
		   	doc.send(null);
			
			if(doc.responseText!='')
				alert(doc.responseText);
			}
}
	
	function calc_counter_from_time(diff) 
{
  if (diff > 0) {
	days=Math.floor(diff / (3600*24));
    hours=Math.floor((diff / 3600)-(days*24));
	//  hours=Math.floor((diff / 3600));
    minutes=Math.floor((diff / 3600 - hours -(days*24)) * 60);
    seconds=Math.round((((diff / 3600 - hours-(days*24)) * 60) - minutes) * 60);
  } else {
	days=0;
    hours = 0;
    minutes = 0;
    seconds = 0;
  }

  if (seconds == 60) {
    seconds = 0;
  }

  if (minutes < 10) {
    if (minutes < 0) {
      minutes = 0;
    }
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    if (seconds < 0) {
      seconds = 0;
    }
    seconds = '0' + seconds;
  }
  if (hours < 10) {
    if (hours < 0) {
      hours = 0;
    }
    hours = '0' + hours;
  }
  
	if(days>0)
 		return days + "D " + hours + ":" + minutes + ":" + seconds;
	else
	 	return hours + ":" + minutes + ":" + seconds;
}

/*
	function calc_counter_from_time(diff) 
{

  if (diff > 0) {
	days=Math.floor(diff / (3600*24));
		  
    hours1=Math.floor((diff / 3600)-(days*24));
	  hours=Math.floor((diff / 3600));			
    minutes=Math.floor((diff / 3600 - hours1 -(days*24)) * 60);
	
    seconds=Math.round((((diff / 3600 - hours1-(days*24)) * 60) - minutes) * 60);
  } else {
	days=0;
    hours = 0;
    minutes = 0;
    seconds = 0;
  }

  if (seconds == 60) {
    seconds = 0;
  }

  if (minutes < 10) {
    if (minutes < 0) {
      minutes = 0;
    }
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    if (seconds < 0) {
      seconds = 0;
    }
    seconds = '0' + seconds;
  }
  if (hours < 10) {
    if (hours < 0) {
      hours = 0;
    }
    hours = '0' + hours;
  }
  

  return hours + ":" + minutes + ":" + seconds;
 }
 
 */


function calc_counter_from_time_short(diff) {

  if (diff > 0) {
    hours=Math.floor(diff / 3600)

    minutes=Math.floor((diff / 3600 - hours) * 60)

    seconds=Math.round((((diff / 3600 - hours) * 60) - minutes) * 60)
  } else {
    hours = 0;
    minutes = 0;
    seconds = 0;
  }

  if (seconds == 60) {
    seconds = 0;
  }

  if (minutes < 10) {
    if (minutes < 0) {
      minutes = 0;
    }
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    if (seconds < 0) {
      seconds = 0;
    }
    seconds = '0' + seconds;
  }
  if (hours < 10) {
    if (hours < 0) {
      hours = 0;
    }
    hours = '0' + hours;
  }

  return minutes + ":" + seconds;
}
		


function Add_bid(pro_id) {
	
	
		ajax();
	    if (doc){
			Extend_timer[pro_id]=(Extend_timer[pro_id]+1);
	       doc.open("GET", "./location.php?section=add_bid&add_bid_id="+pro_id+"&extend_timer="+Extend_timer[pro_id], false);
 			doc.send(null);
			if(parseInt(doc.responseText)==99999)
				document.location="login.html";
			else
				{
					
					
				var mainarraylist=doc.responseText.split("**");
				if(mainarraylist.length>3)
					{
					Old_Bidcounter[pro_id]=mainarraylist[3];	
															
					Update_Auction_Detail(pro_id);
							
					if(Product_id!=0)
						Update_bid_table();
					
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 10);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 70);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 130);	
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 200);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 270);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 330);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 400);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = "'+Timer_color+'"', 470);
					setTimeout('document.getElementById("price_index_div_'+pro_id+'").style.backgroundColor = ""', 530);	
					
					document.getElementById('div_blance').innerHTML = mainarraylist[1];
					}
				else
					{
					if(mainarraylist[1]=="ADDBID")	
						alert(trim(mainarraylist[0]));
					}
				}
			}
		}

 

function showdisplay(item_id){

	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location1.php?section=show_detail&item_id=" + item_id, false);
		   	doc.send(null);
			document.getElementById('auction_detail_'+parseInt(item_id)).innerHTML = doc.responseText;
					
			}
}

function hidedisplay(item_id){

document.getElementById('auction_detail_'+parseInt(item_id)).innerHTML = '';

}


function hidedisplay_auctiontype(div_id){
  el = document.getElementById(div_id);

  if (div_id == 'help_AUCTIONS_FLAG_1_CENT')
  {
    if (document.getElementById('help_AUCTIONS_FLAG_CLICK_ONLY'))
  {
    document.getElementById('help_AUCTIONS_FLAG_CLICK_ONLY').style.display = "none";
  }
  if (document.getElementById('help_AUCTIONS_FLAG_INTERNATIONAL'))
  {
    document.getElementById('help_AUCTIONS_FLAG_INTERNATIONAL').style.display = "none";
  }
  }
  if (div_id == 'help_AUCTIONS_FLAG_CLICK_ONLY')
  {
    if (document.getElementById('help_AUCTIONS_FLAG_1_CENT'))
  {
    document.getElementById('help_AUCTIONS_FLAG_1_CENT').style.display = "none";
  }
  if (document.getElementById('help_AUCTIONS_FLAG_INTERNATIONAL'))
  {
    document.getElementById('help_AUCTIONS_FLAG_INTERNATIONAL').style.display = "none";
  }
  }
  if (div_id == 'help_AUCTIONS_FLAG_INTERNATIONAL')
  {
    if (document.getElementById('help_AUCTIONS_FLAG_CLICK_ONLY'))
  {
    document.getElementById('help_AUCTIONS_FLAG_CLICK_ONLY').style.display = "none";
  }
  if (document.getElementById('help_AUCTIONS_FLAG_1_CENT'))
  {
    document.getElementById('help_AUCTIONS_FLAG_1_CENT').style.display = "none";
  }
  }

  if (el) {
    if (el.style.display == "none") {
      el.style.display = "";

    } else {
      el.style.display = "none";
    }
  }
}

function Congratulation_auction(item_id)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location.php?section=congratulation_auction&item_id="+item_id, false);
 			doc.send(null);
            var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="congraulation")
			document.getElementById('congratulation_auction_div_'+parseInt(item_id)).innerHTML = mainarraylist[0];
		}
	
}

function showzoomdisplay(item_id){

	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location1.php?section=showzoomdisplay&item_id=" + item_id, false);
		   	doc.send(null);
			document.getElementById('zoom_img_'+parseInt(item_id)).innerHTML = doc.responseText;
					
			}
}


function Update_credits() {
    ajax();
	  if (doc){
	       doc.open("GET", "./timer_location.php?section=update_credits", false);
 			doc.send(null);
				
			var mainarraylist=doc.responseText.split("|**|");
		   if(mainarraylist[1]=="update_balance")
		     document.getElementById('div_blance').innerHTML = mainarraylist[0];
		  }
	}

function hidezoomdisplay(item_id){

document.getElementById('zoom_img_'+parseInt(item_id)).innerHTML = '';

}

function Show_product_details(URL)
	{
	document.location=URL;
	}


function Resize_auction(Proid)
	{
	if(document.getElementById('aution_box_'+Proid).style.display=="block")
		{
		document.getElementById('aution_box_'+Proid).style.display="none";	
		document.getElementById('Aution_img_'+Proid).src="images/mainsite/minimize.jpg";
		}
	else
		{
		document.getElementById('aution_box_'+Proid).style.display="block";	
		document.getElementById('Aution_img_'+Proid).src="images/mainsite/maximize.jpg";	
		}
	
	}
	
function web_end_Bid() {
    ajax();
	
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location.php?section=web_close_bid", false);
 			doc.send(null);
			}
}	

  function do_empty(sel_id){
		document.getElementById(sel_id).value="";
	}
	function do_default(sel_id,text_val){
		if(document.getElementById(sel_id).value=="")
			document.getElementById(sel_id).value =text_val;
	}
function validation(frm)
{
	var error=0;
	var message="";
if(frm.login.value=="" || frm.login.value=="User Name")
    {		
       if(error==0)
	     frm.login.focus();
       message=message+document.getElementById('login_alert').innerHTML+"\n";
	   error=1;
	}
  if(frm.pass.value=="" || frm.pass.value=="Password")
    {		
       if(error==0)
	     frm.pass.focus();
       message=message+document.getElementById('pass_exists').innerHTML+"\n";
	   error=1;
	}
	if(message)
 	  {	  
	    alert(message);
		return false;
	   }
	   else
	   {	
	   		document.loginform.submit();
			return true;
	   }
	}
	
	function validation_friend(frm)
	{
	var error=0;
	var message="";
	
	if(frm.friend_email.value=="" || frm.friend_email.value=="FRIEND EMAIL")
		{		
		   if(error==0)
			 frm.friend_email.focus();
		   message=message+document.getElementById('friend_email_alert').innerHTML+"\n";
		   error=1;
		}
	else
		{
			var frmEmail1 =frm.friend_email.value.toLowerCase();	
			var frmEmailformat = /^[^@\s]+@([-a-z0-9]+\.)+([a-z]{2}|com|net|edu|org|gov|mil|int|biz|pro|info|arpa|aero|coop|name|museum)$/;
			if (!frmEmailformat.test(frmEmail1)) 
			{
				if(error!=1)
					frm.friend_email.focus();
				message=message+document.getElementById('friend_email_check').innerHTML+"\n";		
				error=1;
			}
			else
			{ 
			var ret2=Valid_email(frm.friend_email.value); 
			if(ret2==1)
				{
				if(error!=1)
					frm.friend_email.focus();
					message=message+document.getElementById('email_exists').innerHTML+"\n";
					error=1;	
				}
			}
		}
	   if(message)
 	  {	  
	    alert(message);
		return false;
	   }
	   else
	   {	
	   		document.tellfriend.submit();
			return true;
	   }
	}
	
function showFAQdetails(faqid)
	{ 
		ajax();
	   if (doc){ 
	       doc.open("GET", SITE_URL+"/location.php?section=show_faqdetails&faqid="+faqid, false);    
	       doc.send(null);
		  
		    document.getElementById('showdtid').innerHTML = doc.responseText;
			}
	}
	
function Show_buy_auction(item_id)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location.php?section=show_buy_auction&item_id="+item_id, false);
 			doc.send(null);
            var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="buy_auction")
			document.getElementById('show_buy_auction_'+parseInt(item_id)).innerHTML = mainarraylist[0];
		}
		
			Update_Buy_Detail(item_id);
}

function view_autobid(item_id)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location1.php?section=view_autobid&item_id="+item_id, false);
 			doc.send(null);
            var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="view_autobid")
			document.getElementById('edit_autobid_div').innerHTML = mainarraylist[0];
		}
}

function edit_autobid(item_id)
{
	ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
	    if (doc){
	       doc.open("GET", "./location1.php?section=edit_autobid&item_id="+item_id, false);
 			doc.send(null);
            var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[1]=="edit_autobid")
			document.getElementById('edit_autobid_div').innerHTML = mainarraylist[0];
		}
}

function Update_Buy_Detail(pro_id) {
    ajax();
	  if (doc){
	       doc.open("GET", "./location.php?section=buy_detail&buy_detail_id=" + pro_id, false);
 			doc.send(null);
			var mainarraylist=doc.responseText.split("|**|");
			
			if(mainarraylist[3]=="show_buy_bid")
			{
		     document.getElementById('bid_rebate_price_div_'+pro_id).innerHTML = mainarraylist[0];
			 document.getElementById('bid_rebate_totlaprice_div_'+pro_id).innerHTML = mainarraylist[1];
			}
		  }
		setTimeout('Update_Buy_Detail('+pro_id+');',15000); 
	}
	
function get_total_cost(quantity,amount,cid,keyid,total)
  {
	 ajax();
	  if (doc){
		    var x=1;
			var y=0;	
			var z=0;
			var new_y=0;
			var new_z=0;
			var new_exchange_value=0;
			y=quantity*amount;
			while(x<=total)
			{
			if(cid!=x)	
			{	
			if(!isNaN(new_z) && document.getElementById('total_cost_value_'+x).value!='')
			{
			new_z=new_z+parseInt(document.getElementById('total_cost_value_'+x).value);
			}
			}
			x++;
			}
			z=y+new_z;			
			new_y=z;
			new_exchange_value=new_y;
			
	       doc.open("GET", "./location.php?section=get_total_cost&quantity=" + quantity + "&keyid=" + keyid + "&new_exchange_value=" + new_exchange_value, false);
 			doc.send(null);
			var mainarraylist=doc.responseText.split("|**|");
			
			if(mainarraylist[2]=="get_total_cost")
			{
		     document.getElementById('total_cost_'+keyid).innerHTML = mainarraylist[0];
			 document.getElementById('total_key_cost_'+keyid).value = mainarraylist[1];
			 document.getElementById('total_cost_value_'+cid).value = mainarraylist[4];
			 document.getElementById('total_key').value = mainarraylist[3];
			}
		  }
  }
  
function get_exchange_cost(quantity,amount,cid,keyid,exchange_value,total)
  {
	 ajax();
	  if (doc){
			var x=1;
			var y=0;	
			var z=0;
			var new_y=0;
			var new_z=0;
			var new_exchange_value=0;
			y=quantity*amount;
			while(x<=total)
			{
			if(cid!=x)	
			{
			if(!isNaN(new_z) && document.getElementById('total_cost_value_'+x).value!='')
			{
			new_z=new_z+parseInt(document.getElementById('total_cost_value_'+x).value);
			}
			}
			x++;
			}
			z=y+new_z;			
			new_y=exchange_value-z;
			new_exchange_value=new_y;	

	       doc.open("GET", "./location.php?section=get_exchange_cost&quantity=" + quantity + "&keyid=" + keyid + "&exchange_value=" + exchange_value + "&new_exchange_value=" + new_exchange_value, false);
 			doc.send(null);
			var mainarraylist=doc.responseText.split("|**|");
			
			if(mainarraylist[2]=="get_exchange_cost")
			{
		     document.getElementById('total_cost_'+keyid).innerHTML = mainarraylist[0];
			 document.getElementById('total_cost_value_'+cid).value = mainarraylist[4];
			 document.getElementById('total_key_cost_'+keyid).value = mainarraylist[1];
			 document.getElementById('remain_key').value = mainarraylist[3];
			 if(mainarraylist[3]<0)
			 {
			 	alert(mainarraylist[5]);
				return false;
			 }
			}
		  }
  }
  
function get_exchange_cost_all(quantity,amount,cid,keyid,exchange_value,total)
  {
	 ajax();
	  if (doc){
			var x=1;
			var y=0;	
			var z=0;
			var new_y=0;
			var new_z=0;
			var new_exchange_value=0;
			y=quantity*amount;			
			while(x<=total)
			{
			if(cid!=x)	
			{
			if(!isNaN(new_z) && document.getElementById('total_cost_value_'+x).value!='')
			{
			new_z=new_z+parseInt(document.getElementById('total_cost_value_'+x).value);
			}
			}
			x++;
			}
			z=y+new_z;			
			new_y=exchange_value-z;
			new_exchange_value=new_y;	

	       doc.open("GET", "./location.php?section=get_exchange_cost_all&quantity=" + quantity + "&keyid=" + keyid + "&exchange_value=" + exchange_value + "&new_exchange_value=" + new_exchange_value, false);
 			doc.send(null);
			var mainarraylist=doc.responseText.split("|**|");
			if(mainarraylist[2]=="get_exchange_cost_all")
			{
		     document.getElementById('total_cost_'+keyid).innerHTML = mainarraylist[0];
			 document.getElementById('total_cost_value_'+cid).value = mainarraylist[4];
			 document.getElementById('total_key_cost_'+keyid).value = mainarraylist[1];
			 document.getElementById('remain_key').value = mainarraylist[3];
			 document.getElementById('total_key').value = mainarraylist[5];
			}
		  }
  }
