// JavaScript Document
function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function addToCart(tmpProductId,tmpProdPrice,tmpProdColor,tmpProdDisc,stURL)
	{
		//alert(1);
		var tmpPId		= tmpProductId;
		var tmpPriceId	= tmpProdPrice;
		var tmpColorId	= tmpProdColor;
		var tmpDisc		= tmpProdDisc;
		
		window.location.href = stURL+"/shopping-cart/addtocart.php?prodId="+tmpPId+"&price="+tmpPriceId+"&color="+tmpColorId+"&discount="+tmpDisc;
	}
	
function verification(frm)
{
     if(frm.txtNewsName.value == "")
   {
		alert("Please Enter your Name");
		frm.txtNewsName.focus();  
	    return false;
	}	
		
	if (frm.txtNewsEmail.value == "")
	 {
	   alert("Please Enter your Email");
	   frm.txtNewsEmail.focus();
		return false;
	}	
	else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.txtNewsEmail.value))
			return (true);
		else
		{
			alert("Invalid E-mail Address! Please re-enter.");
			return (false);
		}
	
	return (true);
}
	
	
function mycenteralpopwinVHS(fname,width,height)
{
	var file
	var sWidth	= 200
	var sHeight = 200
	
	if(width.length > 0){
	sWidth = width;
	}
	else{
	width =100;
	}
	
	if(height.length > 0){
	sHeight = height;
	}
	else{
	height =100;
	}
	
	file = fname
	file =file	
	
	var wintop  =window.screen.availHeight;
	var winleft =window.screen.availWidth;
	wintop  =(wintop/2) -(height/2)
	winleft =(winleft/2) -(width/2)
	//wintop  = 0
	//winleft = 0
	
	if ( sWidth > window.screen.availWidth )
		{ sWidth = window.screen.availWidth; }
	if (sHeight > window.screen.availHeight )
		{ sHeight = window.screen.availHeight; }
	if ( parseInt(sWidth) < width )
		{ sWidth = width; }
	if ( parseInt(sHeight) < height )
		{ sHeight = height; }
	
	if ( navigator.appName == "Microsoft Internet Explorer" )
		{ window.open(file, "_blank", "status=no, scrollbars=yes, toolbar=no, resizable=yes, location=no, menubar=no, top=" + wintop + ", left= "+ winleft +", height=" + sHeight + ", width=" + sWidth); 
		}
	if ( navigator.appName == "Netscape" ) 
		{ 
		window.open(file,"_blank","scrollbars=yes,alwaysRaised,dependant,innerheight=" + sHeight + ",innerwidth=" + sWidth); 		 
		//window.open(file,"_blank","alwaysRaised,dependant,scrollbars=yes,innerheight=" + sHeight + ",innerwidth=" + sWidth); 
		}
}


	// Java Script functions for Compare Products 
	function checkComparePrd() 
	{     
		var total=0;
		var comp = document.frmcompare['compare[]'];
		if(comp.length>0)
		{
			for(var i=0; i < comp.length; i++)
			{
				if(comp[i].checked)
				total = total + 1;
			}
		}
		http.open("GET", urlComp + total, true);
		http.onreadystatechange = handleHttpResponseComp;
		http.send(null);
	}

   function handleHttpResponseComp()
    {   
		if (http.readyState == 4) 
		{
			  if(http.status==200) 
			  {
				//alert(http.status); 
				 var results=http.responseText;
				// alert(results);
				//window.location.reload( true );
					if(results == 0)
					{
						document.getElementById('redbold').innerHTML = "Please select more than one product to compare";
					}
					else
					{
						document.frmcompare.submit();
					}				
			  }
		   
		 }
   }
   
	function getHTTPObject() 
	{
		var xmlhttp;
		
		if(window.XMLHttpRequest)
		{
		xmlhttp = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if (!xmlhttp)
			{
				xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		}
		
		return xmlhttp;
	}
	var http = getHTTPObject();
	
	
	
var AdminResponseL = "";

function parseResponseL()
{
//alert(AdminResponse);
var nMessage = document.getElementById('echoM');
nMessage.style.display = '';
	if(AdminResponseL == 1)
	{
	//nMessage.innerHTML = "You have successfully registered";
	window.location="member_home.php";
	}
	else
	{
	nMessage.innerHTML = AdminResponseL;
	}
}

function registerUserL(){
//document.getElementById("boxmiddleMem").style.display = "none";
//return;
var AdminRequestL = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
AdminRequestL.onreadystatechange = function()
{
	myDiv	= document.getElementById("echoM");
		if(AdminRequestL.readyState == 1 || AdminRequestL.readyState == 2 || AdminRequestL.readyState == 3)
		{
				//alert('123');
				myDiv.style.display = "block";
				myDiv.innerHTML = " <img src='<?=$siteURL?>/images/loading1.gif' border='0' align='texttop'> <b>Please wait. Loading...</b>";
		}
	
	if (AdminRequestL.readyState == 4)
	{
		//alert(AdminRequest.readyState)
		if (AdminRequestL.status == 200)
		{
		AdminResponseL = AdminRequestL.responseText;
		parseResponseL();
		}
	}
}
var nForm = document.frmlogin;
var infoStr = "txtEmail=" + nForm.txtEmail.value;
infoStr += "&txtPwd=" + nForm.txtPwd.value;

//alert(infoStr);
AdminRequestL.open("POST", "validation_login.php", true);
AdminRequestL.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
AdminRequestL.send(infoStr);
}

function validatelogin(nForm){
//alert('123');
document.getElementById('echoM').style.display = 'none';
registerUserL();
}

var AdminResponseF = "";

function parseResponseF()
{

var nMessage = document.getElementById('echoF');
nMessage.style.display = '';
	if(AdminResponseF == 1)
	{
	nMessage.innerHTML = "An e-mail containing your password has been sent.";
	}
	else
	{
	nMessage.innerHTML = AdminResponseF;
	}
}

function registerUserF(){
var AdminRequestF = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
AdminRequestF.onreadystatechange = function()
{
	if (AdminRequestF.readyState == 4)
	{
		if (AdminRequestF.status == 200)
		{
		AdminResponseF = AdminRequestF.responseText;
		parseResponseF();
		}
	}
}
var nForm = document.frmforgot;
var infoStr = "txtEmail1=" + nForm.txtEmail1.value;
AdminRequestF.open("POST", "chcekforgot.php", true);
AdminRequestF.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
AdminRequestF.send(infoStr);
}

function validateforgot(nForm){
document.getElementById('echoF').style.display = 'none';
registerUserF();
}

function EmptyValues()
{
  docum = document.frmDisplay;
  if(docum.chkEmpty.checked==true)
  {
	docum.Fname.value 		= "";//first name
	docum.Lname.value 		= "";//lastname
	docum.address.value 	= "";//address
	docum.county.value		= "";//state
	docum.postcode.value 	= "";//city		
  }
}

function frmSubmit(curPID,aID)
{	
	document.frmcompare.txtPID.value = curPID;
	if(aID == 1)
	{
		document.frmcompare.action='index.php';
	}
	else
	if(aID == 2)
	{
		document.frmcompare.action='products.php';	
	}
	document.frmcompare.submit();
}

function PrintPage()
{
	window.print();	
	return false;
}

// function for delete the category products in admin.

	function ajax(stURL,frmProdId,frmPackageId) // paramters for different forms eg: 1 for register form, 2 for login form etc..
	{ 
		getHTTPObject();
		//alert("Id = "+frmProdId);
		url = stURL+"/delete_cat_product.php?prodId="+frmProdId+"&packageId="+frmPackageId; 
		http.open("GET",url,true); 
		http.onreadystatechange = StateChange;
		http.send(null); 
	}
	
	function StateChange()
	{ 
		
		if(http.readyState == 4)
		{	
			//alert(" Response one : "+http.responseText);
			document.getElementById("edit_package").innerHTML=http.responseText;	
		}
	
	}  //StateChange
	
	function select_category(catId)
	{	
		//alert(catId);
		getHTTPObject();
		url = "select_category.php?catId="+catId;
		http.open("GET",url,true);
		http.onreadystatechange = CategoryChange;
		http.send(null); 
		
	}
	
	function CategoryChange()
	{ 
		
		if(http.readyState == 4)
		{	
			alert(" Response one : "+http.responseText);
			var content = http.responseText;
			var allContent = content.split('|');
			var catContent = allContent[0];
			var prodContent = allContent[1];
			document.getElementById("selProd").innerHTML= "";
			document.getElementById("selProdId").innerHTML= "";
			document.getElementById("selProd").innerHTML=catContent;	
			document.getElementById("selProdId").innerHTML=prodContent;	
		}
	
	}  //StateChange
	

function Gift_Tag(objVal,stURL,objDiv,pgType)
{ 
	var merVal	= objVal;
	
	if(pgType == 'S')
	{
		if(objVal == true)
		{
			new Effect.BlindDown(document.getElementById(objDiv));	
		}
		else
		if(objVal == false)
		{
			new Effect.BlindUp(document.getElementById(objDiv));	
		}
	}
	else
	if(pgType == 'C')
	{ 
		if(objVal == 'Paypal')
		{
			document.getElementById("CC_DETAILS").style.display	= 'none';
		}
		else
		if(objVal == 'CC')
		{
			document.getElementById("CC_DETAILS").style.display	= 'block';
		}		
	}
}
