// All Rights Reserved hurriKane Solutions, 2005

// Change Shipping
function changeShipping(id){

window.location = "checkOutStepTwo.asp?shippingId=" + id + "#shipping"
}

// Check Out System

function checkCheckOut(theForm)
{
    if (theForm.cardnumber.value.length  != 16)  {
    alert("You have entered in an Invalid Card Number!");
    theForm.cardnumber.focus();
    return (false);
	}
if (!hkNumbers(theForm.cardnumber.value)) {
		valid = 0
		alert("Please Enter in Numbers Only")
		theForm.cardnumber.focus();
    	return (false);
	}
	if (theForm.expmonth.value == "")
  {
    alert("Please enter a value for the \"Experation\" field.");
    theForm.expmonth.focus();
    return (false);
  }
	if (theForm.expyear.value == "")
  {
    alert("Please enter a value for the \"Experation\" field.");
    theForm.expyear.focus();
    return (false);
  }
  if (!hkNumbers(theForm.cvmvalue.value)) {
		valid = 0
		alert("Please Enter in Numbers Only")
		theForm.cvmvalue.focus();
    	return (false);
	}
  
if (theForm.termsOfUse.checked==false)
  {
    alert("You must agree to the Terms and Conditions before proceeding!");
    theForm.termsOfUse.focus();
    return (false);
  }
  return (true);
}
//


// Check Contact Form
function checkEmailFriend(theForm)
{
	var ValidEmail=IsValidEmail (theForm.toEmail.value);
	if ((ValidEmail==false) ){
	alert("You have entered in a invalid email address");
	theForm.toEmail.focus();
	return (false);
	}
	if (theForm.toName.value == "")
  {
    alert("Please enter a value for the \"To Name\" field.");
    theForm.toName.focus();
    return (false);
  }
		if (theForm.fromName.value == "")
  {
    alert("Please enter a value for the \"From Name\" field.");
    theForm.fromName.focus();
    return (false);
  }
	var ValidEmail=IsValidEmail (theForm.fromEmail.value);
	if ((ValidEmail==false) ){
	alert("You have entered in a invalid email address");
	theForm.fromEmail.focus();
	return (false);
	}
  return (true);
}

// billing script
function billingCheck(theForm)
{
if (theForm.username.value == "")
  {
    alert("Please enter a value for the \"Email Address (username)\" field.");
    theForm.username.focus();
    return (false);
  }
 	if (theForm.billingFirstName.value == "")
  {
    alert("Please enter a value for the \"Billing First Name\" field.");
    theForm.billingFirstName.focus();
    return (false);
  }
   	if (theForm.billingLastName.value == "")
  {
    alert("Please enter a value for the \"Billing Last Name\" field.");
    theForm.billingLastName.focus();
    return (false);
  }
	if (theForm.billingAddress1.value == "")
  {
    alert("Please enter a value for the \"Billing Address\" field.");
    theForm.billingAddress1.focus();
    return (false);
  }
  	if (theForm.billingCity.value == "")
  {
    alert("Please enter a value for the \"Billing City\" field.");
    theForm.billingCity.focus();
    return (false);
  }
  	if (theForm.billingState.value == "")
  {
    alert("Please enter a value for the \"Billing State\" field.");
    theForm.billingState.focus();
    return (false);
  }
  	if (theForm.billingZip.value == "")
  {
    alert("Please enter a value for the \"Billing Zip\" field.");
    theForm.billingZip.focus();
    return (false);
  }
if (theForm.billingPhoneArea.value == ""  || theForm.billingPhonePrefix.value == ""  ||  theForm.billingPhoneSuffix.value == "")
  {
    alert("Please enter a value for the \"Billing Home Phone\" field.");
    theForm.billingPhoneArea.focus();
    return (false);
  }
  return (true);
}
//

