

function validateForm()
	{
	//alert("validateForm");
	formObj = arguments[0];
	//alert(formObj);
	var valType="";
	var noErrors = true;
	//var cardDate;
	
	var errorString = "Please check your entries for...\n \n";
	//alert(arguments.length);
	for(argCount = 0; argCount < (arguments.length-1);argCount=argCount+3)
		{
		valType = arguments[argCount + 2];
		//alert(argCount + " -- valType " + valType);
		//alert(arguments[argCount+1]);
		if((valType=="cardDate")||(valType=="reqOption"))
			{
			fieldRef = "formObj." + arguments[argCount+1];
			}
		else
			{
		fieldRef = eval("formObj." + arguments[argCount+1]);
			}
		//alert(valType);
		switch(valType)
			{
			case "required":
				//alert(arguments[argCount+1] + " = " + fieldRef.value);
				if(fieldRef.value == null)
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					//alert("appended errorstring - required");
					noErrors = false;
					break;
					}
				if((fieldRef.value.length < 1)||(fieldRef.value == ""))
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					//alert("appended errorstring - required");
					noErrors = false;
					} 
				break;

				
				case "reqOption":
					//alert(arguments[argCount+1] + " = " + fieldRef);
					var optionIndex = eval(fieldRef + ".selectedIndex");
					var optionValue = eval(fieldRef + ".options[" + optionIndex + "].value");
					//alert(optionValue);
					
					if(optionValue == null)
						{
						errorString = errorString + arguments[argCount+3] + "\n";
						//alert("appended errorstring - required");
						noErrors = false;
						break;
						}
					if((optionValue.length < 1)||(optionValue == ""))
						{
						errorString = errorString + arguments[argCount+3] + "\n";
						//alert("appended errorstring - required");
						noErrors = false;
						} 
					break;
				
			case "radio":
				//alert(arguments[argCount+1] + " = " + fieldRef.checked);
					var noRadioError;
					//alert (fieldRef);
					noRadioError = false;
					
					for (index=0; index<fieldRef.length; index++)
						{ 
						if (fieldRef[index].checked)
							{
							noRadioError = true;
							}
						}
						
					if(!noRadioError)
						{
						errorString = errorString + arguments[argCount+3] + "\n";
						noErrors = false;
						}

			
				break;
				
			case "email":
				//alert(arguments[argCount+1] + " = " + fieldRef.value);
				if (fieldRef.value.indexOf(".") == -1)
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					noErrors=false;
					//alert("appended errorstring - email 1");
					break;
					}
					
				if (fieldRef.value.indexOf("@") == -1)
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					noErrors=false;
					//alert("appended errorstring - email 2");
					break;
					}
				break;
				
			
			case "zip":
				//alert(arguments[argCount+1] + " = " + fieldRef.value);
				if((fieldRef.value.length < 5)||(fieldRef.value.length > 10))
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					//alert("appended errorstring - phone");
					noErrors = false;
					}
				break; 
				
				
			case "phone":
				//alert(arguments[argCount+1] + " = " + fieldRef.value);
				if(fieldRef.value.length < 10)
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					//alert("appended errorstring - phone");
					noErrors = false;
					}
				break; 
				
			case "color":
				if(fieldRef.value.length != 6)
					{
					errorString = errorString + arguments[argCount+3] + "\n";
					//alert("appended errorstring - phone");
					noErrors = false;
					}
				break; 
				
			case "creditCard":
					//alert(arguments[argCount+1] + " = " + fieldRef.value);
					if (!ValidCard(fieldRef.value))
						{
						errorString = errorString + arguments[argCount+3] + "\n";
						noErrors = false;
						}
				break; 
				
			case "cardDate":
					
					//var domStr = fieldRef + "Year.selectedIndex";
					//alert(domStr);
					var YearIndex = eval(fieldRef + "Year.selectedIndex");
					var cardYear = eval(fieldRef + "Year.options[" + YearIndex + "].value");
					var monthIndex = eval(fieldRef + "Month.selectedIndex");
					var cardMonth = eval(fieldRef + "Month.options[" + monthIndex + "].value");
					//alert(cardMonth + "/" + cardYear);
					
					if((cardYear=="")||(cardYear==null)||(cardMonth=="")||(cardMonth==null))
						{
						errorString = errorString + arguments[argCount+3] + "\n";
						noErrors = false;
						//break;
						}
					
					
					var cardDate = new Date(cardYear,cardMonth,1);
					var currDate = new Date()
					//alert(cardDate + " - " + currDate)
					
					if(cardDate.valueOf() < currDate.valueOf())
						{
						errorString = errorString + arguments[argCount+3] + "\n";
						noErrors = false
						}
					
					//if (fieldRef.value))
						//{
						//noErrors = false;
						//}
				break; 
			
			case "password":
				checkStr = fieldRef.value;
				if(checkStr.length < 4)
					{
					errorString = errorString + "Length " + arguments[argCount+3] + "\n";
					//alert("appended errorstring - phone");
					noErrors = false;
					//alert(errorString);
					}
				for(var p = 0;p < checkStr.length; p++)
					{
					checkChar = checkStr.substring(p,p+1);
					checkChar = checkChar.toUpperCase();
					if((checkChar < "A" || checkChar > "Z") && (checkChar < "0" || checkChar > "9"))
						{
						errorString = errorString + "Invalid Character " + checkChar + " " + arguments[argCount+3] + "\n";
						noErrors = false;

						}
					}
				break; 
			}	
		//alert(noErrors);
		
		}
		//alert(errorString);
		//alert("noErrors = " + noErrors);
		if(noErrors==false)
			{
			alert(errorString);
			return false;
			}
	
	return noErrors; 
	}
		

