var xmlHttp
var xmlHttp1
function chkxmlhttp(){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
}
function chkxmlhttp1(){
	xmlHttp1=GetXmlHttpObject1()
	if (xmlHttp1==null){
		alert ("Browser does not support HTTP Request")
		return
	}
}
function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("txtShow").innerHTML=xmlHttp.responseText 
	}
	if (xmlHttp.readyState==3){
		document.getElementById("txtShow").innerHTML="Loading Data.... Please wait."
	} 
}
function stateChanged1(){
	if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete"){
		document.getElementById("txtucart").innerHTML=xmlHttp1.responseText 
	}
}
function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function GetXmlHttpObject1(){ 
	var objXMLHttp1=null
	if (window.XMLHttpRequest){
		objXMLHttp1=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		objXMLHttp1=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp1
}
function txtopen(str){
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",str,true)
	xmlHttp.send(null)
}
function txtopen1(str){
	xmlHttp1.onreadystatechange=stateChanged1
	xmlHttp1.open("GET",str,true)
	xmlHttp1.send(null)
}
function showCart(){
//	chkxmlhttp1()
//	var url2="tcart.php?unid="+Math.random()
//	txtopen1(url2)
}
function showCustomer(str,str1){ 
	chkxmlhttp()
	var url="sshout.php?uname="+str+"&msg="+str1+"&sid="+Math.random()
	txtopen(url)
}
function sHome(){ 
	chkxmlhttp()
	var url="default.php?unid="+Math.random()
	txtopen(url)
	showCart()
}
function sAbout(){ 
	chkxmlhttp()
	var url="about.php?unid="+Math.random()
	txtopen(url)
	showCart()
}
function sProducts(){ 
	chkxmlhttp()
	var url="products.php?unid="+Math.random()
	txtopen(url)
	showCart()
}
function scatProducts(str,str2,str3){ 
	chkxmlhttp()
	var url="products.php?category_id="+str+"&subid="+str2+"&start="+str3+"&unid="+Math.random()
	txtopen(url)
	showCart()
}
function advProducts(str,str2){ 
	chkxmlhttp()
	var url="advsrch.php?unid="+Math.random()+str+"&start="+str2
	txtopen(url)
	showCart()
}
function sSupport(){ 
	chkxmlhttp()
	var url="support.php?unid="+Math.random()
	txtopen(url)
	showCart()
}
function sNews(){ 
	chkxmlhttp()
	var url="news.php?unid="+Math.random()
	txtopen(url)
	showCart()
}
function sNewsid(str){ 
	chkxmlhttp()
	var url="news.php?news_id="+str+"&unid="+Math.random()
	txtopen(url)
	showCart()
}
function sContact(){ 
	chkxmlhttp()
	var url="contact.php?unid="+Math.random()
	txtopen(url)
	showCart()
}
function lData(str1,str2,str3){ 
	chkxmlhttp()
	var url=str1+"?unid="+Math.random()+str2+str3
	txtopen(url)
	showCart()
}
function lData2(str1,str2,str3,str4,str5){ 
	chkxmlhttp()
	var url=str1+"?unid="+Math.random()+str2+str3+str4+str5
	txtopen(url)
	showCart()
}

function actnletter(){
	chkxmlhttp()
	var url="newsletter.php?subScribe="+document.all.subScribe.value+"&txtEmail="+document.all.txtEmail.value+"&unid="+Math.random()
	txtopen(url)
	showCart()
}
function validateNletter(){

	if(document.all.txtEmail.value==""){
		alert("Please enter your Email");
	}else{
		actnletter()
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function test(obj,msg) {
		  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		  if (regex.test(obj.value))
		  {
			return true;
		  }
		  else{
			alert(msg);
			obj.focus();
			return false;
		  }
		}
	function checkempty(obj,msg)
	{
	 if(obj.value=="")
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	function checkzero(obj,msg)
	{
	 if(obj.value==0)
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	function confirmPassword(obj,obj1,msg)
	{
	 if(!(obj.value==obj1.value))
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	function checkint(obj,msg)
	{
	 if(isNaN(obj.value))
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
///////////////TRIM KEY///////////////////
function trim(Key) {
	while(''+Key.charAt(Key.length-1)==' ')
		{ Key=Key.substring(0,Key.length-1); }
	return Key;
}
///////////////Check Qty///////////////////
function chkqty(Key,Act) {
	a = Key;
	if (checkempty(a.qty,"Information - Enter Quantity")==false) return false;
	if (checkint(a.qty,"Information - Enter Quantity in digits")==false) return false;
	if (checkzero(a.qty,"Information - Enter Quantity greater then 0")==false) return false;
	lData("cart.php","&product_id="+a.pid.value+"&qty="+a.qty.value,Act);
}
function defadd(Key,Act){
	lData("cart.php","&product_id="+Key+"&qty=1",Act);
}
function chkqty1(myQty,myPid,Act) {
	if (checkempty(myQty,"Information - Enter Quantity")==false) return false;
	if (checkint(myQty,"Information - Enter Quantity in digits")==false) return false;
	if (checkzero(myQty,"Information - Enter Quantity greater then 0")==false) return false;
	lData("cart.php","&product_id="+myPid.value+"&qty="+myQty.value,Act);
}
///////////////Del Item///////////////////
function delitm(myPid,Act) {
	if(confirm('Are You Sure you want to delete')){
		lData("cart.php","&product_id="+myPid.value,Act);
		return true;
	}else{
		return false;
	}
}
/////////////////User Management///////////////////

	function CheckRegUser()
	{
		if (test(document.frmOrder.Email,"Account Registration :.. Enter User's Email..:")==false) return false;
		if (checkempty(document.frmOrder.password,"Account Registration :.. Enter User's Password..:")==false) return false;
		if (confirmPassword(document.frmOrder.password,document.frmOrder.repassword,"Account Registration :.. Password & Confirm Password Fields must be same..:")==false) return false;
		
		if (checkempty(document.frmOrder.FName,"Account Registration :.. Enter User Full Name..:")==false) return false;
		if (checkempty(document.frmOrder.cAddress,"Account Registration :.. Enter Address..:")==false) return false;
//		if (checkempty(document.frmOrder.cState,"Account Registration :.. Enter State..:")==false) return false;
		if (checkempty(document.frmOrder.country,"Account Registration :.. Select Country..:")==false) return false;
		return true;
	}
	function CheckeRegUser()
	{
		if (checkempty(document.frmOrder.password,"Account Information :.. Enter User's Password..:")==false) return false;
		if (confirmPassword(document.frmOrder.password,document.frmOrder.repassword,"Account Information :.. Password & Confirm Password Fields must be same..:")==false) return false;
		
		if (checkempty(document.frmOrder.FName,"Account Information :.. Enter User Full Name..:")==false) return false;
		if (checkempty(document.frmOrder.cAddress,"Account Information :.. Enter Address..:")==false) return false;
		if (checkempty(document.frmOrder.country,"Account Information :.. Select Country..:")==false) return false;
		return true;
	}
	function chkLogin()
	{
		if (test(document.frmLogin.user,"Login - Enter Email As User Name.")==false) return false;
		if (checkempty(document.frmLogin.pass,"Login - Enter Password")==false) return false;		
		return true;
	}
/////////////VALIDATE RECOMMEND/////////////
function validatePostal() {

	a = document.frmPostalRepairs;
	a.txtName.value = trim(a.txtName.value);
	if (!a.txtName.value) {
		alert('Please enter your name.');
		a.txtName.focus();
		return false;
	}
	a.txtAddress.value = trim(a.txtAddress.value);
	if (!a.txtAddress.value) {
		alert('Please enter your address.');
		a.txtAddress.focus();
		return false;
	}
	a.txtCountry.value = trim(a.txtCountry.value);
	if (!a.txtCountry.value) {
		alert('Please enter your country.');
		a.txtCountry.focus();
		return false;
	}
	a.txtCode.value = trim(a.txtCode.value);
	if (!a.txtCode.value) {
		alert('Please enter your post code.');
		a.txtCode.focus();
		return false;
	}
	a.txtCity.value = trim(a.txtCity.value);
	if (!a.txtCity.value) {
		alert('Please enter your city.');
		a.txtCity.focus();
		return false;
	}
	a.txtPhone.value = trim(a.txtPhone.value);
	if (!a.txtPhone.value) {
		alert('Please enter your phone number.');
		a.txtPhone.focus();
		return false;
	}
	a.txtEmail.value = trim(a.txtEmail.value);
	if (!a.txtEmail.value) {
		alert('Please enter your email address.');
		a.txtEmail.focus();
		return false;
	}
}
/////////////VALIDATE RECOMMEND/////////////
function validateRecommend() {

	a = document.frmRecommend;
	a.txtName.value = trim(a.txtName.value);
	if (!a.txtName.value) {
		alert('Please enter your name.');
		a.txtName.focus();
		return false;
	}
	
	a.txtEmail.value = trim(a.txtEmail.value);
	if (!a.txtEmail.value) {
		alert('Please enter your email address.');
		a.txtEmail.focus();
		return false;
	}
	
	a.txtNameF.value = trim(a.txtNameF.value);
	if (!a.txtNameF.value) {
		alert('Please enter your friend name.');
		a.txtNameF.focus();
		return false;
	}
	
	a.txtEmailF.value = trim(a.txtEmailF.value);
	if (!a.txtEmailF.value) {
		alert('Please enter your friend email address.');
		a.txtEmailF.focus();
		return false;
	}
}
/////////////VALIDATE CATEGORY//////////////
function validateCategory() {
	a = document.frmCategory;
	a.txtCategory.value = trim(a.txtCategory.value);
	if (a.txtCategory.value=="") {
		alert('Enter the category!');
		a.txtCategory.focus();
		return false;
	}
}
/////////////VALIDATE RESELLER//////////////
function validateReseller() {
	a = document.frmReseller;
	a.txtReseller.value = trim(a.txtReseller.value);
	if (a.txtReseller.value=="") {
		alert('Enter the reseller!');
		a.txtReseller.focus();
		return false;
	}
}
////////////////Login Check/////////////////
	function chkLogin2()
	{
		if (test(document.frmLogin2.user,"Login - Enter Email As User Name.")==false) return false;
		if (checkempty(document.frmLogin2.pass,"Login - Enter Password")==false) return false;		
		return true;
	}
////////////Check Forget/////////////////
	function chkforget()
	{
		if (test(document.frmLogin2.user,"Login - Enter Email As User Name.")==false) return false;		
		return true;
	}
/////////////VALIDATE PRODUCT//////////////
function validateProduct() {
	a = document.frmProduct;
	a.txtProduct.value = trim(a.txtProduct.value);
	if (a.txtProduct.value=="") {
		alert('Enter product name!');
		a.txtProduct.focus();
		return false;
	}
	a.txtPrice.value = trim(a.txtPrice.value);
	if (a.txtPrice.value=="") {
		alert('Enter the price!');
		a.txtPrice.focus();
		return false;
	}
}
/////////////VALIDATE PAYMENT//////////////
function validatePayment() {
	a = document.frmPayment;
	a.txtPayment.value = trim(a.txtPayment.value);
	if (a.txtPayment.value=="") {
		alert('Enter payment name!');
		a.txtPayment.focus();
		return false;
	}
	a.txtPrice.value = trim(a.txtPrice.value);
	if (a.txtPrice.value=="") {
		alert('Enter the price!');
		a.txtPrice.focus();
		return false;
	}
}
/////////////VALIDATE DELIVERY//////////////
function validateDelivery() {
	a = document.frmDelivery;
	a.txtDelivery.value = trim(a.txtDelivery.value);
	if (a.txtDelivery.value=="") {
		alert('Enter delivery name!');
		a.txtDelivery.focus();
		return false;
	}
	a.txtPrice.value = trim(a.txtPrice.value);
	if (a.txtPrice.value=="") {
		alert('Enter the price!');
		a.txtPrice.focus();
		return false;
	}
}
/////////////VALIDATE EMAIL//////////////
function validateEmail() {
	a = document.frmAddEmail;
	a.txtEmail.value = trim(a.txtEmail.value);
	if (a.txtEmail.value=="") {
		alert('Enter the email address!');
		a.txtEmail.focus();
		return false;
	}
}
////////////////Reset Form///////////////////
function frmreset(){
	document.all.txtFirstname.value='';
	document.all.Company.value='';
	document.all.txtPhone.value='';
	document.all.Fax.value='';
	document.all.ctxtEmail.value='';
	document.all.country.value='';
	document.all.inqType.value='';
	document.all.Address.value='';
	document.all.txtMessage.value='';
}
/////////////VALIDATE MAIL//////////////
function validateMail() {
	document.all.txtFirstname.value = trim(document.all.txtFirstname.value);
	if (document.all.txtFirstname.value=="") {
		alert('Enter your Name!');
		document.all.txtFirstname.focus();
		return false;
	}
	document.all.Company.value = trim(document.all.Company.value);
	if (document.all.Company.value=="") {
		alert('Enter your Company Name!');
		document.all.Company.focus();
		return false;
	}
	document.all.ctxtEmail.value = trim(document.all.ctxtEmail.value);
	if (test(document.all.ctxtEmail,"Information - Enter Valid Email Address!")==false) return false;
	
	document.all.txtMessage.value = trim(document.all.txtMessage.value);
	if (document.all.txtMessage.value=="") {
		alert('Enter your Message!');
		document.all.txtMessage.focus();
		return false;
	}

	chkxmlhttp()
	var url="smail.php?fname="+document.all.txtFirstname.value+"&Company="+document.all.Company.value+"&Fax="+document.all.Fax.value+"&country="+document.all.country.value+"&inqType="+document.all.inqType.value+"&Address="+document.all.Address.value+"&eml="+document.all.ctxtEmail.value+"&phone="+document.all.txtPhone.value+"&msg="+document.all.txtMessage.value+"&unid="+Math.random()
	txtopen(url)
	showCart()
}
/////////////VALIDATE ORDER//////////////
function validateOrder() {
	b = document.all;
	b.firstName.value = trim(b.firstName.value);
	if (b.firstName.value=="") {
		alert('Enter your firstname!');
		b.firstName.focus();
		return false;
	}
	b.lastName.value = trim(b.lastName.value);
	if (b.lastName.value=="") {
		alert('Enter your lastname!');
		b.lastName.focus();
		return false;
	}
	if (test(b.email,"Information - Enter Valid Email Address!")==false) return false;
	
	b.address1.value = trim(b.address1.value);
	if (b.address1.value=="") {
		alert('Enter your address!');
		b.address1.focus();
		return false;
	}
	b.zip.value = trim(b.zip.value);
	if (b.zip.value=="") {
		alert('Enter your zipcode!');
		b.zip.focus();
		return false;
	}
	b.city.value = trim(b.city.value);
	if (b.city.value=="") {
		alert('Enter the city!');
		b.city.focus();
		return false;
	}
	b.country.value = trim(b.country.value);
	if (b.country.value=="") {
		alert('Enter the country!');
		b.country.focus();
		return false;
	}
	
//	chkxmlhttp()
//	var url="preview.php?payment="+b.payment.value+"&delivery="+b.delivery.value+"&priceP="+b.priceP.value+"&priceD="+b.priceD.value+"&payment_id="+b.payment_id.value+"&delivery_id="+b.delivery_id.value+"&indice="+b.indice.value+"&total="+b.total.value+"&firstName="+b.firstName.value+"&lastName="+b.lastName.value+"&email="+b.email.value+"&phone="+b.phone.value+"&address1="+b.address1.value+"&zip="+b.zip.value+"&city="+b.city.value+"&country="+b.country.value+"&comments="+b.comments.value+"&remember="+b.remember.value+"&unid="+Math.random()
//	txtopen(url)
//	showCart()
}
function scheckout(){
	chkxmlhttp()
	var url="submit_order.php?payment="+b.payment.value+"&priceP="+b.priceP.value+"&delivery="+b.delivery.value+"&priceD="+b.priceD.value+"&indice="+b.indice.value+"&total="+b.total.value+"&email="+b.email.value+"&firstName="+b.firstName.value+"&lastName="+b.lastName.value+"&address1="+b.address1.value+"&zip="+b.zip.value+"&city="+b.city.value+"&country="+b.country.value+"&phone="+b.phone.value+"&comments="+b.comments.value+Math.random()
	txtopen(url)
	showCart()
}
/////////////VALIDATE SMS//////////////
function validateSMS() {
	a = document.frmAddSMS;
	a.txtPhone.value = trim(a.txtPhone.value);
	if (a.txtPhone.value=="") {
		alert('Enter the phone number!');
		a.txtPhone.focus();
		return false;
	}
}

////////////SELECT CATEGORY///////////////////////
function SelectCategory()
{    
	document.forms[0].submit();
}

////////////POPUP RESIZED - OPEN WINDOW//////////////////////
function openWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = "height="+h+", width="+w+", top="+wint+", left="+winl+", scrollbars="+scroll+", resizable=no";
	window.open(mypage, "CurencyConverter", winprops);
	
}
////////////NORMAL POPUP/////////////////////////////////////
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
} 
////////////////////////////////////////////////////////////
function getCheckedValue(radioObj){	if(!radioObj)		return "";	var radioLength = radioObj.length;	if(radioLength == undefined)		if(radioObj.checked)			return radioObj.value;		else			return "";	for(var i = 0; i < radioLength; i++) {		if(radioObj[i].checked) {			return radioObj[i].value;		}	}	return "";}
////////////////////////////////////////////////////////////
function getRadVal(){
	var payment = getCheckedValue(document.forms["frmModify1"].elements['payment_id'])
	var delivery = getCheckedValue(document.forms["frmModify1"].elements['delivery_id'])
	lData("order.php","&totalCost=<?=$totalCost;?>","&payment_id="+payment+"&delivery_id="+delivery)
}