// shipping script
function shippingCheck(theForm)
{
  if (theForm.shipFirstName.value == "")
  {
    alert("Please enter a value for the \"Shipping First Name\" field.");
    theForm.shipFirstName.focus();
    return (false);
  }
   	if (theForm.shipLastName.value == "")
  {
    alert("Please enter a value for the \"Shipping Last Name\" field.");
    theForm.shipLastName.focus();
    return (false);
  }
	if (theForm.shipAddress1.value == "")
  {
    alert("Please enter a value for the \"Shipping Address\" field.");
    theForm.shipAddress1.focus();
    return (false);
  }
  	if (theForm.shipCity.value == "")
  {
    alert("Please enter a value for the \"Shipping City\" field.");
    theForm.shipCity.focus();
    return (false);
  }
  	if (theForm.shipState.value == "")
  {
    alert("Please enter a value for the \"Shipping State\" field.");
    theForm.shipState.focus();
    return (false);
  }
  	if (theForm.shipZip.value == "")
  {
    alert("Please enter a value for the \"Shipping Zip\" field.");
    theForm.shipZip.focus();
    return (false);
  }
if (theForm.shipPhoneArea.value == ""  || theForm.shipPhonePrefix.value == ""  ||  theForm.shipPhoneSuffix.value == "")
  {
    alert("Please enter a value for the \"Shipping Home Phone\" field.");
    theForm.shipPhoneArea.focus();
    return (false);
  }
  
  return (true);
}
//
// register script
function registerCheck(theForm)
{

if (theForm.username.value == "")
  {
    alert("Please enter a value for the \"Email Address (username)\" field.");
    theForm.username.focus();
    return (false);
  }
	var ValidEmail=IsValidEmail (theForm.username.value);
	if ((ValidEmail==false) && (theForm.username.value != "")){
	alert("You have entered in a invalid email address");
	theForm.username.focus();
	return (false);
	}
			
	if (theForm.password1.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.password1.focus();
    return (false);
  }
   if (theForm.password2.value == "")
  {
    alert("Please enter a value for the \"Confirm Password\" field.");
    theForm.password2.focus();
    return (false);
  }
    if (theForm.password1.value != theForm.password2.value)
  {
    alert("Your passwords do not match.  Please re-confirm your password.");
    theForm.password2.focus();
    return (false);
  }
 	if (theForm.billingFirstName.value == "")
  {
    alert("Please enter a value for the \"Billing First Name\" field.");
    theForm.billingFirstName.focus();
    return (false);
  }
   	if (theForm.billingLastName.value == "")
  {
    alert("Please enter a value for the \"Billing Last Name\" field.");
    theForm.billingLastName.focus();
    return (false);
  }
	if (theForm.billingAddress1.value == "")
  {
    alert("Please enter a value for the \"Billing Address\" field.");
    theForm.billingAddress1.focus();
    return (false);
  }
  	if (theForm.billingCity.value == "")
  {
    alert("Please enter a value for the \"Billing City\" field.");
    theForm.billingCity.focus();
    return (false);
  }
  	if (theForm.billingState.value == "")
  {
    alert("Please enter a value for the \"Billing State\" field.");
    theForm.billingState.focus();
    return (false);
  }
  	if (theForm.billingZip.value == "")
  {
    alert("Please enter a value for the \"Billing Zip\" field.");
    theForm.billingZip.focus();
    return (false);
  }
if (theForm.billingPhoneArea.value == ""  || theForm.billingPhonePrefix.value == ""  ||  theForm.billingPhoneSuffix.value == "")
  {
    alert("Please enter a value for the \"Billing Home Phone\" field.");
    theForm.billingPhoneArea.focus();
    return (false);
  }
  
  if (theForm.shipFirstName.value == "")
  {
    alert("Please enter a value for the \"Shipping First Name\" field.");
    theForm.shipFirstName.focus();
    return (false);
  }
   	if (theForm.shipLastName.value == "")
  {
    alert("Please enter a value for the \"Shipping Last Name\" field.");
    theForm.shipLastName.focus();
    return (false);
  }
	if (theForm.shipAddress1.value == "")
  {
    alert("Please enter a value for the \"Shipping Address\" field.");
    theForm.shipAddress1.focus();
    return (false);
  }
  	if (theForm.shipCity.value == "")
  {
    alert("Please enter a value for the \"Shipping City\" field.");
    theForm.shipCity.focus();
    return (false);
  }
  	if (theForm.shipState.value == "")
  {
    alert("Please enter a value for the \"Shipping State\" field.");
    theForm.shipState.focus();
    return (false);
  }
  	if (theForm.shipZip.value == "")
  {
    alert("Please enter a value for the \"Shipping Zip\" field.");
    theForm.shipZip.focus();
    return (false);
  }
if (theForm.shipPhoneArea.value == ""  || theForm.shipPhonePrefix.value == ""  ||  theForm.shipPhoneSuffix.value == "")
  {
    alert("Please enter a value for the \"Shipping Home Phone\" field.");
    theForm.shipPhoneArea.focus();
    return (false);
  }
  
  return (true);
}
//
// Change password
function myPassword(theForm)
{

if (theForm.username.value == "")
  {
    alert("Please enter a value for the \"Username\" field.");
    theForm.username.focus();
    return (false);
  }
	var ValidEmail=IsValidEmail (theForm.username.value);
	if ((ValidEmail==false) && (theForm.username.value != "")){
	alert("You have entered in a invalid username (email address)");
	theForm.username.focus();
	return (false);
	}
	if (theForm.currentpassword.value == "")
  {
    alert("Please enter a value for the \"Current Password\" field.");
    theForm.currentpassword.focus();
    return (false);
  }
	if (theForm.password1.value == "")
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.password1.focus();
    return (false);
  }
   if (theForm.password2.value == "")
  {
    alert("Please enter a value for the \"Confirm Password\" field.");
    theForm.password2.focus();
    return (false);
  }
    if (theForm.password1.value != theForm.password2.value)
  {
    alert("Your passwords do not match.  Please re-confirm your password.");
    theForm.password2.focus();
    return (false);
  } 
  return (true);
}
//
// duplicate address for user
function sameAddress(theForm)
{
	var strErrorVal = "The following fields are required for this Feature: ";
	var focus = 0;
	if (theForm.billingFirstName.value == "")
	{
		strErrorVal += "First Name, ";
		focus = 1;
	}
	if (theForm.billingLastName.value == "")
	{
		strErrorVal += "Last Name, ";
		focus = 2;
	}
	if (theForm.billingAddress1.value == "")
	{
		strErrorVal += "Address, ";
		focus = 3;
	}
	 if ( (theForm.billingCity.value == "") )
	{
		strErrorVal += "City, ";
		focus = 4;
	}
	 if ( (theForm.billingState.value == "") )
	{
		strErrorVal += "State, ";
		focus = 5;
	}
 if ( (theForm.billingZip.value == "") )
	{
		strErrorVal += "Zip ";
		focus = 6;
	}
 if ( (theForm.billingPhoneArea.value == "" || theForm.billingPhonePrefix.value == "" || theForm.billingPhoneSuffix.value == "") )
	{
		strErrorVal += "Home Phone ";
		focus = 7;
	}
	
if (focus != 0){
	theForm.sameAsBilling.checked=false;

	alert(strErrorVal); }
else {
theForm.shipFirstName.value = theForm.billingFirstName.value
theForm.shipLastName.value = theForm.billingLastName.value
theForm.shipCompanyName.value = theForm.billingCompanyName.value
theForm.shipAddress1.value = theForm.billingAddress1.value
theForm.shipAddress2.value = theForm.billingAddress2.value
theForm.shipCity.value = theForm.billingCity.value
theForm.shipState.value = theForm.billingState.value
theForm.shipZip.value = theForm.billingZip.value
theForm.shipPhoneArea.value = theForm.billingPhoneArea.value
theForm.shipPhonePrefix.value =	theForm.billingPhonePrefix.value
theForm.shipPhoneSuffix.value =	theForm.billingPhoneSuffix.value
theForm.shipCompPhoneArea.value = theForm.billingCompPhoneArea.value
theForm.shipCompPhonePrefix.value = theForm.billingCompPhonePrefix.value
theForm.shipCompPhoneSuffix.value = theForm.billingCompPhoneSuffix.value
theForm.shipCompPhoneExt.value = theForm.billingCompPhoneExt.value
	}
}