function ValidCard(CreditCard)
	{
// Valid Input Syntax:
// Type1: **************** (16 columns)
// Type2: **** **** **** **** (19)
// Type3: ****-****-****-**** (19)
// Input is a credit card number in the form of a string.
// Validates numbers which use a "double-add-double MOD 10"
// check digit Output is False if not valid, True if valid.

//alert(CreditCard);

var Validity = false;       // Assume invalid card
var LN = CreditCard.length;	 // Get input value length

	if ((16 <= LN) && (LN <= 19))
		{
    LN --;
    CheckSum = 0;	// start with 0 checksum
    Dbl = false;	// Start with a non-doubling

    //------------------------------------------------------------
    //	Beginning backward loop through string
    //-------------------------------------------------------------

    for (Idx = LN; Idx >= 0; Idx --)
			{
			Digit = CreditCard.substr(Idx, 1);	  // Isolate character
			if (("0" <= Digit && Digit <= "9") || Digit == " " || Digit == "-")
				{
	    	if (Digit != " " && Digit != "-")
					{ // Skip connector
					Digit -= "0";	  // Remove ASCII bias
					if (Dbl)
						{		  // If in the "double-add" phase
		   			Digit += Digit; // Then double first
			   		if (Digit > 9)
							{ // Cast nines
						Digit -= 9;
					    }
						}
					Dbl = !Dbl; // Flip doubling flag
					CheckSum += Digit;  // Add to running sum
					if (CheckSum > 9)
						{  // Cast tens
	   				 CheckSum -= 10; // Same as MOD 10, but faster
						}
	   			}
				}
			else 
				{
				//alert(Validity);
	    	return(Validity);	// Invalid
				}
    	}
    	Validity = (CheckSum == 0) ? true : false; // Must sum to 0
  	}
	//alert(Validity);
	return(Validity);
}

	
function verifyPassword()
	{
	//alert("verifyPassword");
	formObj = arguments[0];
	//alert(formObj);
	var noErrors = true;
	var errorString = "Your Password does not match";
	var pw1 = eval("formObj." + arguments[1]);
	var pw2 = eval("formObj." + arguments[2]);
	//alert(pw1.value);
	//alert(pw2.value);

	if(pw1.value != pw2.value)
		{
		alert(errorString);
		pw1.value = "";
		pw2.value = "";
		noErrors = false;
		}

	return noErrors; 
	}
	
	
	
function confirmDelete(RecordID,RecordTitle,deleteMode,tempPK)
	{
	var newLoc;
	deleteCheck = confirm('Are you sure you want to delete ' + RecordTitle + '?');
	//alert(deleteCheck);
	if (deleteCheck==true)
		{
		newLoc = "ProcessDelete.asp?deleteMode=" + deleteMode + "&" + "RecordID="+ RecordID + "&tempPk=" + tempPK;
		//alert(newLoc);
		window.location=newLoc;

		}
		return;
	}
	
	
function updateMedia(selectName)
	{
	//window.document.mediaForm.
	}	