
function outputJavascriptValidation(requiredElementsName,requiredElementsText) {
	var errormessage = "";
	for(var x=0;x < requiredElementsName.length;++x) {
		var thisElement = document.getElementById(requiredElementsName[x]);
		if( (thisElement.type == "text") || (thisElement.type == "select-one") ) {
			if(WithoutContent(thisElement.value)) {
				errormessage += "\n\n" + requiredElementsText[x];
			}
		} else if(thisElement.type == "checkbox") {
			if(!thisElement.checked) {
				errormessage += "\n\n" + requiredElementsText[x];
			}
                } else if (thisElement.type == 'select-multiple') {
                    var totalSelected = 0;
                    for (i = 0; i < thisElement.options.length; i++) {
                        if (thisElement.options[i].selected && thisElement.options[i].value != '') {
                            totalSelected++;
                        }
                    }
                    if (totalSelected == 0) {
                        errormessage += "\n\n" + requiredElementsText[x];
                    }

                }
		
	}
	return errormessage;
}

function WithoutContent(ss) {
	if(ss.length > 0) { return false; }
	return true;
}

function checkCountry(origin) {
	var usaStateList = "<select name=\"state\" id=\"state\" size=\"1\" style=\"border: 1px solid #95a22c; margin-right:12px;\"><option value=\"\">Select State</option><option value=\"AL\">Alabama</option><option value=\"AK\">Alaska</option><option value=\"AZ\">Arizona</option><option value=\"AR\">Arkansas</option><option value=\"CA\">California</option><option value=\"CO\">Colorado</option><option value=\"CT\">Connecticut</option><option value=\"DE\">Delaware</option><option value=\"DC\">District of Columbia</option><option value=\"FL\">Florida</option><option value=\"GA\">Georgia</option><option value=\"HI\">Hawaii</option><option value=\"ID\">Idaho</option><option value=\"IL\">Illinois</option><option value=\"IN\">Indiana</option><option value=\"IA\">Iowa</option><option value=\"KS\">Kansas</option><option value=\"KY\">Kentucky</option><option value=\"LA\">Louisiana</option><option value=\"ME\">Maine</option><option value=\"MD\">Maryland</option><option value=\"MA\">Massachusetts</option><option value=\"MI\">Michigan</option><option value=\"MN\">Minnesota</option><option value=\"MS\">Mississippi</option><option value=\"MO\">Missouri</option><option value=\"MT\">Montana</option><option value=\"NE\">Nebraska</option><option value=\"NV\">Nevada</option><option value=\"NH\">New Hampshire</option><option value=\"NJ\">New Jersey</option><option value=\"NM\">New Mexico</option><option value=\"NY\">New York</option><option value=\"NC\">North Carolina</option><option value=\"ND\">North Dakota</option><option value=\"OH\">Ohio</option><option value=\"OK\">Oklahoma</option><option value=\"OR\">Oregon</option><option value=\"PA\">Pennsylvania</option><option value=\"RI\">Rhode Island</option><option value=\"SC\">South Carolina</option><option value=\"SD\">South Dakota</option><option value=\"TN\">Tennessee</option><option value=\"TX\">Texas</option><option value=\"UT\">Utah</option><option value=\"VT\">Vermont</option><option value=\"VA\">Virginia</option><option value=\"WA\">Washington</option><option value=\"WV\">West Virginia</option><option value=\"WI\">Wisconsin</option><option value=\"WY\">Wyoming</option></select>";
	var canadaProvinceList = "<select id=\"state\" name=\"state\" size=\"1\" style=\"border: 1px solid #95a22c; margin-right:12px;\"><option value=\"\" selected=\"selected\">Select Province</option><option value=\"Alberta\">Alberta</option><option value=\"British Columbia\">British Columbia</option><option value=\"Manitoba\">Manitoba</option><option value=\"New Brunswick\">New Brunswick</option><option value=\"Newfoundland\">Newfoundland</option><option value=\"Northwest Territories\">Northwest Territories</option><option value=\"Nova Scotia\">Nova Scotia</option><option value=\"Ontario\">Ontario</option><option value=\"Prince Edward Island\">Prince Edward Island</option><option value=\"Quebec\">Quebec</option><option value=\"Saskatchewan\">Saskatchewan</option><option value=\"Yukon\">Yukon</option></select>";

	if(origin == "United States") {
		document.getElementById("sp_field").innerHTML = usaStateList;
		document.getElementById("sp_text").innerHTML = "<span class=\"required_asterix\">*</span>State: ";
		document.getElementById("sp_text").style.padding = "5px 4px 5px 0px";
		//document.getElementById("zipDiv").style.float = "right";
	} else if(origin == "Canada"){
		document.getElementById("sp_field").innerHTML = canadaProvinceList;
		document.getElementById("sp_text").innerHTML = "<span class=\"required_asterix\">*</span>Province: ";
		document.getElementById("sp_text").style.padding = "5px 4px 5px 0px";
		//document.getElementById("zipDiv").style.float = "right";
	} else {
		document.getElementById("sp_field").innerHTML = "<input type=\"hidden\" id=\"state\" name=\"state\" value=\"other\">";
		document.getElementById("sp_text").innerHTML = "";
		document.getElementById("sp_text").style.padding = "0px 0px 0px 0px";
		//document.getElementById("zipDiv").style.float = "left";
	}

}


function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}


function eatCookie () {
	document.cookie='cookietest=pentaho; expires=Thu, 2 Aug 1973 20:47:11 UTC; path=/; domain=.pentaho.com';
}


function checkCookies() {
	document.cookie='cookietest=pentaho; expires=Thu, 2 Aug 2020 20:47:11 UTC; path=/; domain=.pentaho.com';
	var hungry = get_cookie("cookietest");
	if(hungry == '') {
		alert("Note: Some features of our site are disabled \r\nunless you enable cookies in your browser.");
	}
	return hungry;
}

function CheckRequiredFields() {
	var errormessage = "";

	var requiredFields = requiredElements();
	
	errormessage += outputJavascriptValidation(requiredFields.requiredElementsName,requiredFields.requiredElementsText);

// Put field checks above this point.
	if(errormessage.length > 2) {
		alert('The following required fields were not completed:' + errormessage);
		
		return false;
	}

	// FF 2.0.0.6 refresh bug fix attempt
	if(document.getElementById('state').value == "other") {
		if((document.getElementById('country').value == "United States") || (document.getElementById('country').value == "Canada")) {
			checkCountry(document.getElementById('country').value);
			CheckRequiredFields();
			return false;
		}
	}
	
	// add cookie if successful submit
	document.cookie='assetGate=4rtfgb9i8ujhyrfg; expires=Thu, 2 Aug 2020 20:47:11 UTC; path=/; domain=.pentaho.com';
	
	return true;
}

function handleType(currTypeVal) {
	// get special field names for sf values
	var sfFieldVal = specialFieldNames();
	
	if(currTypeVal == "other") {
		// show other input field for this addition
		document.getElementById("otherType_field").innerHTML = "<input type=\"text\" id=\"" + sfFieldVal + "\" name=\"" + sfFieldVal + "\" value=\"\" class=\"inputbox_search\" size=\"30\" style=\"border: 1px solid #95a22c; margin-top:8px;\">";
	} else {
		// hide otherRole objects
		document.getElementById("otherType_field").innerHTML = "<input type=\"hidden\" id=\"" + sfFieldVal + "\" name=\"" + sfFieldVal + "\" value=\"" + currTypeVal + "\">";
	}
}



























