
function open_download(name, winName, winDressing, winWidth, winHeight) 
{
	if (winWidth == null) winWidth = 500;
	if (winHeight == null) winHeight = 350;
	var newWindow = window.open(name, winName, 'width=' + winWidth + ',height=' + winHeight + ',' + winDressing);
}

function placeObject(id,type,width,height,data)
{
	// Version check based upon the values entered above in "Globals"
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	if (hasReqestedVersion)
	{
		document.write("\n"+'<object id="'+id+'" type="'+type+'" width="'+width+'" height="'+height+'" data="'+data+'">'+"\n");
		if (arguments.length > 5) {
			for(i = 5; i < arguments.length; i++) {
				paramValues = arguments[i].split(",");
				document.write('	<param name="'+paramValues[0]+'" value="'+paramValues[1]+'" />'+"\n");
			}
		}
		document.write('</object>'+"\n");
	}
	else
	{
		var alternateContent = '<BR><BR><BR><BR><BR><BR><BR>This content requires the Adobe Flash Player.  '
		+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
		document.write(alternateContent);  // insert non-flash content
	}
}

// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}


// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		
		return false;
	} else {
		return false;
	}
}

// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------


// ' ~~~~ Seach Form Validation ~~~~
function searchFormValidator(theForm)
{

  if (theForm.SearchQuery.value == "")
  {
    alert("Please enter a value for the \"Search Keywords\" field.");
    theForm.SearchQuery.focus();
    return (false);
  }

  if (theForm.SearchQuery.value.length > 100)
  {
    alert("Please enter at most 100 characters in the \"Search Keywords\" field.");
    theForm.SearchQuery.focus();
    return (false);
  }
  return (true);
}

// ' View Product Checks
function viewProductCheck() {
	var i;
	var prodV = document.getElementById('productView'); //productView.elements;
	var formElements = prodV.elements;
	var eName;
	var bSingleValidElementFound = false;
	var proceed = true;
	for(i=0; i<formElements.length; i++){
		eName = formElements[i].id;
		
		eValue = formElements[i].value;
		if(eName.indexOf("Quantity_") > -1)
		{
			//alert('name: ' + eName + ' - ' + formElements[i].id);			
			if(eValue!='0' && !Number(eValue))
			{
				proceed=false;
				formElements[i].value = '0';
				//window.alert("Please make sure all item quantities are numbers and greater than or equal to 0.");
			}
			if (eValue>'0' && Number(eValue))
			{
				bSingleValidElementFound=true;
			}
		}
		else
		{
			//alert("number of items is less than 1 or equal to zero");
		}
	}
	if (bSingleValidElementFound==true) //&& proceed=true
	{
		/* if (document.getElementById("chkCustomEmbroidery").checked == true) 
		{
			if (checkEmbroideryForm()==true) {proceed=true;}
			else {proceed= false;}
		}
		else
		{
			proceed = true;			
		} */
	}
	else
	{
		if (bSingleValidElementFound==false) {
			window.alert("Please make sure at least one Size has a quantity of 1 or more and that all item quantities are greater than or equal to 0.");
			proceed = false;
		}
	}
	return proceed;
	
}




// ' ~~~~ Shopping Cart specific scripts ~~~~ 
	
function ConfirmCartQuantities()
{
    var i;
    var formElements = document.frmCartItems.elements;
    var eName;
    var proceed = true;
    
    for(i=0; i<formElements.length; i++)
    {
	    eName = formElements[i].name;
	    eValue = formElements[i].value;
	    
	    if(eName.indexOf("Quantity_") > -1)
	    {
		    if(eValue!='0' && !Number(eValue))
		    {
			    proceed=false;
			    window.alert("Please make sure all item quantities are numbers and greater than or equal to 0.");
		    }
	    }
    }
    return proceed;
}

