
// **********************  Form Validation For the order information stuff. ***************************

// regular expressions. I put them in an array to make re-usable
arrRegExps = new Array("[a-zA-Z0-9]+", "[\(\)0-9\-_]+", "^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z0-9_-]{2,3}$");

// human readable form of the verified elements name
arrNames = new Array('First Name', 'Last Name', 'Address Line 1', 'City', 'Postal Code', 'Region', 'Country', 'Phone', 'User Name', 'User Password');

// form names of the verified elements
arrFields = new Array('FirstName', 'LastName', 'Address_Line1', 'City', 'PostalCode', 'Region', 'Country', 'Phone', 'UserName', 'Password');

// index of the arrRegExps array indicating what regular expression should be used with what form field
arrCheck = new Array(0, 0, 0, 0, 0, 0, 0, 1, 0, 0);



function checkForm() {
	for (i = 0; i < arrFields.length; i++) {  // Running throught the array elements

    objField = eval( 'document.forms[2].' + arrFields[i]);
    strType = objField.type;
    
		// get the element's value
        switch (strType) {
			case "select-one":
				strEntry = objField.options[objField.selectedIndex].value;
				break;
			default:
				strEntry = objField.value;
				break;
		}

 
        objRegExp = new RegExp(arrRegExps[arrCheck[i]]); // Create regular expression
        strMatchUp = new String(strEntry); // Create a string object so we can search using the RegExp objec (regular expression object).
        intResult = strMatchUp.match(objRegExp);
    
        if (intResult == null) { // Does it match the expression?  If not do this.
            strAlert =  'Your ' + arrNames[i] + ' field is not formatted correctly.\nPlease correct.';
            alert(strAlert);  
            objField.focus();  // Set the cursor focus for convenience.
            return false;  // No go!
     
		} 

	}

	return true; // Go!

}


// ********************** End Form Validation ***************************







// Setting the select values when you first hit the page.
function setSelects() {

    arrSelObj = new Array();
    arrSelObjValue = new Array();
    
    
    arrSelObj[0] = document.forms[2].Billing_Region;
    arrSelObj[1] = document.forms[2].Billing_Country;
    arrSelObj[2] = document.forms[2].Shipping_Region;
    arrSelObj[3] = document.forms[2].Shipping_Country;


    arrSelObjValue[0] = strBilling_Region;
    arrSelObjValue[1] = strBilling_Country;
    arrSelObjValue[2] = strShipping_Region;
    arrSelObjValue[3] = strShipping_Country;
    

    for (i = 0; i <= arrSelObj.length-1; i++) {

        intFound = 0;

        for (i2 = 0; i2 <= arrSelObj[i].options.length-1; i2++) {

            if (arrSelObj[i].options[i2].value.toUpperCase() == arrSelObjValue[i].toUpperCase() ) {
                arrSelObj[i].options[i2].selected = true;
                intFound = 1;
                break;
            }

        }
			
    }

}



function billing_to_shipping() {

    var frm = document.forms[2];
    
    for( i = 6; i <= 20; i++ ) {
    
        if(frm.elements[i].type == 'select-one')
        
            frm.elements[i + 15].selectedIndex = frm.elements[i].selectedIndex;
        
        else if(frm.elements[i].type == 'text')
        
            frm.elements[i + 15].value = frm.elements[i].value;
    
    }


}



// -->