// Check Products
function checkProducts(theForm)
{
 	if (theForm.cat_sub.value == "")
  {
    alert("Please enter a value for the \"Category\" field.");
    theForm.cat_sub.focus();
    return (false);
  }
 	if (theForm.title.value == "")
  {
    alert("Please enter a value for the \"Title\" field.");
    theForm.title.focus();
    return (false);
  }
   	if (!hkCurrency(theForm.price.value))
  {
    alert("Please enter a value for the \"Price\" field.");
    theForm.price.focus();
    return (false);
  }
	if (theForm.saleFlag.value == "1" && theForm.salePrice.value == "")
  {
    alert("Please enter a number for the \"Sale Price\" field.");
	theForm.salePrice.value = theForm.price.value;
    theForm.salePrice.focus();
    return (false);
  }
  if (theForm.salePrice.value != "")
  {
	if (!hkCurrency(theForm.salePrice.value))
  {
    alert("Please enter a number for the \"Sale Price\" field.");
    theForm.salePrice.focus();
    return (false);
  }
  }
  
if (theForm.featuredFlag.value == "1" && theForm.newFlag.value == "1")
  {
    alert("This Product can not be both a Featured Item and a New Arrival");
	theForm.newFlag.value = 0;
    theForm.newFlag.focus();
    return (false);
  }  

if (theForm.weight.value != "")
  {
if (!hkCurrency(theForm.weight.value))
  {
    alert("Please enter a number for the \"Weight\" field.");
    theForm.weight.focus();
    return (false);
  }
  }

  return (true);
}

