var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {


  	// Array to hold the permitted card characteristics
	var cards = new Array();

  	// Define the cards we support. You may add addtional card types.

  	//  Name:      As in the selection box of the form - must be same as user's
  	//  Length:    List of possible valid lengths of the card number for the card
  	//  prefixes:  List of possible prefixes for the card
  	//  checkdigit Boolean to say whether there is a check digit

  	cards [0] = {name: "VISA",
               length: "13,16",
               prefixes: "4",
               checkdigit: true};
  	cards [1] = {name: "Mastercard",
               length: "16",
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  	cards [2] = {name: "American Express",
               length: "15",
               prefixes: "34,37",
               checkdigit: true};
  	cards [3] = {name: "Discover",
               length: "16",
               prefixes: "6011,650",
               checkdigit: true};

  	// Establish card type
  	var cardType = -1;
  	for (var i=0; i<cards.length; i++)
  	{
		// See if it is this card (ignoring the case of the string)
		if (cardname.toLowerCase () == cards[i].name.toLowerCase())
    	{
      		cardType = i;
      		break;
    	}
  	}

  	// If card type not found, report an error
  	if (cardType == -1)
  	{
    	ccErrorNo = 0;
     	return false;
  	}

  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false;
  }

  // Now remove any spaces from the credit card number
  cardnumber = cardnumber.replace (/\s/g, "");

  // Check that the number is numeric
  var cardNo = cardnumber
  var cardexp = /^[0-9]{13,19}$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false;
  }

  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2

    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {

      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;

      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }

      // Add the units element to the checksum total
      checksum = checksum + calc;

      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    }

    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false;
    }
  }

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false;
  var undefined;

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();

  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");

  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }

  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false;
  }

  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }

  // See if all is OK by seeing if the length was valid. We only check the
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false;
  };

  // The credit card is in the required format.
  return true;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate()
{
	var argv = isExpiryDate.arguments;
	var argc = isExpiryDate.arguments.length;

	year = argc > 0 ? argv[0] : this.year;
	month = argc > 1 ? argv[1] : this.month;

	if (!isNum(year+""))
	return false;
	if (!isNum(month+""))
	return false;
	today = new Date();
	expiry = new Date(year, month);
	if (today.getTime() > expiry.getTime())
	return false;
	else
	return true;
}
/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
/*
//--------- Commented this function as it is redefined later ---------
function isNum(argvalue) {
	if(argvalue != "undefined" && argvalue != "")
	{
		argvalue = argvalue.toString();
		if (argvalue.length == 0)
			return false;
		for (var n = 0; n < argvalue.length; n++)
		if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
			return false;
		return true;
	}
	return false;
}
*/

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
\*************************************************************************/
function luhnCheck() {
	var argv = luhnCheck.arguments;
	var argc = luhnCheck.arguments.length;

	var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

	if (! isNum(CardNumber)) {
	return false;
	  }

	var no_digit = CardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;

	for (var count = 0; count < no_digit; count++) {
	var digit = parseInt(CardNumber.charAt(count));
	if (!((count & 1) ^ oddoeven)) {
	digit *= 2;
	if (digit > 9)
	digit -= 9;
	}
	sum += digit;
	}
	if (sum % 10 == 0)
	return true;
	else
	return false;
}
/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
this.size = size;
return this;
}
/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
this.cardnumber = cardnumber;
return this;
}
/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
this.cardtype = cardtype;
return this;
}
/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
this.year = year;
this.month = month;
return this;
}
/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
	// Create the len array.
	if (len.length == 0 || len == null)
	len = "13,14,15,16,19";
	var tmplen = len;
	n = 1;
	while (tmplen.indexOf(",") != -1) {
	tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);n++;}
	this.len = new makeArray(n);
	n = 0;
	while (len.indexOf(",") != -1) {
	var tmpstr = len.substring(0, len.indexOf(","));
	this.len[n] = tmpstr;
	len = len.substring(len.indexOf(",") + 1, len.length);
	n++;
	}
	this.len[n] = len;
	return this;
}
/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
	// Create the rules array.
	if (rules.length == 0 || rules == null)
	rules = "0,1,2,3,4,5,6,7,8,9";

	var tmprules = rules;
	n = 1;
	while (tmprules.indexOf(",") != -1) {
	tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
	n++;
	}
	this.rules = new makeArray(n);
	n = 0;
	while (rules.indexOf(",") != -1) {
	var tmpstr = rules.substring(0, rules.indexOf(","));
	this.rules[n] = tmpstr;
	rules = rules.substring(rules.indexOf(",") + 1, rules.length);
	n++;
	}
	this.rules[n] = rules;
	return this;
}
/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
	if(argvalue != "undefined" && argvalue != null)
	{
		argvalue = argvalue.toString();
		if (argvalue.length == 0)
			return false;
		for (var n = 0; n < argvalue.length; n++)
			if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
				return false;
		return true;
	}
	return false;
}