function ModifyCartItems() {
	if(ConfirmCartQuantities()){
		document.frmCartItems.submit();
	}
}
function Checkout() {
	document.frmCartItems.elements['action'].value="PrepareOrder"
	if(ConfirmCartQuantities()){
		document.frmCartItems.submit();
	}
}
function ContinueShopping() {
	if(ConfirmCartQuantities()){
		document.frmCartItems.elements['action'].value="Browse";
		document.frmCartItems.submit();
	}
}
function RemoveCartItem(intOrderDetailID){
	if(ConfirmCartQuantities()){
		document.frmCartItems.elements["Quantity_" + intOrderDetailID].value = "0"
		document.frmCartItems.submit();
	}
}


function ApprovedShipping() {
	var varFrmSingleShipping =document.getElementById('SingleShippingForm');
			varFrmSingleShipping.submit();

}
// ' ~~~~ Shipping Address scripts ~~~~

function ShowShippingCheck() {
	var varFrmSingleShipping =document.getElementById('SingleShippingForm');
	if (varFrmSingleShipping.AddressID.length != null) {
		if (varFrmSingleShipping.AddressID[0].checked) {
			
			if(varFrmSingleShipping.txtFirstname.value ==''){
				window.alert("Please provide your first name.")
				varFrmSingleShipping.txtFirstname.focus();
				return;
			}
			if(varFrmSingleShipping.txtLastname.value ==''){
				window.alert("Please provide your last name.")
				varFrmSingleShipping.txtLastname.focus();
				return;
			}
			if(varFrmSingleShipping.txtAddress1.value ==''){
				window.alert("Please provide your address.")
				varFrmSingleShipping.txtAddress1.focus();
				return;
			}
			if(varFrmSingleShipping.txtCity.value ==''){
				window.alert("Please provide your city.")
				varFrmSingleShipping.txtCity.focus();
				return;
			}
			if((varFrmSingleShipping.txtZipcode.value =='')||(varFrmSingleShipping.txtZipcode.value.length != 5)){
				window.alert("Please provide your 5-digit zipcode.")
				varFrmSingleShipping.txtZipcode.focus();
				return;
			}
			if(varFrmSingleShipping.txtPhone.value ==''){
				window.alert("Please provide your phone number.")
				varFrmSingleShipping.txtPhone.focus();
				return;
			}
			varFrmSingleShipping.submit();
		} else {
			varFrmSingleShipping.submit();
		}
		
	} else {
			if (varFrmSingleShipping.AddressID.checked) {
			
			if(varFrmSingleShipping.txtFirstname.value ==''){
				window.alert("Please provide your first name.")
				return;
			}
			if(varFrmSingleShipping.txtLastname.value ==''){
				window.alert("Please provide your last name.")
				return;
			}
			if(varFrmSingleShipping.txtAddress1.value ==''){
				window.alert("Please provide your address.")
				return;
			}
			if(varFrmSingleShipping.txtCity.value ==''){
				window.alert("Please provide your city.")
				return;
			}
			if(varFrmSingleShipping.txtZipcode.value ==''){
				window.alert("Please provide your zipcode.")
				return;
			}
			if(varFrmSingleShipping.txtPhone.value ==''){
				window.alert("Please provide your phone number.")
				return;
			}
			varFrmSingleShipping.submit();
		} else {
			varFrmSingleShipping.submit();
		}
	}
}

function ShowEditShippingCheck() {
	var varFrmSingleShipping =document.getElementById('SingleEditShippingForm');
	if(varFrmSingleShipping.txtFirstname.value ==''){
		window.alert("Please provide your first name.")
		varFrmSingleShipping.txtFirstname.focus();
		return;
	}
	if(varFrmSingleShipping.txtLastname.value ==''){
		window.alert("Please provide your last name.")
		varFrmSingleShipping.txtLastname.focus();
		return;
	}
	if(varFrmSingleShipping.txtAddress1.value ==''){
		window.alert("Please provide your address.")
		varFrmSingleShipping.txtAddress1.focus();
		return;
	}
	if(varFrmSingleShipping.txtCity.value ==''){
		window.alert("Please provide your city.")
		varFrmSingleShipping.txtCity.focus();
		return;
	}
	if((varFrmSingleShipping.txtZipcode.value =='')||(varFrmSingleShipping.txtZipcode.value.length != 5)){
		window.alert("Please provide your 5-digit zipcode.")
		varFrmSingleShipping.txtZipcode.focus();
		return;
	}
	if(varFrmSingleShipping.txtPhone.value ==''){
		window.alert("Please provide your phone number.")
		varFrmSingleShipping.txtPhone.focus();
		return;
	}
	varFrmSingleShipping.submit();
}

