// JavaScript Document
// Welcome to WireOx.Com
// Cell Phones, BlueTooths, Batteries, Chargers And Other Accessories are Available in the site

function correctMail(frm)
{
	var x = frm.EmailAddress.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)){ 
	   return true;
	}else{
		alert('Please write email address in correct format');
		return false;   
		}
}
function correctZipCode(frm){
	var strValue = frm.ZipCode.value;
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  //check for valid US Zipcode
  if(objRegExp.test(strValue)){
	  return true;
	  }else {
		  alert('Please write zip/postal code in correct format');
		  return false;
		  }
	
	}
// Search Field Empty Check In Top Header Page = Top.php 

function searchEmpty()
{
	if(document.SearchForm.searchText.value== "")
	{
		alert("Please enter search word") ;
		document.SearchForm.searchText.focus() ;
		return false ;
	}
	else
		return true ;
}


function newsletterEmpty()
{
	if(document.NewsLetterForm.NewsLetter.value== "")
	{
		alert("Please enter your Email Address") ;
		document.NewsLetterForm.NewsLetter.focus() ;
		return false ;
	}
	else
		return true ;
}

// Forget Password !

function ForgetPassword()
{
	if(document.forgetPassword.EmailAddress.value== "")
	{
		alert("Please enter your email address") ;	
		document.forgetPassword.EmailAddress.focus() ;
		return false ;
	}
	else
		return true ;
}

// Registration Form Check Page = RegisterWholeSaler.php

function regEmpty(isWholesaler)
{
	
	if(document.regForm.FirstName.value== "")
	{
		alert("Please enter First Name") ;
		document.regForm.FirstName.focus() ;
		return false ;
	}
	if(document.regForm.LastName.value== "")
	{
		alert("Please enter Last Name") ;
		document.regForm.LastName.focus() ;
		return false ;
	}
	if(document.regForm.Address1.value== "")
	{
		alert("Please enter Address 1") ;
		document.regForm.Address1.focus() ;
		return false ;
	}
	
	if(document.regForm.City.value== "")
	{
		alert("Please enter City") ;
		document.regForm.City.focus() ;
		return false ;
	}
	if(document.regForm.State.value== "")
	{
		alert("Please enter State") ;
		document.regForm.State.focus() ;
		return false ;
	}
	if(document.regForm.ZipCode.value== "")
	{
		alert("Please enter Zip Code") ;
		document.regForm.ZipCode.focus() ;
		return false ;
	}
	if(document.regForm.PhoneNumber.value== "")
	{
		alert("Please enter Phone Number") ;
		document.regForm.PhoneNumber.focus() ;
		return false ;
	}
	if(document.regForm.EmailAddress.value== "")
	{
		alert("Please enter Email Address") ;
		document.regForm.EmailAddress.focus() ;
		return false ;
	}
	if(isWholesaler=='t') {
		if(document.regForm.CompanyName.value== "")
		{
			alert("Please enter company name") ;
			document.regForm.CompanyName.focus() ;
			return false ;
		}
	}
	
	if(!document.regForm.privacyCheckbox.checked)
	{
			alert("Please Select Privacy Policy checkbox to proceed") ;
			document.regForm.privacyCheckbox.focus() ;
			return false ;
	}
	
	if(!correctMail(document.regForm)){
		   return false; 
		}
	
	if(!correctZipCode(document.regForm)){
		   return false;	
		}
		return true ;
	
	
}

//Modify User Profile
function modifyReg(isWholesaler)
{
	
		if(document.manageForm.FirstName.value== "")
	{
		alert("Please enter First Name") ;
		document.manageForm.FirstName.focus() ;
		return false ;
	}
	if(document.manageForm.LastName.value== "")
	{
		alert("Please enter Last Name") ;
		document.manageForm.LastName.focus() ;
		return false ;
	}
	if(document.manageForm.Address1.value== "")
	{
		alert("Please enter Address 1") ;
		document.manageForm.Address1.focus() ;
		return false ;
	}
	
	if(document.manageForm.City.value== "")
	{
		alert("Please enter City") ;
		document.manageForm.City.focus() ;
		return false ;
	}
	if(document.manageForm.State.value== "")
	{
		alert("Please enter State") ;
		document.manageForm.State.focus() ;
		return false ;
	}
	if(document.manageForm.ZipCode.value== "")
	{
		alert("Please enter Zip Code") ;
		document.manageForm.ZipCode.focus() ;
		return false ;
	}
	if(document.manageForm.PhoneNumber.value== "")
	{
		alert("Please enter Phone Number") ;
		document.manageForm.PhoneNumber.focus() ;
		return false ;
	}

	if(isWholesaler=='W') {
	
		if(document.manageForm.CompanyName.value== "")
		{
			alert("Please enter company name") ;
			document.manageForm.CompanyName.focus() ;
			return false ;
		}
	}
	
	if(!correctZipCode(document.manageForm)){
		   return false;	
		}
		return true ;
	
	
}