function checkExpiryDate()
{
	 // check if date is greater than current system date
	var today=new Date();
	if((document.getElementById('oodform1').cmbDtExpiryYear.value)>today.getFullYear())
		return true;
	if((document.getElementById('oodform1').cmbDtExpiryYear.value)==today.getFullYear())
	{
		if(document.getElementById('oodform1').cmbDtExpiryMonth.value>=today.getMonth())
			return true;
		else
			return false;
	}
	else
		return false;
}

function validateEmail(mail)
{
	if(mail.indexOf("@")==-1 || mail.indexOf("@")==0 || (mail.indexOf("@")==(mail.length-1)))
		return false;
	if(mail.indexOf(".")==-1|| (mail.indexOf(".")==(mail.length-1))|| (mail.indexOf(".")-mail.indexOf("@")==1)|| (mail.indexOf(".")-mail.indexOf("@")==-1))
		return false;

	for(var i=0;i<mail.length;i++)
		if(mail.charAt(i)==" ")
			return false;

	return true;
}

function isValidPhoneNo(thestring)
{
	var OK=true;
	for(var i=0;i<thestring.length;i++)
	{
		thechar=thestring.charAt(i);
		if((thechar<"0") || (thechar>"9"))
		{
			//if(!((thechar=="+") || (thechar=="(") || (thechar==")") || (thechar=="-") || (thechar==" ")))
			if(!((thechar=="+") || (thechar=="(") || (thechar==")") || (thechar=="-") ))
			{
				OK=false;
				break;
			}
		}
	}
	return OK;
}
// This function is for validating the name
function isValidName(thestring)
{
	var OK=true;
	for(var i=0;i<thestring.length;i++)
	{
		// Allow "spaces" before or after the name
		// Refers bugs reported by Dean - Relax SQL filter
		// Commented the following checks the remove the bug.
		/*
		if(thestring.charAt(0)==" ")
		{
			OK=false;
			break;
		}
		var len=thestring.length;
		if(thestring.charAt(len-1)==" ")
		{
			OK=false;
			break;
		}
		*/
		thechar=thestring.charAt(i);
		if((thechar<"0") || (thechar>"9"))
		{
			if(!(thechar=="'"))
			{
				if((thechar<"a") || (thechar>"z"))
				{
					if((thechar<"A") || (thechar>"Z"))
					{
						if(!(thechar==" "))
						{
							if(!(thechar=="."))
							{
								OK=false;
								break;
							}
						}
					}
				}
			}
		}
	}
	return OK;
}