// ' ~~~~ Multiple Shipping Cart specific scripts ~~~~ 

function AddAddress(){
	window.alert("AddAddress: Not Implemented Yet")
}
function RemoveLineItem(intLineItem){
	window.alert("RemoveLineItem: Not Implemented Yet")
}
function UpdateProductQuantities(intOrderDetailID){
	window.alert("UpdateProductQuantities: Not Implemented Yet");
}
function SubmitForm(){
	document.frmShipping.submit();
}
function GoToShippingMethods(){
	document.frmShipping.elements['goto'].value="ShowShippingMethods"
	document.frmShipping.submit();
}
function SplitShippingItem(intOrderDetailID){
	document.frmShipping.elements['UpdateShippingAction'].value="SplitShippingItem_" + intOrderDetailID;
	SubmitForm();
}

// ' ~~~~ "ShowPayment" specific scripts ~~~~ 

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isArray(a) {
	alert(a.constructor);
    return isObject(a) && a.constructor == '[NodeList]';
}

function validateNewAddress(AddressToValidate) {
	if(AddressToValidate.txtFirstname.value ==''){
		window.alert("Please provide your first name.")
		return(false);
	}
	if(AddressToValidate.txtLastname.value ==''){
		window.alert("Please provide your last name.")
		return(false);
	}
	if(AddressToValidate.txtAddress1.value ==''){
		window.alert("Please provide your address.")
		return(false);
	}
	if(AddressToValidate.txtCity.value ==''){
		window.alert("Please provide your city.")
		return(false);
	}
	if(AddressToValidate.txtZipcode.value ==''){
		window.alert("Please provide your zipcode.")
		return(false);
	}
	if(AddressToValidate.txtPhone.value ==''){
		window.alert("Please provide your phone number.")
		return(false);
	}
	return(true);
}

function validateNewCard(CardToValidate) {
	if(CardToValidate.CCType.value ==''){
		window.alert("Please choose a credit card Type.")
		CardToValidate.CCType.focus();
		return(false);
	}
	if(CardToValidate.CCNumber.value ==''){
		window.alert("Please enter a valid credit card number.")
		CardToValidate.CCNumber.focus();		
		return(false);
	}
	if(CardToValidate.CCMonth.value ==''){
		window.alert("Please select an expire month for your credit card.")
		CardToValidate.CCMonth.focus();
		return(false);
	}
	if(CardToValidate.CCYear.value ==''){
		window.alert("Please select an expire year for your credit card.")
		CardToValidate.CCYear.focus();
		return(false);
	}
	//note: specific for visa and mastercard, length of 3 should be good
	if((CardToValidate.CCCode.value =='')||(CardToValidate.CCCode.value.length !=3)||(!Number(CardToValidate.CCCode.value))){
		window.alert("Please enter a valid 3-digit Credit Card CVV2 code.")
		CardToValidate.CCCode.focus();
		return(false);
	}	
	
	return(true);
}

function validateRequired(field, alertText)
{
    with(field)
    {
        if(value==null || value=="")
        {
            alert(alertText);
            return false;
        }
        else
        {
            return true;
        }
    }
}

function validateSelected(field, alertText)
{
	with(field)
	{
		if(field.options[field.selectedIndex].value == null || field.options[field.selectedIndex].value == "")
		{
			alert(alertText);
			return false;
		}
		else
		{
			return true;
		}
	}
}