// Check The Anything
function checkAnything(theForm)
{
	if (theForm.pageTitle.value == "")
  {
    alert("Please enter a number for the \"Page Title\" field.");
    theForm.pageTitle.focus();
    return (false);
  }
	if (theForm.linkTitle.value == "")
  {
    alert("Please enter a number for the \"Link Title\" field.");
    theForm.linkTitle.focus();
    return (false);
  }
 	if (theForm.title.value == "")
  {
    alert("Please enter a number for the \"Title\" field.");
    theForm.title.focus();
    return (false);
  }
   	if (theForm.des.value == "")
  {
    alert("Please enter a number for the \"Body\" field.");
    theForm.des.focus();
    return (false);
  }
  return (true);
}

// Check The Rant
function checkTheRant(theForm)
{
 	if (theForm.title.value == "")
  {
    alert("Please enter a number for the \"Title\" field.");
    theForm.title.focus();
    return (false);
  }
   	if (theForm.des.value == "")
  {
    alert("Please enter a number for the \"Body\" field.");
    theForm.des.focus();
    return (false);
  }
  return (true);
}

// Check Image Upload
function checkImage(theForm)
{
 	if (theForm.img.value == "")
  {
    alert("You need to click the \"Choose Image First\"'");
    theForm.img.focus();
    return (false);
  }
  return (true);
}



// Check Contact Form
function checkContact(theForm)
{
 if (theForm.name.value == "")
  {
    alert("Please enter a value for the \"name\" field.");
    theForm.name.focus();
    return (false);
  }  
	var ValidEmail=IsValidEmail (theForm.email.value);
	if ((ValidEmail==false) ){
	alert("You have entered in a invalid email address");
	theForm.email.focus();
	return (false);
	}
  return (true);
}
function checkNewsLetter(theForm)
{
	var ValidEmail=IsValidEmail (theForm.email.value);
	if ((ValidEmail==false) ){
	alert("You have entered in a invalid email address");
	theForm.email.focus();
	return (false);
	}
return (true);
}

function checkCat(theForm)
{
 	if (theForm.title.value == "")
  {
    alert("Please enter a value for the \"Title\" field.");
    theForm.title.focus();
    return (false);
  }
  return (true);
}

function deleteCheck(theForm)
{
if (theForm.deleteLock.checked == false)
  {
    alert("If you are sure you want to delete this item and all items associated with it.\nCheck the \"Delete Lock\" box and hit the delete button again.");
    return (false);
  }
  return (true);
}

var hK;
function hkOpen(winurl,winname,winfeatures)
{
	hK = window.open(winurl,winname,winfeatures);
 	setTimeout('hK.focus();',250);
}