// User Sign In / Login Page = SignIn.php

function signInEmpty()
{
		
	if(document.LoginForm.UserName.value== "")
	{
		alert("Please enter username") ;
		document.LoginForm.UserName.focus() ;
		return false ;
	}
	if(document.LoginForm.Password.value== "")
	{
		alert("Please enter password") ;
		document.LoginForm.Password.focus() ;
		return false ;
	}
	else
	
		return true ;
}

// Change Password

function ChgPwd()
{
	if(document.ChgPwD.OldPassword.value== "")
	{
		alert("Please enter old password") ;
		document.ChgPwD.OldPassword.focus() ;
		return false ;
	}
	if(document.ChgPwD.NewPassword.value== "")
	{
		alert("Please enter new password") ;
		document.ChgPwD.NewPassword.focus() ;
		return false ;
	}
	else
		return true ;
}

// Shipping Address Page = CartItemDetails

function ShippingAddressField()
{
	if(document.CartItemDetails.ShippingAddress.value=="")	
	{
		alert("Please enter shipping address");
		document.CartItemDetails.ShippingAddress.focus();
		return false;
	}
	else
		return true;
}

// Open A New Window

function OpenNewWindow(viewImage)
{
		window.open( viewImage , "" , "height=550 , width=550 , status=no , toolbar=no , menubar=no , location=no , scrollbars=no , resizable=no" ) ;
}

// Confirm Close Window Page = BigImage.php

function CloseWindow()
{
	if(confirm ("Are you sure, you want to close this window"))
	{
		return true ;
	}
	else
		return false ;
}

// Delete User Account Confirmation 

function deleteUserAccount()
{
	if(confirm("Are you sure, you want to delete this user account - OK Press for Delete"))
	{
		return true ;	
	}
	else
		return false ;
}

// Activate User Confirmation

function activateUserAccount()
{
	if(confirm("Are you sure, you want to activate this user account - OK Press for Delete"))
	{
		return true ;	
	}
	else
		return false ;
}

// DeActivate User Confirmation

function deActivateUserAccount()
{
	if(confirm("Are you sure, you want to deactivate this user account - OK Press for Delete"))
	{
		return true ;	
	}
	else
		return false ;
}

// Update Add To Cart Price

function updateAddToCartPrice()
{
	document.location.herf="UpdateAddToCartPrice.php" ;	
}

// This function send to home page , From CartItemDetails Page
function moreShopping()
{	
		document.location.href="?page=BestSeller";
		return false;
		
}
function editShopping()
{	
		document.location.href="?page=CheckOut&shpng=w_reg";
		return false;
		
}
function setUserValue(val,control)
{
     var obj = document.getElementById(control)
     for(var i=0; i<obj.options.length; i++ ) {
        if( obj.options[i].value == val)
          obj.options[i].selected=true;
     }
}
function customizeFields()
{
	var payTypeValue = document.getElementById('PaymentType').value;
	if(payTypeValue=='Paypal')
	{
		document.getElementById('rowCardNumber').style.display="none";
		document.getElementById('verifNum').style.display="none";
		document.getElementById('expDate').style.display="none";
	}
	else
	{
		document.getElementById('rowCardNumber').style.display="block";
		document.getElementById('verifNum').style.display="block";
		document.getElementById('expDate').style.display="block";
	}
	return false;
}
function disableCheckbox()
{
		var btn = document.CheckOut.shippingRadioButton.checked=false;;

}