function validateCatalogRequestForm(thisForm)
{
    with(thisForm)
    {
        if(validateRequired(physicalAddress, "Physical Address must be filled in.") == false)
        {
            physicalAddress.focus();
            return false;
        }
        
        if(validateRequired(paCity, "Physical Address City must be filled in.") == false)
        {
            paCity.focus();
            return false;
        }

        if(validateRequired(paState, "Physical Address State must be filled in.") == false)
        {
            paState.focus();
            return false;
        }

        if(validateRequired(paZipCode, "Physical Address Zip Code must be filled in.") == false)
        {
            paZipCode.focus();
            return false;
        }

        if(validateRequired(mailingAddress, "Mailing Address must be filled in.") == false)
        {
            mailingAddress.focus();
            return false;
        }
        
        if(validateRequired(city, "City must be filled in.") == false)
        {
            city.focus();
            return false;
        }
        
        if(validateRequired(states, "State must be filled in.") == false)
        {
            states.focus();
            return false;
        }
        
        if(validateRequired(zipCode, "Zip code must be filled in.") == false)
        {
            zipCode.focus();
            return false;
        }
        
        if(validateRequired(preferredNumber, "Preferred Phone # must be filled in.") == false)
        {
            preferredNumber.focus();
            return false;
        }
        
        if(validateRequired(timeZone, "Time Zone must be selected.") == false)
        {
            timeZone.focus();
            return false;
        }
        
        if(validateRequired(emailAddress, "Email Address must be filled in.") == false)
        {
            emailAddress.focus();
            return false;
        }
        
        if(validateRequired(extraPlan, "'How do you plan to use our products?' must be filled in.") == false)
        {
        	extraPlan.focus();
        	return false;
        }
    }
    
    return true;
}

