function validatefields()
{
	if(document.getElementById('username').value == '')
	{
		alert("Please Enter Username");
		document.getElementById('username').focus();
		return false;
	}
	if(document.getElementById('password').value == '')
	{
		alert("Please Enter Password");
		document.getElementById('password').focus();
		return false;
	}
	else
		return true;					
}

function isInteger(s)
{   var i;
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}
	
function validateuserfields()
{
	var a=document.getElementById('txtname').value;
	var c=document.getElementById('txtemail').value;
	var e=document.getElementById('txtpass').value;
	var Phone=document.check.txtphone;
	var country_code = document.check.txtcountry;
	var area_code = document.check.txtarea;

	if(document.getElementById('txtname').value=="")
	{
		alert("Please Enter the Name");
		document.getElementById('txtname').focus();
		return false;
	}
	if(c=="")
	{
		alert("Please Enter Email Address");
		document.getElementById('txtemail').focus();
		return false;
	}
	var cmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!(c.match(cmail)))
	{
		alert("Please Enter Valid Email Address");
		document.getElementById('txtemail').focus();
		return false;
	}
	if(e=="")
	{
		alert("Please Enter Password");
		document.getElementById('txtpass').focus();
		return false;
	}
	if ((country_code.value==null)||(country_code.value=="")){
		alert("Please Enter your Country code")
		country_code.focus()
		return false
	}
	if (isInteger(country_code.value)==false){
		alert("Please Enter a Valid Country code")
		country_code.value=""
		country_code.focus()
		return false
	}
	if(country_code.value.length != '2'){
		alert("Please Enter Valid Country code")
		country_code.focus()
		return false
	}
	if ((area_code.value==null)||(area_code.value=="")){
		alert("Please Enter your Area code")
		area_code.focus()
		return false
	}
	if (isInteger(area_code.value)==false){
		alert("Please Enter a Valid Area code")
		area_code.value=""
		area_code.focus()
		return false
	}
	if(area_code.value.length < '2'){
		alert("Please Enter Valid Area code")
		area_code.focus()
		return false
	}
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (isInteger(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	if(Phone.value.length < '6'){
		alert("Please Enter Valid Phone Number")
		Phone.focus()
		return false
	}
	else
		return true;
}

var xmlHttp;
var id;

function addcart(pid,cid)
{
	xmlHttp=GetXmlHttpObject();
	id = cid;
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="cart.php";
	url=url+"?pid="+pid;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("cart_result"+id).innerHTML=xmlHttp.responseText;
	} 
}
	
function GetXmlHttpObject()
{
	var xmlHttp=null;
	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;
}


// load submenus

function loadmenuitems(name,id,noitem)
{
	var j;
	for(var i=1;i<=noitem;i++)
	{
		if(id==name+i)
		{
			if(document.getElementById(name+i).style.display == 'none')
			{
				document.getElementById(name+i).style.display='inline';
				document.getElementById('imgid'+i).style.display='inline';
			}
			else
			{
				document.getElementById(name+i).style.display='none';
				document.getElementById('imgid'+i).style.display='none';
			}
		}
		else
		{
			document.getElementById(name+i).style.display='none';
			document.getElementById('imgid'+i).style.display='none';
		}
	}
}

function loadresult(catid,limitstart)
{
	document.getElementById('result_load').innerHTML='<div style="clear:both; padding-top:200px; height:160px;" align="center"><img src="images/ajaxloader.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajaxfunctions.php";
	url=url+"?page=loadresults&catid="+catid+"&limitstart="+limitstart;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged1() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("result_load").innerHTML=xmlHttp.responseText;
		var box = {};
		window.addEvent('domready', function(){
			box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: true});
		});
	} 
}

function loadsubcat_result(catid,subcatid,limitstart)
{
	document.getElementById('result_load').innerHTML='<div style="clear:both; padding-top:200px; height:160px;" align="center"><img src="images/ajaxloader.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajaxfunctions.php";
	url=url+"?page=loadsubresults&catid="+catid+"&subcatid="+subcatid+"&limitstart="+limitstart;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}