// Universal Functions
// Checks for Valid Email Formats
function IsValidEmail (strEmail){
		var bIsValid=true;
		var Space1=" ";
		var At1="@";
		var Dot1=".";
		var strTemp=new String(strEmail);
		if (strTemp.length < 5) 
				bIsValid = false;
		
		if (strTemp.indexOf(Space1)>0)
				bIsValid = false;
		
		if (strTemp.indexOf(At1)<2)
				bIsValid = false;
		
		if (strTemp.lastIndexOf(Dot1) < strTemp.indexOf(At1, 1) + 1)
				bIsValid = false;
		return bIsValid; 
}
// Checks to see if Date is formatted correctly
function checkdate(theDate)
{
var valid = 1
value = theDate
	var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
		var match=value.match(dateregex);
			if (match) 
				{
				var tmpdate=new Date(match[3],parseInt(match[1])-1,match[2]);
				if (tmpdate.getDate()==parseInt(match[2]) && tmpdate.getFullYear()==parseInt(match[3]) && (tmpdate.getMonth()+1)==parseInt(match[1]))
				{ 
			return valid
			}
		}
	}
//
// Checks for Currency Formats
function hkCurrency(TheNumber) {
var valid = 1
var hkGoodNumbers = "0123456789,."
var i = 0
if (TheNumber=="") {
valid = 0
	}
for (i =0; i <= TheNumber.length -1; i++) {
if (hkGoodNumbers.indexOf(TheNumber.charAt(i)) == -1) {
valid = 0
}
	}
return valid
}

// Checks for Numbesr Only
function hkNumbers(TheNumber) {
var valid = 1
var hkGoodNumbers = "0123456789"
var i = 0
if (TheNumber=="") {
valid = 0
	}
for (i =0; i <= TheNumber.length -1; i++) {
if (hkGoodNumbers.indexOf(TheNumber.charAt(i)) == -1) {
valid = 0
}
	}
return valid
}
//

///////////  Related Products Script

function assignProgram()
{
	var oOption = new Option();
	varIndex=document.thisInputForm.programNotAss.selectedIndex;
	if(varIndex<0)
	{
		SaveProgramsAsText();
		return;
	}
	oOption.text=document.thisInputForm.programNotAss.options[varIndex].text;
	oOption.value=document.thisInputForm.programNotAss.options[varIndex].value;
	document.thisInputForm.programAss.add(oOption);
	document.thisInputForm.programNotAss.remove(varIndex);
	SaveProgramsAsText();
}
function unassignProgram()
{
	var oOption = new Option();
	varIndex=document.thisInputForm.programAss.selectedIndex;
	if(varIndex<0)
	{
		SaveProgramsAsText();
		return;
	}
	selprogvalue = document.thisInputForm.programAss.options[varIndex].value;
	oOption.text=document.thisInputForm.programAss.options[varIndex].text;
	oOption.value=document.thisInputForm.programAss.options[varIndex].value;
	document.thisInputForm.programAss.remove(varIndex);
	document.thisInputForm.programNotAss.add(oOption);
	SaveProgramsAsText();
}

function SaveProgramsAsText()
{
    document.thisInputForm.newRelatedProducts.value="";
    for(i=0;i<document.thisInputForm.programAss.length;i++)
	{
	if(i!=0){
	document.thisInputForm.newRelatedProducts.value+=", "+document.thisInputForm.programAss(i).value
	} else {
	document.thisInputForm.newRelatedProducts.value+=+document.thisInputForm.programAss(i).value
	}
	}
    return;
}
var negprogs
negprogs=""		

///////////  Related Products Script



/**************************************************************/
/* You may freely distribute and modify the following code,  */
/* but please don't delete the refference to my email id, so  */
/* that people could ask the updates on it ... THANK YOU     */
/* AUTHOR: Rajesh (Kochu)                                   */
/* EMAIL: rajeshkochu@hotmail.com          */
/**************************************************************/

function checkExt(theForm)
{
//Checks wheather any file is present for uploading
if(theForm.upload.value=="")
{
alert("Please select the image")
return false
}
var t=theForm.upload.value
var f=t.split('.')
if (f.length>2)
{
alert("The file type is not Correct or please check the file type...")
return false
}
else
{
if((theForm.upload.value.lastIndexOf(".jpg")==-1) && (theForm.upload.value.lastIndexOf(".gif")==-1) && (theForm.upload.value.lastIndexOf(".JPG")==-1) && (theForm.upload.value.lastIndexOf(".GIF")==-1))
{
alert("You can upload only GIF and JPG extention files")
return false
}
//Checks wheather any file is present for uploading

}
return true
}