function validateEmploymentForm(thisForm)
{
    with(thisForm)
    {
        if(validateSelected(title, "'Title' must be selected.") == false)
        {
            title.focus();
            return false;
        }
        
        if(validateRequired(firstName, "'First Name' must be filled in.") == false)
        {
            firstName.focus();
            return false;
        }

        if(validateRequired(lastName, "'Last Name' must be filled in.") == false)
        {
            lastName.focus();
            return false;
        }

        if(validateRequired(mailingAddress, "'Mailing Address must be filled in.") == false)
        {
            mailingAddress.focus();
            return false;
        }
        
        if(validateRequired(city, "'City' must be filled in.") == false)
        {
            city.focus();
            return false;
        }
        
        if(validateRequired(applicantInfoState, "'State' must be filled in.") == false)
        {
            applicantInfoState.focus();
            return false;
        }
        
        if(validateRequired(applicantInfoZipCode, "'Zip code' must be filled in.") == false)
        {
            applicantInfoZipCode.focus();
            return false;
        }
        
        if(validateRequired(phoneNumber, "'Home Phone #' must be filled in.") == false)
        {
            phoneNumber.focus();
            return false;
        }
        
        if(validateSelected(desiredPosition, "'Position Desired' must be selected.") == false)
        {
            desiredPosition.focus();
            return false;
        }
        
        if(desiredPosition.options[desiredPosition.selectedIndex].value == "Other")
        {
        	if(validateRequired(positionDesiredOther, "You must specify Other position") == false)
        	{
        		positionDesiredOther.focus();
        		return false;
        	}
        }
        
        if(validateRequired(expectedWage, "'Expected Wage' must be filled in.") == false)
        {
        	expectedWage.focus();
        	return false;
        }
        
        if(validateSelected(preferredShift, "'Preferred Shift' must be selected.") == false)
        {
            preferredShift.focus();
            return false;
        }
        
        if(validateSelected(yearRoundOrSeasonal, "'Year-round or Seasonal' must be selected.") == false)
        {
        	yearRoundOrSeasonal.focus();
        	return false;
        }
        
        if(validateSelected(fullOrPartTime, "'Full or Part time' must be selected.") == false)
        {
        	fullOrPartTime.focus();
        	return false;
        }
        
        if(validateRequired(startDate1, "'Availability for Employment' must be filled in.") == false)
        {
        	startDate1.focus();
        	return false;
        }

        if(validateRequired(startDate2, "'Availability for Employment' must be filled in.") == false)
        {
        	startDate2.focus();
        	return false;
        }

        if(validateRequired(startDate3, "'Availability for Employment' must be filled in.") == false)
        {
        	startDate3.focus();
        	return false;
        }
        
        if(validateSelected(walzBefore, "'Have you ever worked for WalzCraft or its divisions before?' must be selected.") == false)
        {
        	walzBefore.focus();
        	return false;
        }

        if(validateRequired(educationBackgroundHighSchoolName, "'High School' must be filled in.") == false)
        {
        	educationBackgroundHighSchoolName.focus();
        	return false;
        }

        if(validateSelected(educationBackgroundHighSchoolDidGraduate, "'Did you graduate?' must be selected.") == false)
        {
        	educationBackgroundHighSchoolDidGraduate.focus();
        	return false;
        }

        if(validateRequired(educationBackgroundHighSchoolDegreeType, "'Degree Type' must be filled in.") == false)
        {
        	educationBackgroundHighSchoolDegreeType.focus();
        	return false;
        }
        
        if(validateSelected(eligibility, "'Legal Information' questions must be answered.") == false)
        {
        	eligibility.focus();
        	return false;
        }

        if(validateSelected(convictedOfCrime, "'Legal Information' questions must be answered.") == false)
        {
        	convictedOfCrime.focus();
        	return false;
        }
        
        if(validateRequired(whyWalzCraft, "'Why do you want to work for WalzCraft Industries?' must be filled in.") == false)
        {
        	whyWalzCraft.focus();
        	return false;
        }
        
        if(validateSelected(haveRelativesAtWalzCraft, "'Do you have any relative(s) that presently work for WalzCraft Industries?' must be selected.") == false)
        {
        	haveRelativesAtWalzCraft.focus();
        	return false;
        }

        if(validateSelected(knowEmployee, "'Do you know anyone other than relative(s) that presently work for WalzCraft Industries?' must be selected.") == false)
        {
        	knowEmployee.focus();
        	return false;
        }
        
        if(validateRequired(supervisorCommments, "'What would your previous supervisor tell us about you?' must be filled in.") == false)
        {
        	supervisorCommments.focus();
        	return false;
        }

        if(validateRequired(employeeTreatment, "'Describe your last employer's treatment of their employess.' must be filled in.") == false)
        {
        	employeeTreatment.focus();
        	return false;
        }
        
        if(validateRequired(positiveNegative, "'What are some of the positives and negatives of your last job?' must be filled in.") == false)
        {
        	positiveNegative.focus();
        	return false;
        }
        
        if(validateRequired(whyLastCompany, "'Why did you go to work for that company?' must be filled in.") == false)
        {
        	whyLastCompany.focus();
        	return false;
        }

        if(validateRequired(timeAway, "'How many days - other than weekends, holidays or vacation time - do you feel is too much time to be away from work in a one year time period?' must be filled in.") == false)
        {
        	timeAway.focus();
        	return false;
        }

        if(validateSelected(transportation, "'Means of transportation to and from work:' must be selected.") == false)
        {
        	transportation.focus();
        	return false;
        }

        if(validateSelected(previouslyApplied, "'Have you applied with WalzCraft previously?") == false)
        {
        	previouslyApplied.focus();
        	return false;
        }

        if(validateSelected(workOvertime, "'Are you willing to work overtime?") == false)
        {
        	workOvertime.focus();
        	return false;
        }

        if(validateRequired(acknowlegeInitial, "'Applicant Initial Here' must be filled in.") == false)
        {
        	acknowlegeInitial.focus();
        	return false;
        }
    }
    
    return true;
}

