//======================================================================
// COMPATIBILITY FUNCTIONS
//======================================================================
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);

//======================================================================
// FORM VALIDATION FUNCTIONS
//======================================================================

function IsBlank(obj){return (GetValue(obj)=="");}

function IsEqual(obj1, obj2){return (GetValue(obj1)==GetValue(obj2));}

function IsEmail(obj, allowBlank){
	var s = new String(GetValue(obj));
    var i = 1;
    var sLength = s.length;

    if (!obj || sLength==0) {return (allowBlank) ? true : false;} //check length
    while ((i < sLength) && (s.charAt(i) != "@")) {i++;} //find @
	
	if ((i >= sLength) || (s.charAt(i) != "@")) {return false;}
    else {i += 2;}
    
    while ((i < sLength) && (s.charAt(i) != ".")) {i++;}//find .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {return false;}
	else {return true;}   
}

function IsNumeric(strString, allowBlank){
	if (strString.length == 0){return (allowBlank) ? true : false;}
	
	var strValidChars = "0123456789.,-$";
	var strChar;
	var blnResult = true;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
	   strChar = strString.charAt(i);
	   if (strValidChars.indexOf(strChar) == -1){blnResult = false;}
	}
	return blnResult;
}

function ValidateCC(cc_type, cc_number, allowBlank){
	var valid = true;
	var cc_len = cc_number.length;

	if(cc_number == ""){return (allowBlank ? true : false);}
	if(cc_number.indexOf(" ") != -1 || cc_number.indexOf("-") != -1){valid=false;}
	if(!parseInt(cc_number)){valid=false;}

	var cc_lft2 = cc_number.substr(0,2);
	var cc_lft4 = cc_number.substr(0,4);

	if(cc_type == "VISA") {
		if(cc_len != 13 && cc_len != 16){valid=false;}
		if(parseInt(cc_number.charAt(0)) != 4){valid=false;}
	}
	else if(cc_type == "MC") {
		if(cc_len != 16){valid=false;}
		if(parseInt(cc_lft2) < 51 || parseInt(cc_lft2) > 55){valid=false;}
	}
	else if(cc_type == "AMEX") {
		if(cc_len != 15){valid=false;}
		if(parseInt(cc_lft2) != 34 && parseInt(cc_lft2) != 37){valid=false;}
	}
	else if(cc_type == "DISC") {
		if(cc_len != 16){valid=false;}
		if(parseInt(cc_lft4) != 6011){valid=false;}
	}
	else {valid=false;}

	if (valid){
		//STAGE 2 Validation
		var x=1;
		var total = 0;
		var temp;
		for(i=cc_len-1;i>=0;i--){
			temp = cc_number.charAt(i) * x
			if (temp > 9){temp = (temp % 10) + 1;}
			total += temp;
			x = 2/x;
		}
		if((total % 10) != 0){valid=false;}
	}

	return(valid);
}


function GetValue(obj){
	var val = null;
	if(obj){
		var tagName = (arguments[1]!=null)? arguments[1] : obj.tagName;
		
		if(tagName==null){
			if(obj.length){return GetValue(obj, obj[0].tagName);}
		}else{
			switch(tagName){
				case "SELECT":
					if(obj.selectedIndex>-1){val = obj.options[obj.selectedIndex].value;}
					else{val = "";}
					break;

				default:
					if(obj.length){
						for(i=0;i<obj.length;i++){
							if(obj[i].checked){val=obj[i].value;break;}
						}
						if(val==null){val="";}
					}else{
						val = obj.value;
					}
					break;
			}
		}
	}
	return val;
}

//======================================================================
// QTY Functions
//======================================================================
function SetProductQtyValue(obj){
	if(!obj){return;}
	
	var oQty = document.getElementById("SKUQty");
	if(oQty){oQty.value = (obj.checked) ? "1" : "";}
}

function SetQtyValue(obj){
	if(!obj){return;}
	
	var oQty = document.getElementById("SKUQty_" + obj.value);
	if(oQty){
		oQty.value = (obj.checked) ? "1" : "";
	}
}