var subWin = null;
var oDoc = document.all == null ? document : document.all;
//var oForm = document.all == null ? document.forms[0] : document.all;

function hasFocus()
{
	if (subWin != null)
		subWin.focus();
}

function goBack() 
{ 
	return (window.location.href.indexOf('#') == -1)?-1:-2;
}

function getCookie(name) {
	var vals;
	var cookies = document.cookie.split(';');
	for (var i = 0; i < cookies.length; i++) {
		vals = cookies[i].split('=');
		if (vals[0] == name)
			return vals[1];
	}
	return '';
}

function imgOn(o) {
	if(!o.srcOff) o.srcOff = o.src;
	o.src = o.src.replace('Off', 'On');
}

function imgOff(o) {
	o.src = o.srcOff;
}

function BodyOnLoad() {
	//alert(getCookie('ChkOutPage'));
	/*if (< =(int)CurrentPage > != getCookie('ChkOutPage')) {
		alert('Back Button!');
	}*/
}

function printThisPage() {
	window.print();
}

function popUpKioskReset() {
	window.open("http://" + window.location.hostname + "/asp/html/KioskResetButton.html", 'copopup','top=80,left=80,width=325,height=175,screenX=80,screenY=80,notoolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
}

//function popUpCCSafetyInfo() {
//	openPicWin('/CheckOut/PopUpCCSafety.aspx' + gotoAnchor,400,200,'scrollbars=yes,resizable=no');
//	//popUp_Win('/CheckOut/PopUpCCSafety.aspx', 'Credit+Card+Safety', 400, 200);
//}

function popUpShippingChgs(countryName) {
	var gotoAnchor = (countryName != "") ? "#" + countryName : "";
	openPicWin('/CheckOut/PopUpShippingChg.aspx' + gotoAnchor,500,260,'scrollbars=yes,resizable=no');
	//popUp_Win('/CheckOut/PopUpShippingChg.aspx&h=PopUpShippingChgHdr.htm', 'Shipping+Charges', 480, 320);
	//&bk=' + whichOne
}

//function popUpOfferCodeInfo() {
//	popUp_Win('/CheckOut/PopUpOfferCode.aspx', 'Offer+Code', 400, 200);
//}

function popUpGiftMsgInfo() {
	openPicWin('/CheckOut/PopUpGiftMessage.aspx',500,260,'scrollbars=yes,resizable=no');
	//popUp_Win('/CheckOut/PopUpGiftMessage.aspx', 'Gift+Message', 400, 260);
}

//function popUp_Win(url,title,width,height) {
//	coPopUpWin = window.open('/CheckOut/PopUpWin.aspx?t=' + title + '&b=' + url, 'copopup','top=80,left=80,width=' + width + ',height=' + height + ',screenX=80,screenY=80,notoolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1');
//	coPopUpWin.focus();
//}


function valEmailAddr(o, args) {
	args.IsValid = (args.Value.length == 0 || args.Value.length > 4);
}

function setMyCCards(oSel,oName,oNumb,oMnth,oYear,oIsSv) {
	var idx = parseInt(oSel.options[oSel.selectedIndex].value);
	if (! isNaN(idx) ) {
		cc = MyCCards[idx].split("|");
		oName.value = cc[1];
		oNumb.value = cc[0];
		oNumb.disabled = true;
		//oMnth.value = cc[3];
		//oYear.value = cc[4];
		setSel(oMnth, cc[3]);
		setSel(oYear, cc[4]);
		oIsSv.checked = true;
	}
	else {
		oIsSv.checked = false;
		oNumb.disabled = false;
		if (oNumb.value.substr(0,1) == 'M') oNumb.value = '';
	}	
}

function setSel(oSel, val) {
	for (var i = 0; i < oSel.options.length; i++) {
		if (oSel.options[i].value == val) {
			oSel.selectedIndex = i;
			return;
		}
	}
}

function autoTab(input, len, e) {
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length) {
			if(arr[index] == ele)
				found = true;
			else
				index++;
		}
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1) {
			if (input.form[i] == input)
				index = i;
			else
				i++;
		}
		return index;
	}
	return true;
}