function PaymentFormCheck() {											//  Function to validate the Payment Address fieldset on fb_ShowShipping
	varPaymentForm = document.getElementById('PaymentForm');
	
	var FormValid = true;
	var AddressSelected = false;
	var PaymentSelected = false;
	
	if (varPaymentForm.BillToAddress.length != null) {						//  Check to see if there is more than one address to select...;
		for (i = 0; i < varPaymentForm.BillToAddress.length; i++) {		//  ...If there is more than one address, then make sure one of them is selected
			if (varPaymentForm.BillToAddress[i].checked) {
				AddressSelected = true;
				if (varPaymentForm.BillToAddress[i].value == 0) {
					FormValid = validateNewAddress(varPaymentForm);
				}
			}
		}
				
	} else if (varPaymentForm.BillToAddress.checked) {					// Checks to see that the ONLY payment address option (Enter New Address) is selected
		AddressSelected = true;
		FormValid = validateNewAddress(varPaymentForm);					// Validates new Address information	
	}
	if (!AddressSelected) {
		alert("Please Select a Payment Address");
		FormValid = false;
	}
	
	if (FormValid)
	{
		if  (varPaymentForm.PaymentType.length != null) {
			for (j = 0; j < varPaymentForm.PaymentType.length; j++) {
				if (varPaymentForm.PaymentType[j].checked) {
					PaymentSelected = true;
					if (varPaymentForm.PaymentType[j].value == 'CreditCard') {
						FormValid = validateNewCard(varPaymentForm);
					} else if (varPaymentForm.PaymentType[j].value == 'PO') {
						if (varPaymentForm.PONumber.value == '') {
							alert('Please enter a Pre-Approved Account Number');
							FormValid = false;
						}
					}
				}
			}
		} else if (varPaymentForm.PaymentType.checked) {
			PaymentSelected = true;
			FormValid = validateNewCard(varPaymentForm);					// Validates new Address information	
		}

		if (!PaymentSelected) {
			alert("Please Select a Payment Method");
			FormValid = false;
		}
	}
	

		
	if (FormValid) {
		varPaymentForm.submit();
	}
}

function Approved() {
	varPaymentForm = document.getElementById('PaymentForm');
	
	var FormValid = true;
	var AddressSelected = false;
	var PaymentSelected = false;
	
	if (varPaymentForm.BillToAddress.length != null) {						//  Check to see if there is more than one address to select...;
		for (i = 0; i < varPaymentForm.BillToAddress.length; i++) {		//  ...If there is more than one address, then make sure one of them is selected
			if (varPaymentForm.BillToAddress[i].checked) {
				AddressSelected = true;
				/* if (varPaymentForm.BillToAddress[i].value == 0) {
					FormValid = validateNewAddress(varPaymentForm);
				} */
			}
		}
				
	} else if (varPaymentForm.BillToAddress.checked) {					// Checks to see that the ONLY payment address option (Enter New Address) is selected
		AddressSelected = true;
		//FormValid = validateNewAddress(varPaymentForm);					// Validates new Address information	
	}
	
	
	if (!AddressSelected) {
		alert("Please Select a Payment Address");
		FormValid = false;
	}

	if (FormValid) {
		varPaymentForm.submit();
	}
}

function Manager() {
	varPaymentForm = document.getElementById('PaymentForm');
	
	var FormValid = true;
	var AddressSelected = false;
	var PaymentSelected = false;
	
	if (varPaymentForm.BillToAddress.length != null) {						//  Check to see if there is more than one address to select...;
		for (i = 0; i < varPaymentForm.BillToAddress.length; i++) {		//  ...If there is more than one address, then make sure one of them is selected
			if (varPaymentForm.BillToAddress[i].checked) {
				AddressSelected = true;
				/* if (varPaymentForm.BillToAddress[i].value == 0) {
					FormValid = validateNewAddress(varPaymentForm);
				} */
			}
		}
				
	} else if (varPaymentForm.BillToAddress.checked) {					// Checks to see that the ONLY payment address option (Enter New Address) is selected
		AddressSelected = true;
		//FormValid = validateNewAddress(varPaymentForm);					// Validates new Address information	
	}
	if (varPaymentForm.CompanyCode.value == '') {
		alert('Please enter a Company Code.');
		FormValid = false;
	}
	if (varPaymentForm.DeptCode.value == '') {
		alert('Please enter a Department Code');
		FormValid = false;
	}
	if (varPaymentForm.ExpenseCatCode.value == '') {
		alert('Please enter an Expense Category Code');
		FormValid = false;
	}
	
	if (!AddressSelected) {
		alert("Please Select a Payment Address");
		FormValid = false;
	}

	if (FormValid) {
		varPaymentForm.submit();
	}
}

function ClearCC(){
	document.varPaymentForm.ClearCreditCard.value='1';
	PaymentFormCheck();
}


//	' ~~~~ Open and close window (like the audio player window) ~~~~ 
//	' ~~~~ var newWindow stores the object specifically used for the Audio Player ~~~~


