var iwin = null;
function openWin(filename,H,V) {
	if (!iwin || iwin.closed) {
		var mystring = "status=no,resizable=yes,toolbar=yes,scrollbars=yes,location=no,menu=no,height=" + H + ",width=" + V;
		iwin = window.open(filename,'IWIN', mystring, false);
		iwin.location=filename;
		iwin.focus();
	} else {
		iwin.location=filename;
		iwin.focus();
	}
}

var iwin2 = null;
function openDoc(filename,H,V) {
	if (!iwin2 || iwin2.closed) {
		var mystring = "status=no,toolbar=no,scrollbars=yes,resizable=yes,location=no,menu=no,height=" + H + ",width=" + V;
		iwin2 = window.open(filename,'IWIN2', mystring, false);
		iwin2.location=filename;
		iwin2.focus();
	} else {
		iwin2.location=filename;
		iwin2.focus();
	}
}
var iwin3 = null;
function openHelp(filename,H,V) {
	if (!iwin || iwin.closed) {
		var mystring = "status=no,toolbar=no,scrollbars=yes,location=no,menu=no,height=" + H + ",width=" + V;
		iwin3 = window.open(filename,'IWIN3', mystring, false);
		iwin3.location=filename;
		iwin3.focus();
	} else {
		iwin3.location=filename;
		iwin3.focus();
	}
}

var popUp; 

function OpenCalendar(idname, postBack)
{
	popUp = window.open('/catalog/common/calendar/Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=170,height=225,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}		

function isEmpty(s){   
	return ((s.value == null) || (s.value.length == 0));
}

function isEmptyList(s){   
	return ((s == null) || (s == "") || (s == "0"));
}

function askDelete(sUrl, sEntity){
		var agree=confirm("Are you sure you want to DELETE the "+sEntity+"?");
		if (agree)
		{location.href = sUrl;}
	}

function show(s)
{   alert (s);
	return 0;
}

function getListValue(s) {
   var listValue = "";
   if (s.selectedIndex != -1) {
      listValue = s.options[s.selectedIndex].value;
   }
   return (listValue);
}

function getTextValue(s) {
   return (s.value);
}

function getTextLength(s) {
   return (s.value.length);
}

function warnEmpty (s, theField){
	var mPrefix = "Please enter a value into the ";
	var mSuffix = " field.";
	s.focus();
    alert(mPrefix + theField + mSuffix);
    return false;
}

function warning (s, sMessage){
	s.focus();
    alert(sMessage);
    return false;
}

function ValidEntry(sTextToValidate, sValidChars) 
{
	var ok = "yes";
	var temp;
		
	for (var i=0; i < sTextToValidate.length; i++)
	{
		temp = "" + sTextToValidate.substring(i, i+1);
		if (sValidChars.indexOf(temp) == "-1")
		{	ok = "no";	}
	}
		
	if (ok == "no") 
	{	return(false)	}
	else
	{	return(true)	}
}

//validate credit card numbers with LUHN formula
function ValidCCEntry(sCCNumber, sCCType){
var iIndex;
var iSum=0;
var iTemp="";

	switch(sCCType){
		case "Visa":
			if (sCCNumber.substr(0,1) != "4") { return false; }
			break;
		case "MasterCard":
			if (sCCNumber.substr(0,2) < 51 || sCCNumber.substr(0,2) > 55) { return false; }
			break;
		case "Amex":
			if (sCCNumber.substr(0,2) != "34" && sCCNumber.substr(0,2) != "37") { return false; }
			break;
		default:
			return false; break;
	}
	
	//don't allow testing numbers
	switch(sCCNumber){
		case "4111111111111111": { return false; break; }
		case "5500000000000004": { return false; break; }
		case "5555555555554444": { return false; break; }
		case "378282246310005": { return false; break; }
	}
	
	// pad the number with zeros so its length is 20 chars
	for(iIndex=20-sCCNumber.length; sCCNumber.length!=20; iIndex--)
	{	sCCNumber = "0" + sCCNumber;	}

	for(iIndex=0; iIndex<sCCNumber.length; iIndex++)
	{
		var iDigit = parseInt(sCCNumber.charAt(iIndex));
		if (!((iIndex+1) % 2 == 0))
		{
			iDigit *= 2;
			if (iDigit > 9)	{ iDigit -= 9; }
		}
		iSum += iDigit;
	}
	
	if (iSum % 10 == 0)
	{	return true;	}
	else
	{	return false;	}
}



function MoverBox(option, boxLeft, boxRight) {
	var selection;
	var selectionindex;
	var i;
	
	if (option == 1)
	{
		selectionindex = boxLeft.selectedIndex;
		if (selectionindex == -1)
			alert ("Please select an available item.");
		else
		{
			for(i = (boxLeft.options.length-1); i > -1; i--){
				if (boxLeft.options(i).selected == 1){
					selection = boxLeft.options(i);
					var oOption = document.createElement("OPTION");
					oOption.text=selection.text;
					oOption.value=selection.value;
					boxRight.add(oOption);
					boxLeft.remove(i); 
				}
			}
		}
	}
	else
	{
		selectionindex = boxRight.selectedIndex;
		if (selectionindex == -1)
			alert ("Please select an assigned item.");
		else
		{
			for(i = (boxRight.options.length-1); i > -1; i--){
				if (boxRight.options(i).selected == 1){
					selection = boxRight.options(i);
					var oOption = document.createElement("OPTION");
					oOption.text=selection.text;
					oOption.value=selection.value;
					boxLeft.add(oOption);
					boxRight.remove(i); 
				}
			}
		}
	}
}