// JavaScript Document
var xmlHttp=null;
function Trim(str)
{
	//trim leding spaces
	while(true)
	{
		if(str.charAt(0) == ' ')
			str = str.substr(1);
		else
			break;
	}
	
	//trim trailing spaces
	while(true)
	{
		if(str.charAt(str.length-1) == ' ')
			str = str.substr(0,str.length-1);
		else
			break;
	}
	return(str);	
}

function fun_quickshow()
{
//	var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
	var pathArray = window.location.pathname.split( '/' );
	var txt;
		txt = Trim(document.getElementById('srchtxtquick').value).length;
		if (Trim(document.getElementById('srchtxtquick').value)!='' && txt>=3)
		{
			if (parseInt(pathArray.length)==2)
			{
				fun_quickdivshow('images/productsearch_ajax-loader.gif');
				data_quickshow(document.getElementById('srchtxtquick').value);
			}
			else if (parseInt(pathArray.length)>2)
			{
				fun_quickdivshow('../images/productsearch_ajax-loader.gif');
				data_quickshow2(document.getElementById('srchtxtquick').value);
			}
			
		}
		else if (Trim(document.getElementById('srchtxtquick').value)=='' && txt<=3)
		{
			document.getElementById('show').style.visibility="hidden";
			document.getElementById('show').style.position="absolute";
		}
}
function fun_quickview()
{
	document.getElementById("srchtxtquick").value="Start your product search here...";
	document.getElementById("srchtxtquick").style.color="#ccc";
	document.getElementById('show').style.visibility="hidden";
	document.getElementById('show').style.position="absolute";
	document.getElementById("srchtxtquick").blur();
}
function fun_quickviewhide()
{
	if (document.getElementById("srchtxtquick").value=="Start your product search here...")
	{document.getElementById("srchtxtquick").value="";}
	document.getElementById("srchtxtquick").style.color="#000";
	document.getElementById("srchtxtquick").focus();
}
function fun_quickdivshow(img)
{
	document.getElementById('show').style.visibility="visible";
	document.getElementById('show').style.position="absolute";
	document.getElementById('show').innerHTML="<br><br><br><div align='center'><img src='"+img+"'></div>"	
}
function fun_quickadd(nval)
{
	window.open("shopexd.asp?id="+nval,"_self");
}
function data_quickshow(val)
{
	var url;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	url="quickgetprod.asp";
	url=url+"?val="+val;
	xmlHttp.onreadystatechange=stateChangedquick88;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function data_quickshow2(val)
{
	var url;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	url="../quickgetprod.asp";
	url=url+"?val="+val;
	xmlHttp.onreadystatechange=stateChangedquick89;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function getFileName(path){
var fn = path.match(/\/([a-z0-9_-]+\.\w+)$/i);
return (fn == null)? '' : fn[fn.length-1];
}
function GetXmlHttpObject()
{
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function stateChangedquick88() 
{ 
	var divstr;
	if (xmlHttp.readyState==4)
	{ 
		var proddet;
		proddet=Trim(xmlHttp.responseText);
		document.getElementById("show").innerHTML="";
		divstr="<table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff'>";
		if (proddet=='no')
		{
			divstr=divstr+"<tr><td valign='top'><div align='right'><img src='images/close.jpg' onclick='fun_quickview();' border='0' style='cursor:hand;'><br><br><br><br></div></td></tr>";
			divstr=divstr+"<tr><td><div align='center'><br><br>Product not found</div></td></tr>";
		}
		else if (proddet!='no')
		{
			divstr=divstr+"<tr><td valign='top' colspan='5'><div align='right'><img src='images/close.jpg' onclick='fun_quickview();' border='0' style='cursor:hand;'><br></div></td></tr>";
			var splitproddet;
			splitproddet=proddet.split("<<");
			for (i=1;i<splitproddet.length-1;i++)
			{
				var splitproddet2;
				splitproddet2=splitproddet[i].split(">>");
//				alert(splitproddet2[8]);
				divstr=divstr+"<tr>";
				divstr=divstr+"<td rowspan='2'>&nbsp;</td>";
				divstr=divstr+"<td rowspan='2'><div align='center'>&nbsp;<a href='"+splitproddet2[8]+"?source=SE001' title="+splitproddet2[2]+"><img border='0' alt='"+splitproddet2[2]+"' src='"+splitproddet2[4]+"'></a>&nbsp;</div></td>";
				divstr=divstr+"<td rowspan='2'>&nbsp;</td>";
				divstr=divstr+"<td rowspan='2'>&nbsp;</td>";
				divstr=divstr+"<td class='thumbprice'><a href='"+splitproddet2[8]+"?source=SE001'><h2>"+splitproddet2[2]+"</h2></a><br>Base price  : "+splitproddet2[3]+"<br>"+splitproddet2[5]+" : "+splitproddet2[6]+"</td>";
				divstr=divstr+"</tr>";
				divstr=divstr+"<tr>";
				if(parseInt(splitproddet2[7])<=parseInt(splitproddet2[9]))
				{divstr=divstr+"<td><h3>Out of stock</h3></td>";}
				else
				{
					divstr=divstr+"<td><select class='submitbtn' name='quickQuantity"+i+"' id='quickQuantity"+i+"'>";
					for (k=1;k<=20;k++)
					{
						divstr=divstr+"<option value='"+k+"'>"+k+"</option>";
					}
					divstr=divstr+"</select>";
					divstr=divstr+"<input type='button' class='submitbtn' value='Add to Cart'  name='addtocart' onClick='quickshowproduct("+splitproddet2[0]+","+i+")'/></td>";
				}
				divstr=divstr+"</tr>";
				divstr=divstr+"<tr><td colspan='5' height='10px' bgcolor='#ffffff'></td></tr>";
				divstr=divstr+"<tr><td colspan='5' height='3px' bgcolor='#EDF6F5'></td></tr>";
			}
			
		}
		divstr=divstr+"</table>";
		document.getElementById("show").innerHTML=divstr;
		document.getElementById('show').style.visibility="visible";
		document.getElementById('show').style.position="absolute";
	}
}
function stateChangedquick89() 
{ 
	var divstr;
	if (xmlHttp.readyState==4)
	{ 
		var proddet;
		proddet=Trim(xmlHttp.responseText);
		document.getElementById("show").innerHTML="";
		divstr="<table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff'>";
		if (proddet=='no')
		{
			divstr=divstr+"<tr><td valign='top'><div align='right'><img src='../images/close.jpg' onclick='fun_quickview();' border='0' style='cursor:hand;'><br><br><br><br></div></td></tr>";
			divstr=divstr+"<tr><td><div align='center'><br><br>Product not found</div></td></tr>";
		}
		else if (proddet!='no')
		{
			divstr=divstr+"<tr><td valign='top' colspan='5'><div align='right'><img src='../images/close.jpg' onclick='fun_quickview();' border='0' style='cursor:hand;'><br></div></td></tr>";
			var splitproddet;
			splitproddet=proddet.split("<<");
			for (i=1;i<splitproddet.length-1;i++)
			{
				var splitproddet2;
				splitproddet2=splitproddet[i].split(">>");
				divstr=divstr+"<tr>";
				divstr=divstr+"<td rowspan='2'>&nbsp;</td>";
				divstr=divstr+"<td rowspan='2'><div align='center'>&nbsp;<a href='../"+splitproddet2[8]+"?source=SE001' title="+splitproddet2[2]+"><img border='0' alt='"+splitproddet2[2]+"' src='../"+splitproddet2[4]+"'></a>&nbsp;</div></td>";
				divstr=divstr+"<td rowspan='2'>&nbsp;</td>";
				divstr=divstr+"<td rowspan='2'>&nbsp;</td>";
				divstr=divstr+"<td class='thumbprice'><a href='../"+splitproddet2[8]+"?source=SE001'><h2>"+splitproddet2[2]+"</h2></a><br>Base price  : "+splitproddet2[3]+"<br>"+splitproddet2[5]+" : "+splitproddet2[6]+"</td>";
				divstr=divstr+"</tr>";
				divstr=divstr+"<tr>";
				if(parseInt(splitproddet2[7])<=parseInt(splitproddet2[9]))
				{divstr=divstr+"<td><h3>Out of stock</h3></td>";}
				else
				{
					divstr=divstr+"<td><select class='submitbtn' name='quickQuantity"+i+"' id='quickQuantity"+i+"'>";
					for (k=1;k<=20;k++)
					{
						divstr=divstr+"<option value='"+k+"'>"+k+"</option>";
					}
					divstr=divstr+"</select>";
					divstr=divstr+"<input type='button' class='submitbtn' value='Add to Cart'  name='addtocart' onClick='quickshowproduct2("+splitproddet2[0]+","+i+")'/></td>";
				}
				divstr=divstr+"</tr>";
				divstr=divstr+"<tr><td colspan='5' height='10px' bgcolor='#ffffff'></td></tr>";
				divstr=divstr+"<tr><td colspan='5' height='3px' bgcolor='#EDF6F5'></td></tr>";
			}
			
		}
		divstr=divstr+"</table>";
		document.getElementById("show").innerHTML=divstr;
		document.getElementById('show').style.visibility="visible";
		document.getElementById('show').style.position="absolute";
	}
}


//add to cart
function quickshowproduct(catalogid,qid)
{ 
	var quickQuantity="quickQuantity"+qid;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="getproduct.asp";
	url=url+"?catalogid="+catalogid;
	url=url+"&quantity="+document.getElementById(quickQuantity).value;
	url=url+"&action=insert";	
	url=url+"&sid="+Math.random();
	url=url+"&src=SE001";
	xmlHttp.onreadystatechange=stateChangedquick;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(url);
}
//add to cart
function quickshowproduct2(catalogid,qid)
{ 
	var quickQuantity="quickQuantity"+qid;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="../getproduct.asp";
	url=url+"?catalogid="+catalogid;
	url=url+"&quantity="+document.getElementById(quickQuantity).value;
	url=url+"&action=insert";	
	url=url+"&sid="+Math.random();
	url=url+"&src=SE001";
	xmlHttp.onreadystatechange=stateChangedquick2;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(url);
}
function stateChangedquick() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var a,b;
		a=xmlHttp.responseText;
		window.location.href="quickorder.asp";
	}
}
function stateChangedquick2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var a,b;
		a=xmlHttp.responseText;
		window.location.href="../quickorder.asp";
	}
}