function CheckAlphanum(thestring, blnAllowSingleChar, blnAllowSpecialChars)
{
	//var charpos = thestring.search(/^[a-zA-Z0-9]+(\s)*[a-zA-Z0-9\s]+$/g) ;
	//var charpos = thestring.search(/^[a-zA-Z0-9.\-]+(\s)*[a-zA-Z0-9.\-\s]+$/g) ;
	if(blnAllowSingleChar == null || blnAllowSingleChar == "undefined" )
	{
		// Validation for form fields. Do not allow single character to be entered
		if(blnAllowSpecialChars == null || blnAllowSpecialChars == "undefined" )
			var charpos = thestring.search(/^[a-zA-Z0-9.\s\-]+(\s)*[a-zA-Z0-9.\-\s]+$/g) ;
		else
			var charpos = thestring.search(/^[a-zA-Z0-9#.\/\s\-]+(\s)*[a-zA-Z0-9#.\/\-\s]+$/g) ;

	}
	else
	{
		// Allow single character to be entered only in Address2 field

		if(blnAllowSpecialChars == null || blnAllowSpecialChars == "undefined" )
			var charpos = thestring.search(/^[a-zA-Z0-9.\s\-]+/g) ;
		else
			var charpos = thestring.search(/^[a-zA-Z0-9#.\/\s\-]+/g) ;
	}
	if(charpos==-1)
		return false;
	else
		return true;

}

function Mod10(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
// change alert to on-page display or other indication as needed.
/*if(bResult) {
  alert("This IS a valid Credit Card Number!");
}
if(!bResult){
  alert("This is NOT a valid Credit Card Number!");
}*/
  return bResult; // Return the results
}
function isInteger (s)
{
	var i;
    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}
// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

//Opening New Window code by Dean
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';

  cookie_str = document.cookie;
  cookie_str.toString();

  pos_start  = cookie_str.indexOf(name);
  pos_end    = cookie_str.indexOf('=', pos_start);

  cookie_name = cookie_str.substring(pos_start, pos_end);

  pos_start  = cookie_str.indexOf(name);
  pos_start  = cookie_str.indexOf('=', pos_start);
  pos_end    = cookie_str.indexOf(';', pos_start);

  if (pos_end <= 0) pos_end = cookie_str.length;
  cookie_val = cookie_str.substring(pos_start + 1, pos_end);
  if (cookie_name == name && cookie_val  == "done")
    return;

  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

//End
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function fnGetSelectedCountry(objState)
{
	//alert(document.getElementById('oodform1').CmbState.value);
	if(document.getElementById('oodform1').CmbState.value=="0")
	{
		document.getElementById('oodform1').CmbCountry.selectedIndex=0;
	}
	else if(document.getElementById('oodform1').CmbState.value=="AB" || document.getElementById('oodform1').CmbState.value=="BC" || document.getElementById('oodform1').CmbState.value=="MB" || document.getElementById('oodform1').CmbState.value=="NL" || document.getElementById('oodform1').CmbState.value=="NB" || document.getElementById('oodform1').CmbState.value=="NT" || document.getElementById('oodform1').CmbState.value=="NS" || document.getElementById('oodform1').CmbState.value=="NU" || document.getElementById('oodform1').CmbState.value=="ON" || document.getElementById('oodform1').CmbState.value=="PE" || document.getElementById('oodform1').CmbState.value=="QC" || document.getElementById('oodform1').CmbState.value=="SK" || document.oodform1.CmbState.value=="YT")
	{
		document.getElementById('oodform1').CmbCountry.selectedIndex=2;
	}
	else
	{
		//alert('usa');
		document.getElementById('oodform1').CmbCountry.selectedIndex=1;
	}

}

function fnGetSelectedShipCountry(objState)
{

	if(document.getElementById('oodform1').CmbShipState.value=="0")
	{
		document.getElementById('oodform1').CmbShipCountry.selectedIndex=0;
	}
	else if(document.getElementById('oodform1').CmbShipState.value=="AB" || document.getElementById('oodform1').CmbShipState.value=="BC" || document.getElementById('oodform1').CmbShipState.value=="MB" || document.getElementById('oodform1').CmbShipState.value=="NL" || document.getElementById('oodform1').CmbShipState.value=="NB" || document.getElementById('oodform1').CmbShipState.value=="NT" || document.getElementById('oodform1').CmbShipState.value=="NS" || document.getElementById('oodform1').CmbShipState.value=="NU" || document.getElementById('oodform1').CmbShipState.value=="ON" || document.getElementById('oodform1').CmbShipState.value=="PE" || document.getElementById('oodform1').CmbShipState.value=="QC" || document.getElementById('oodform1').CmbShipState.value=="SK" || document.oodform1.CmbShipState.value=="YT")
	{
		document.getElementById('oodform1').CmbShipCountry.selectedIndex=2;
	}
	else
	{
		document.getElementById('oodform1').CmbShipCountry.selectedIndex=1;
	}

}

function CheckQty()
{
	if(!isNum(document.getElementById('oodform1').cmbQuantity.value))
	{
		alert('Please Enter valid Quantity.');
		document.getElementById('oodform1').cmbQuantity.focus();
		return xhCancel();
	}
	else if(parseInt(document.getElementById('oodform1').cmbQuantity.value) <= 0)
	{
		alert('Please enter Valid Quantity.');
     		document.getElementById('oodform1').cmbQuantity.focus();
		return xhCancel();
	}

	return true;
	/*
	if( document.getElementById('oodform1').action)
	{
		document.getElementById ('oodform1').submit();
	}
	else
	{
		document.getElementById('oodform1').onsubmit();
	}
	*/

}

function CheckQty_snugcoll()
{
	/*alert("HI");
	alert(document.getElementById('oodform1').productCode.length);*/
	/*var total=0;
	for(var i=0; i < document.getElementById('oodform1').productCode.length; i++)
	{
		if(document.getElementById('oodform1').productCode[i].checked)
		{
			if(total < 5)
			{
				total=total+1;
			}
			else
			{
				alert("Please select 5 Schools");
				return false;
			}
		}
	}
	return true;*/
	var a=document.oodform1['productCode[]'];
	var total=0;
	for(var i=0;i<a.length;i++)
	{
		if(a[i].checked)
		{
			if(total < 5)
			{
				total=total+1;
			}
			else
			{
				alert("Please only select 5 choices");
				return false;
			}
		}
		/*else
		{

		}	*/
	}
	if(total==0)
	{
		alert("Please select atleast 1 choice");
			return false;
	}
	else
		return true;
}

/*** begin code from Eric Tirk ***/
function xhCancel(e)
{
	if(window.event)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if(e && e.preventDefault && e.stopPropagation)
	{
		e.preventDefault();
		e.stopPropagation();
	}
	return false;
}
/*** end code from Eric Tirk ***/



function validZip(zip,country)
{
	if(country == 'US')
	{
		if(zip.length == 5)
		{
			if(!isNum(zip))
			{
				return false;
			}
		}
		else
			return false;
	}
	else
	if(country == 'CN' || country == 'CA')
	{
		/*if(zip.length == 6)
		{
			if(!CheckAlphanum(zip))
			{
				return false;
			}
		}
		else
			return false;*/
		strlen=zip.length; if (strlen!==6){return false;}
		zip=zip.toUpperCase();  // in case of lowercase
		// Check for legal characters in string - note index starts at zero
		if('ABCEGHJKLMNPRSTVXY'.indexOf(zip.charAt(0))<0)
		{
			return false;
		}
		if('0123456789'.indexOf(zip.charAt(1))<0)
		{
			return false;
		}
		if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(zip.charAt(2))<0)
		{
			return false;
		}
		if('0123456789'.indexOf(zip.charAt(3))<0)
		{
			return false;
		}
		if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(zip.charAt(4))<0)
		{
			return false;
		}
		if('0123456789'.indexOf(zip.charAt(5))<0)
		{
			return false;
		}
		return true;
	}

	return true;
}

// function checks whether atleast 1 product has been purchased by the user
// The user is provided with the Quantity checkboxes to purchase the items
function SelectProduct()
{
	var a=document.oodform1['productCode[]'];
	var total=0;
	for(var i=0;i<a.length;i++)
	{
		if(a[i].checked)
		{
			total=total+1;
		}
	}
	if(total==0)
	{
		alert("Please select atleast 1 choice");
			return false;
	}
	else
		return true;
}


// function used for special logic "magazine one" that check whether
// 1. User must select at least 1 magazine
// 2. User has selected at the most two magazines
function SelectProductMagazineSplLogic(id)
{
	var a=document.oodform1['productCode[]'];
	var total=0;
	for(var i=0;i<a.length;i++)
	{
		if(a[i].checked)
			total++;
	}
	if(total <= 0)
	{
		alert("Please select at least one magazine");
		return false;
	}
	if(total > 2)
	{
		alert("You can slelect only two magazines");
		id.checked = false;
		return false;
	}
	else
		return true;
}




// function checks whether qunatity is greater then 0 for website = strpbra i.e. atleast one product needs to be selected
function checkProductStrapb()
{
		if(document.getElementById('Quantity2').value <=0 && document.getElementById('Quantity1').value <=0)
		{
			alert("Please select atleast 1 choice");
			return false;
		}
		else
			return true;
}





// function checks whether atleast 1 product has been purchased by the user
// The user is provided with the Quantity dropdown to purchase the items
function validateProductsPurchased()
{
	blnReturn = false;
	var productCodes = document.oodform1['productCodes'].value;
	var arrProductCodes = productCodes.split(",");
	var total=0;
	for(var i=0; i<arrProductCodes.length; i++)
	{
		selQty = "cmbQuantity_" + arrProductCodes[i];
		objQty = document.getElementById(selQty);
		if( objQty[objQty.selectedIndex].value > 0 )
		{
			blnReturn = true;
			break;
		}
	}
	if(!blnReturn)
		alert("Please select atleast 1 product");

	return blnReturn;
}


function fnValidateForm(objform)
{
	with(objform)
	{
		if(itemstatus.value == 1)
		{
			if(cmbQuantity.value=="")
			{
				alert('Please Select Quantity.');
				cmbQuantity.focus();
				return false;
			}
			if(!isNum(cmbQuantity.value))
			{
				alert('Please Enter valid Quantity.');
				cmbQuantity.focus();
				return false;
			}
			else if(parseInt(cmbQuantity.value) <= 0)
			{
				alert('Please enter Valid Quantity.');
				cmbQuantity.focus();
				return false;
			}

			if(cmbType.value=="")
			{
				alert('Please Select Type.');
				cmbType.focus();
				return false;
			}
			if(txtCreditCardNo.value=="")
			{
				alert('Please Enter Credit Card Number.');
				txtCreditCardNo.focus();
				return false;
			}

			if(!checkCreditCard(txtCreditCardNo.value,cmbType.value))
			{
				alert (ccErrors[ccErrorNo]);
				txtCreditCardNo.focus();
				return false;
			}
			if(txtCSCno.value=="")
			{
				alert('Please Enter CSC Number.');
				txtCSCno.focus();
				return false;
			}
			else if (!isNum(txtCSCno.value))
			{
				alert('Please Enter Correct CSC Number.');
				txtCSCno.focus();
				return false;
			}
			if(!checkExpiryDate())
			{
				alert('Please Select Valid Expiry Date.');
				cmbDtExpiryMonth.focus();
				return false;
			}
			if(!isValidName(txtFirstName.value) || txtFirstName.value=="")
			{
				alert('Please Enter Valid Billing First Name.');
				txtFirstName.focus();
				return false;
			}
			else if (!CheckAlphanum(txtFirstName.value))
			{
				alert('only Numbers, Letters and Dashes are allowed.');
				txtFirstName.focus();
				return false;
			}
			if(!isValidName(txtLastName.value) ||txtLastName.value=="")
			{
				alert('Please Enter Valid Billing Last Name.');
				txtLastName.focus();
				return false;
			}
			else if (!CheckAlphanum(txtLastName.value))
			{
				alert('only Numbers, Letters and Dashes are allowed.');
				txtLastName.focus();
				return false;
			}

			if(txtAddress1.value=="")
			{
				alert('Please Enter Billing Address1.');
				txtAddress1.focus();
				return false;
			}
			else if (!CheckAlphanum(txtAddress1.value, null, "true"))
			{
				alert('only Numbers, Letters and Dashes are allowed.');
				txtAddress1.focus();
				return false;
			}

			if(txtAddress2.value.length > 0)
			{
				if (!CheckAlphanum(txtAddress2.value, "true", "true"))
				{
					alert('only Numbers, Letters and Dashes are allowed.');
					txtAddress2.focus();
					return false;
				}
			}
			if(txtCity.value=="")
			{
				alert('Please Enter Billing City.');
				txtCity.focus();
				return false;
			}
			else if (!CheckAlphanum(txtCity.value))
			{
				alert('only Numbers, Letters and Dashes are allowed.');
				txtCity.focus();
				return false;
			}
			if(CmbState.value=="0")
			{
				alert('Please Select Billing State.');
				CmbState.focus();
				return false;
			}
			if(txtZip.value=="")
			{
				alert('Please Enter Billing Zip.');
				txtZip.focus();
				return false;
			}
			else if (!validZip(txtZip.value,CmbCountry.value))
			{
				alert('Please Enter Valid Billing Zipcode(Special Charactes are not allowed)');
				txtZip.focus();
				return false;
			}
			if(CmbCountry.value=="")
			{
				alert('Please Select Billing Country.');
				CmbCountry.focus();
				return false;
			}
			if(txtEmail.value=="")
			{
				alert('Please Enter Billing Email.');
				txtEmail.focus();
				return false;
			}
			if(!validateEmail(txtEmail.value))
			{
				alert("Please Enter Valid Billing Email Address.");
				txtEmail.focus();
				return false;
			}
			if(txtEmail.value!=txtConfirmEmail.value)
			{
				alert('Billing Email and Confirm Email Should be Identical!');
				txtConfirmEmail.focus();
				return false;
			}
			if(!isValidPhoneNo(txtPhone1.value) || txtPhone1.value =="")
			{
				alert("Please Enter Valid Billing Phone Number.");
				txtPhone1.focus();
				return false;
			}
			if(txtPhone1.value.length!=3 )
			{
				alert("Please Enter Valid Area Code. Must be 3 Digit.");
				txtPhone1.focus();
				return false;
			}

			if(!isValidPhoneNo(txtPhone2.value)|| txtPhone2.value =="")
			{
				alert("Please Enter Valid Billing Phone Number.");
				txtPhone2.focus();
				return false;
			}
			if(txtPhone2.value.length!=3)
			{
				alert("Please Enter Valid Number. Must be 3 Digit.");
				txtPhone2.focus();
				return false;
			}

			if(!isValidPhoneNo(txtPhone3.value) || txtPhone3.value =="")
			{
				alert("Please Enter Valid Billing Phone Number.");
				txtPhone3.focus();
				return false;
			}
			if(txtPhone3.value.length!=4)
			{
				alert("Please Enter Valid Number. Must be 4 Digit.");
				txtPhone3.focus();
				return false;
			}

			if(document.getElementsByName("shipinfo")[0])
			{
				/*for (i=0;i<shipinfo.length;i++)
				{
		  			if (shipinfo[i].checked)
		  			{
						rbgroup_value = shipinfo[i].value;
			  		}
				} */


				if (shipinfo[1].checked)
				{
					if(!isValidName(txtShipFirstName.value) || txtShipFirstName.value=="")
					{
						alert('Please Enter Valid Shipping First Name.');
						txtShipFirstName.focus();
						return false;
					}
					else if (!CheckAlphanum(txtShipFirstName.value))
					{
						alert('only Numbers, Letters and Dashes are allowed.');
						txtShipFirstName.focus();
						return false;
					}
					if(!isValidName(txtShipLastName.value) ||txtShipLastName.value=="")
					{
						alert('Please Enter Valid Shipping Last Name.');
						txtShipLastName.focus();
						return false;
					}
					else if (!CheckAlphanum(txtShipLastName.value))
					{
						alert('only Numbers, Letters and Dashes are allowed.');
						txtShipLastName.focus();
						return false;
					}

					if(txtShipAddress1.value=="")
					{
						alert('Please Enter Shipping Address1.');
						txtShipAddress1.focus();
						return false;
					}
					else if (!CheckAlphanum(txtShipAddress1.value, "true", "true"))
					{
						alert('only Numbers, Letters and Dashes are allowed.');
						txtShipAddress1.focus();
						return false;
					}

					if(txtShipAddress2.value.length > 0)
					{
						if (!CheckAlphanum(txtShipAddress2.value, "true", "true"))
						{
							alert('only Numbers, Letters and Dashes are allowed.');
							txtShipAddress2.focus();
							return false;
						}
					}

					if(txtShipCity.value=="")
					{
						alert('Please Enter Shipping City.');
						txtShipCity.focus();
						return false;
					}
					else if (!CheckAlphanum(txtShipCity.value))
					{
						alert('only Numbers, Letters and Dashes are allowed.');
						txtShipCity.focus();
						return false;
					}
					if(CmbShipState.value=="0")
					{
						alert('Please Select Shipping State.');
						CmbShipState.focus();
						return false;
					}

					if(txtShipZip.value=="")
					{
						alert('Please Enter Shipping Zip.');
						txtShipZip.focus();
						return false;
					}
					else if (!validZip(txtShipZip.value,CmbShipCountry.value))
					{
						alert('Please Enter Valid Zipcode(Special Charactes are not allowed)');
						txtShipZip.focus();
						return false;
					}
					if(CmbShipCountry.value=="")
					{
						alert('Please Select Shipping Country.');
						CmbShipCountry.focus();
						return false;
					}

					//------ Shipping email and phone validation -----------
					if(objform.txtShipEmail)
					{
						if(txtShipEmail.value=="")
						{
							alert('Please Enter Shipping Email.');
							txtShipEmail.focus();
							return false;
						}
						if(!validateEmail(txtShipEmail.value))
						{
							alert("Please Enter Valid Shipping Email Address.");
							txtShipEmail.focus();
							return false;
						}
						/*
						if(txtShipEmail.value!=txtShipConfirmEmail.value)
						{
							alert('Shipping Email and Confirm Email Should be Identical!');
							txtShipConfirmEmail.focus();
							return false;
						}
						*/
					}

					if(objform.txtShipPhone1)
					{
						if(!isValidPhoneNo(txtShipPhone1.value) || txtShipPhone1.value =="")
						{
							alert("Please Enter Valid Shipping Phone Number.");
							txtShipPhone1.focus();
							return false;
						}
						if(txtShipPhone1.value.length!=3 )
						{
							alert("Please Enter Valid Area Code. Must be 3 Digit.");
							txtShipPhone1.focus();
							return false;
						}
					}

					if(objform.txtShipPhone2)
					{
						if(!isValidPhoneNo(txtShipPhone2.value)|| txtShipPhone2.value =="")
						{
							alert("Please Enter Valid Shipping Phone Number.");
							txtShipPhone2.focus();
							return false;
						}
						if(txtShipPhone2.value.length!=3)
						{
							alert("Please Enter Valid Number. Must be 3 Digit.");
							txtShipPhone2.focus();
							return false;
						}
					}

					if(objform.txtShipPhone3)
					{
						if(!isValidPhoneNo(txtShipPhone3.value) || txtShipPhone3.value =="")
						{
							alert("Please Enter Valid Shipping Phone Number.");
							txtShipPhone3.focus();
							return false;
						}
						if(txtShipPhone3.value.length!=4)
						{
							alert("Please Enter Valid Number. Must be 4 Digit.");
							txtShipPhone3.focus();
							return false;
						}
					}
					//------------------------------------------------------
				}
			}
			if(!fnCheckPOBox())
			{
				return false;
			}
			else
				return true;
		}
		else
		{
			return true;
		}
	}

}

function fnCheckPOBox()
{
	var strAddress;
	strAddress = window.document.getElementById('oodform1').txtAddress1.value;
	//alert(strAddress);
	var i=0;
	var cnt=0;
	for(i=0;i<strAddress.length;i++)
	{
		cnt=cnt+1;
		c=strAddress.charAt(i)
		if(c=="p"||c=="P")
		{
			//After p
			if(strAddress.charAt(i+1)=="."||strAddress.charAt(i+1)==" ")
			{
				if(strAddress.charAt(i+2)=="o"||strAddress.charAt(i+2)=="O")
				{
					if(strAddress.charAt(i+3)=="."||strAddress.charAt(i+3)==" ")
					{
						if(strAddress.charAt(i+4)==" ")
						{
							if(strAddress.charAt(i+5)=="b"||strAddress.charAt(i+5)=="B")
							{
								if(strAddress.charAt(i+6)=="o"||strAddress.charAt(i+6)=="O")
								{
									if(strAddress.charAt(i+7)=="x"||strAddress.charAt(i+7)=="X")
									{
										alert("The Address is in wrong format:- we are not accepting P.O.");
										window.document.getElementById('oodform1').txtAddress1.focus();
										return false;
									}
								}
							}
						}
						if(strAddress.charAt(i+4)=="b"||strAddress.charAt(i+4)=="B")
						{
							if(strAddress.charAt(i+5)=="o"||strAddress.charAt(i+6)=="O")
							{
								if(strAddress.charAt(i+6)=="x"||strAddress.charAt(i+6)=="X")
								{
									alert("The Address is in wrong format:- we are not accepting P.O.");
									window.document.getElementById('oodform1').txtAddress1.focus();
									return false;
								}
							}
						}
					}
				}
				//after p.
				if(strAddress.charAt(i+2)==" ")
				{
					//alert("p.space");
					if(strAddress.charAt(i+3)=="o"||strAddress.charAt(i+3)=="O")
					{
						if(strAddress.charAt(i+4)=="."||strAddress.charAt(i+4)==" ")
						{
							if(strAddress.charAt(i+5)=="b"||strAddress.charAt(i+5)=="B")
							{
								if(strAddress.charAt(i+6)=="o"||strAddress.charAt(i+6)=="O")
								{
									if(strAddress.charAt(i+7)=="x"||strAddress.charAt(i+7)=="X")
									{
										alert("The Address is in wrong format:- we are not accepting P.O.");
										window.document.getElementById('oodform1').txtAddress1.focus();
										return false;
									}
								}
							}
							if(strAddress.charAt(i+5)==" ")
							{
								if(strAddress.charAt(i+6)=="b"||strAddress.charAt(i+6)=="B")
								{
									if(strAddress.charAt(i+7)=="o"||strAddress.charAt(i+7)=="O")
									{
										if(strAddress.charAt(i+8)=="x"||strAddress.charAt(i+8)=="X")
										{
											alert("The Address is in wrong format:- we are not accepting P.O.");
											window.document.getElementById('oodform1').txtAddress1.focus();
											return false;
										}
									}
								}
							}
						}
						//after p.o
						if(strAddress.charAt(i+4)=="b"||strAddress.charAt(i+4)=="B")
						{
							if(strAddress.charAt(i+5)=="o"||strAddress.charAt(i+6)=="O")
							{
								if(strAddress.charAt(i+6)=="x"||strAddress.charAt(i+6)=="X")
								{
									alert("The Address is in wrong format:- we are not accepting P.O.");
									window.document.getElementById('oodform1').txtAddress1.focus();
									return false;
								}
							}
						}
					}
				}
			}
			//after p
			if(strAddress.charAt(i+1)=="o"||strAddress.charAt(i+1)=="O")
			{
				if(strAddress.charAt(i+2)==" "||strAddress.charAt(i+2)!=" ")
				{
					if(strAddress.charAt(i+3)=="b"||strAddress.charAt(i+3)=="B")
					{
						if(strAddress.charAt(i+4)=="o"||strAddress.charAt(i+4)=="O")
						{
							if(strAddress.charAt(i+5)=="x"||strAddress.charAt(i+5)=="X")
							{
								alert("The Address is in wrong format:- we are not accepting P.O.");
								window.document.getElementById('oodform1').txtAddress1.focus();
								return false;
							}
						}
					}
				}
				if(strAddress.charAt(i+2)=="b"||strAddress.charAt(i+2)=="B")
				{
					if(strAddress.charAt(i+3)=="o"||strAddress.charAt(i+3)=="O")
					{
						if(strAddress.charAt(i+4)=="x"||strAddress.charAt(i+4)=="X")
						{
							alert("The Address is in wrong format:- we are not accepting P.O.");
							window.document.getElementById('oodform1').txtAddress1.focus();
							return false;
						}
					}
				}

			}
		}
		else
			return true;
	}
}

// JavaScript Document
function fnNumbersOnly()
		{
			if(window.event.keyCode==13)
			{
				if(document.frmAddUpsellItems.txtQuantity.value=="")
				{
					return false;
				}
				else
				{
				    return true;
				}
			}
			else if (window.event.keyCode>=48 && window.event.keyCode<=57)
			{
				return true;
			}
			else
			{
				alert("Please Enter Numbers Only");
				return false;
			}
		}


	/*****************************************************************/
		//Checking AlphaNumeric
		function fnAlphaNumericsOnly()
		{

			if(window.event.keyCode==13)
			{
				if(document.frmAddUpsellItems.txtQuantity.value=="")
				{
					return false;
				}
				else
				{
				    return true;
				}
			}
			else if (window.event.keyCode>=48 && window.event.keyCode<=57)
			{
				return true;
			}
			else
				return false;
		}
	/*****************************************************************/
		function ShowHidePanel(show)
		{
			if(show=="1")
			{
				document.all.spanShippingInformation.style.display="block";
			}
			else
			{
				document.all.spanShippingInformation.style.display="none";
			}
		}

	/*****************************************************************/
		function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
		{
		toolbar_str = toolbar ? 'yes' : 'no';
		menubar_str = menubar ? 'yes' : 'no';
		statusbar_str = statusbar ? 'yes' : 'no';

		resizable_str = resizable ? 'yes' : 'no';

		cookie_str = document.cookie;
		cookie_str.toString();

		pos_start  = cookie_str.indexOf(name);
		pos_end    = cookie_str.indexOf('=', pos_start);

		cookie_name = cookie_str.substring(pos_start, pos_end);

		pos_start  = cookie_str.indexOf(name);
		pos_start  = cookie_str.indexOf('=', pos_start);
		pos_end    = cookie_str.indexOf(';', pos_start);

		if (pos_end <= 0) pos_end = cookie_str.length;
		cookie_val = cookie_str.substring(pos_start + 1, pos_end);
		if (cookie_name == name && cookie_val  == "done")
			return;

		window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars=yes,resizable='+resizable_str);
		}
	/*****************************************************************/

		function na_preload_img()
		{
			var img_list = na_preload_img.arguments;
			if (document.preloadlist == null)
				document.preloadlist = new Array();
			var top = document.preloadlist.length;
			for (var i=0; i < img_list.length-1; i++) {
				document.preloadlist[top+i] = new Image;
				document.preloadlist[top+i].src = img_list[i+1];
			}
		}

   /*****************************************************************/

		function na_change_img_src(name, nsdoc, rpath, preload)
		{
			var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
			if (name == '')
				return;
			if (img) {
				img.altsrc = img.src;
				img.src    = rpath;
			}
		}
	/*****************************************************************/
		function na_restore_img_src(name, nsdoc)
		{
			var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
			if (name == '')
				return;
			if (img && img.altsrc) {
				img.src    = img.altsrc;
				img.altsrc = null;
			}
		}
	/*****************************************************************/
		function na_email_validation(fname, type_name, str)
		{
			var email_validation = true
			var temp = document.forms[fname].elements[type_name]
			var at = temp.value.indexOf('@')
			var prd = temp.value.lastIndexOf('.')
			var space = temp.value.indexOf(' ')
			var length = temp.value.length - 1

			if ((at < 1) || (prd <= at+1) ||  (prd == length ) ||  (space  != -1)) {
				email_validation = false
				alert(str)
				temp.focus()
			}
			return email_validation
		}

	/*****************************************************************/
		function na_null_validate(fname, tname, str)
		{
			f_name = document[fname]
			elemnt_name = f_name[tname].value
			if (elemnt_name == "")	{
				alert(str)
				return false
			}
		}

		/*****************************************************************/
		/***********Java Script used in Form Review Page*************/

		function ChangeCursorStatus(){
			document.body.style.cursor = "wait";
			document.getElementById('oodform1').imgPlaceOrder.disabled=true;
				}
	/*****************************************************************/

		function na_restore_img_src(name, nsdoc)
			{
			var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
			 if (name == '')
			  return;
			if (img && img.altsrc) {
			  img.src    = img.altsrc;
			 img.altsrc = null;
				}
			}

	/*****************************************************************/

		function fnWholeNumbersOnly()
		{
			if(window.event.keyCode==13)
			{
				if(document.frmAddUpsellItems.txtQuantity.value=="")
				{
					return false;
				}
				else
				{
					return true;
				}
			}
			else if (window.event.keyCode>=48 && window.event.keyCode<=57)
			{
				return true;
			}
			else
				return false;
		}
		/*****************************************************************/

	    function updateQuantity(itemid, qty) //ItemNumber,Quantity
		{
			document.getElementById('oodform1').step.value = "edit";//Change Form Step Value to Edit
			document.getElementById('oodform1').itemid.value=itemid;//Assign Current Item Id Value

			document.getElementById('oodform1').itemstatus.value = 1;
			if( document.getElementById('oodform1').action)
			{
				document.getElementById('oodform1').submit();
			}
			else
			{
				document.getElementById('oodform1').onsubmit();
			}

		}

/*****************************************************************/
	//Function:Remove Product in Order Page
	function removeitem(itemid)
	{
		document.getElementById('oodform1').itemstatus.value = 0;
		document.getElementById('oodform1').itemid.value = itemid;
		document.getElementById('oodform1').step.value = "edit";
		if( document.getElementById('oodform1').action)
		{
			document.getElementById('oodform1').submit();
		}
		else
		{
			document.getElementById('oodform1').onsubmit();
		}
	}

	/*****************************************************************/
//Function:Click on Order is Place means Completed
	function placeorders()
	{
		document.getElementById('oodform1').step.value ="placeorders";

		if(!fnValidateForm(document.getElementById('oodform1')))
		{
			return false;
		}
		if(document.getElementById('oodform1').action)
		{
			document.getElementById('oodform1').submit();
		}
		else
		{
			document.getElementById('oodform1').onsubmit();
		}
	}
	/*****************************************************************/
	//function:click on Update button Updation form is display.
	function editInfo(ele)
	{
		var srcElement = document.getElementById(ele);
		if(srcElement != null)
		{
			if(srcElement.style.display == "block")
			{
				srcElement.style.display= 'none';
			}
			else
			{
				srcElement.style.display='block';
				document.getElementById('spanShippingInformation').style.display='block';
				document.getElementById('PersonalInfo').style.display='none';
			}
			return false;
		}
	}

 //Function:Update Shipping Information
   function UpdateInfo()
   {
		if(!fnValidateForm(document.getElementById('oodform1')))
		{
			return false;
		}

		if(document.getElementById('oodform1').action)
		{
			document.getElementById('oodform1').submit();
		}
		else
		{
			document.getElementById('oodform1').onsubmit();
		}
   }