var newWindow;
function open_Window(name, winName, winDressing, winWidth, winHeight) 
{
	if (winWidth == null) winWidth = 500;
	if (winHeight == null) winHeight = 350;
	newWindow = window.open(name, winName, 'width=' + winWidth + ',height=' + winHeight + ',' + winDressing);
	newWindow.focus();
}

function closeNewWindow() {
 
  if (newWindow  && newWindow.open && !newWindow.closed)
  {
	   newWindow.close();
  }

}

function open_Centered_Window(fileLocation, winName, winDressing, winWidth, winHeight)
{
	if (winWidth == null) winWidth = 500;
	if (winHeight == null) winHeight = 350;
	var winLeft = (screen.width - winWidth) / 2;
	var winTop = (screen.height - winHeight) / 2;
	var features = 'height='+winHeight+',width='+winWidth+',top='+winTop+',left='+winLeft+','+winDressing;
	
	win = window.open(fileLocation, winName, features);
	
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//	' ~~~~ Preload Images for Navigation Rollovers, etc.

function preLoadImages()
{
	var args = preLoadImages.arguments;
	document.imageArray = new Array(args.length);
	
	for(var i=0; i<args.length; i++)
	{
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

//	' ~~~~ Simple MouseOver/MouseOut for Navigation Rollovers, etc.

function ImageSwitch(src)
{
	pattern = ".gif";
	NewSrc = src.replace(pattern,"DN"+pattern);
	//alert("New: " + NewSrc);
	return NewSrc;
}

function ImageReplace(src)
{
	pattern = "DN.";
	NewSrc = src.replace(pattern,".");
	//alert("New: " + NewSrc);
	return NewSrc;
}

function collapseAllListsExcept(divId)
{
	var labels = document.getElementsByTagName('label');
	
	for(var i = 0; i < labels.length; i++)
	{
		if (labels[i].className == 'row' || labels[i].className == 'sel')
		{
			var fullId = labels[i].id;
			var number = fullId.replace('label', '');
			var ulid = 'ul' + number;
			
			if (ulid != divId)
			{
				var ul = document.getElementById(ulid);
				
				if (ul)
				{
					ul.style.display = 'none';
				}
			}
		}
	}
}

//	' ~~~~ Toggle Collapse/Expand of Div
function divDisplayToggle(divId1)
{
	collapseAllListsExcept(divId1);
	
	if (document.getElementById(divId1))
	{
		if (document.getElementById(divId1).style.display == 'none') 
		{
			document.getElementById(divId1).style.display='block';
		}
		else
		{
			document.getElementById(divId1).style.display='none';
		}
	}		
}

//	' ~~~~ Toggle Collapse/Expand of Div
function toggleElement1DisplayByElement2 (elementId1, presentElement)
{
	if (document.getElementById(elementId1))
	{
		if (document.getElementById(presentElement).checked==true)
		{
			document.getElementById(elementId1).style.display='block'; 
		}
		else
		{
			document.getElementById(elementId1).style.display='none'; 
		}
	}
}

//	' ~~~~ Confirm Delete And Proceed
function ConfirmDeleteAndProceed (confirmText, proceedUrl)
{
	if (window.confirm(confirmText))
	{
		location.href= proceedUrl;
	}
}

function sgsAddEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function sgsRemoveEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

function GetDoorApplications(resultElementId)
{
	document.getElementById(resultElementId).innerHTML = "<img id='imgLoader' src='/site/multimedia/images/ajax-loader.gif' alt='loading images...'>";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert("Browser does not support HTTP Request");
		return;
	} 
	xmlHttp2=GetXmlHttpObject();
	xmlHttp2.open("GET", "/site/doorBuilder/getDoorApps.asp", true);

	xmlHttp2.onreadystatechange = function preHTMLLoaded() {
		if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") {
			document.getElementById(resultElementId).innerHTML = xmlHttp2.responseText;
		}
	}

	xmlHttp2.send(null);
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}


$(document).ready(function(){
	$(document).pngFix();	// Fixes PNG transparancy in IE6 and below
});
