// JavaScript Document

function manageCompareList(pid)
{
	if(document.getElementById('cid'+pid).checked)
	{
		if(addToCompate(pid)==false)
		{
			document.getElementById('cid'+pid).checked = false;
		}
	}
	else
	{
		RemoveFromCompate(pid);
	}
	
}


function addToCompate(prod_id)
{	
//Session("x") = 'me';
	//alert(Session("Id"));
	var StrMsg = "Sorry! We can't complete your request. \nThe following information is incomplete or missing:\n";
	var numberOfProd = document.getElementById('noOfProd').value;
	var productsIds = document.getElementById('products_ids').value;
	
	if(productsIds!="") {
		var productAdded_ids = productsIds.split(':');
		if(productAdded_ids.length>3)
		{
			var msg="Sorry! We can't complete your request.\n You are not allowed to compare more than 4 results:\n";
				alert(msg);
				return false;
		}
		for(var i=0; i < productAdded_ids.length; i++)
		{
			if(productAdded_ids[i]==prod_id) {
				var msg="\nYou have already added this product to your compare list.";
				alert(StrMsg+ msg);
				return false;
			}
		}
	}
	
	if((numberOfProd!="") && (productsIds!="")) {
		
		numberOfProd = parseInt(numberOfProd) + 1;
		productsIds = productsIds +':' + prod_id;
	} else {
		
		numberOfProd = 1;
		productsIds = prod_id;
	}
	
	document.getElementById('products_ids').value = productsIds;
	//document.getElementById('add_id'+prod_id).style.display = 'none';
	//document.getElementById('del_id'+prod_id).style.display = '';
	
	//make XML object 
	var xmlHttp = getXMLObject(); 
	if(xmlHttp)
	{  
		url="setBasket_ids.php?ids="+productsIds;
		url= url +'&rand='+Math.random();
		xmlHttp.onreadystatechange=function()
		{
			if((xmlHttp.readyState==4) && (xmlHttp.status == 200))
			{
				
				IdsUupdateChanged(xmlHttp.responseText);
				
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function IdsUupdateChanged(result)
{   
	var arr = result.split(':');
	var len = arr.length;
	
	document.getElementById('noOfProd').value = len;
	
}
// function to remove id from compare list
function RemoveFromCompate(prod_id)
{
	var StrMsg = "Sorry! We can't complete your request. \nThe following information is incomplete or missing:\n";
	var numberOfProd = document.getElementById('noOfProd').value;
	var productsIds = document.getElementById('products_ids').value;
	var productsIdsnew = "";
	
	if(productsIds!="") {
		var productAdded_ids = productsIds.split(':');
		
		for(var i=0; i < productAdded_ids.length; i++)
		{
			if(productAdded_ids[i]!=prod_id) {
				if(productsIdsnew!="")
					productsIdsnew =  productsIdsnew + ':' +productAdded_ids[i];
				else
					productsIdsnew = productAdded_ids[i];
				
			}
			
		}
	}
	
	if(numberOfProd!=1)
		numberOfProd = parseInt(numberOfProd) - 1;
	else
		numberOfProd = "";
	
	//document.getElementById('noOfProd').value = numberOfProd;
	document.getElementById('products_ids').value = productsIdsnew;
	
	//document.getElementById('add_id'+prod_id).style.display = '';
	//document.getElementById('del_id'+prod_id).style.display = 'none';
	//make XML object 
	var xmlHttp = getXMLObject(); 
	if(xmlHttp)
	{  
		url="setBasket_ids.php?ids="+productsIdsnew;
		url= url +'&rand='+Math.random();
		xmlHttp.onreadystatechange=function()
		{
			if((xmlHttp.readyState==4) && (xmlHttp.status == 200))
			{
				IdsUupdateChanged(xmlHttp.responseText);
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
	
	
}

function checkNoProduct()
{
	var StrMsg = "Sorry! We can't complete your request. \nThe following information is incomplete or missing:\n";
	var msg="\nAt least two product should be selected for its comparision.";
	var queryString;
	
	var noOfProd = document.getElementById('noOfProd').value;
	var products_ids = document.getElementById('products_ids').value;
	if((noOfProd=="") || (noOfProd==1))
	{
		alert(StrMsg+msg);
		return false;
	}
	else
	{
		var prod_ids = products_ids.split(':');
		for(var i=0; i< prod_ids.length; i++) {
		
			if(i==0) {
				queryString = "?products_id"+i+"="+prod_ids[i];
			} else {
				queryString += "&products_id"+i+"="+prod_ids[i];
			}
		}
		
		window:location.href="compared_products.php"+queryString;
		return true;
	}
	
}

function getFeaturedProduct(value) {
	
	  if(document.getElementById(value).style.visibility != "hidden") {
			
			document.getElementById(value).style.visibility = "hidden";
			document.getElementById(value).style.display = "none";
	  }
	  else if(document.getElementById(value).style.visibility == "hidden") {
	   
		document.getElementById(value).style.visibility = "visible";
		document.getElementById(value).style.display = "block";
	  }
}

function getPriceList(list)
{
	 if(document.getElementById(list).style.visibility != "hidden") {
			
			document.getElementById(list).style.visibility = "hidden";
			document.getElementById(list).style.display = "none";
	  }
	  else if(document.getElementById(list).style.visibility == "hidden") {
	   
		document.getElementById(list).style.visibility = "visible";
		document.getElementById(list).style.display = "block";
	  }
}

function hideAll(noOfCat)
{
	var prod_id;
	for(var i=1; i < noOfCat+1; i++)
	{
			prod_id = document.getElementById('id'+i).value;
			document.getElementById(prod_id).style.display='none';
			document.getElementById(prod_id).style.visibility='hidden';
	}
}
function showAll(noOfCat)
{
	var prod_id;
	for(var i=1; i< noOfCat+1; i++)
	{  
			prod_id = document.getElementById('id'+i).value;
			document.getElementById(prod_id).style.display='block';
			document.getElementById(prod_id).style.visibility='visible';
	}
}


function changeColor(no)
{
	var no_feat;
	
	no_feat = document.getElementById('totfea').value;
	
		for(var j=0; j<no_feat; j++)
		{
			var flag = "";var flag1 = "";
			for(var n=0; n<no; n++)
			{
				
					flag = document.getElementById('d'+n+'_'+j).innerHTML;
					
					if(flag!=""&&(flag!=flag1)&&flag1!="")
					{
						for(var m=0; m<no; m++)
						{
							document.getElementById('d'+m+'_'+j).style.backgroundColor = "#FFFCCC";
							
						}
						   document.getElementById('highlight_row').value = "yes";
					}
					
					var flag1 = flag;
					
			}
		}
		document.getElementById('highlight').style.display = 'none';
		document.getElementById('hide').style.display = '';
	
	
}

function colorRemove(no)
{
	var no_feat = document.getElementById('totfea').value;
	for(var j=0; j<no_feat; j++)
	{
		for(var m=0; m<no; m++)
		{
			if(m%2==0)
				document.getElementById('d'+m+'_'+j).style.backgroundColor = "#FFFFFF";
			else
				document.getElementById('d'+m+'_'+j).style.backgroundColor = "#F6F6F6";
			
		}
	}
	document.getElementById('highlight_row').value = "";
	document.getElementById('highlight').style.display = '';
	document.getElementById('hide').style.display = 'none';
	
}
