// JavaScript Document

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//THIS IS A PREFIL SCRIPT FOR THE FORM - USES COOKIES--------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
var expDays = 100;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function cookieForms() {  
	var mode = cookieForms.arguments[0];
	for(f=1; f<cookieForms.arguments.length; f++) {
		formName = cookieForms.arguments[f];
		if(mode == 'open') {	
			cookieValue = GetCookie('saved_'+formName);
			if(cookieValue != null) {
				var cookieArray = cookieValue.split('#cf#');
				if(cookieArray.length == document[formName].elements.length) {
					for(i=0; i<document[formName].elements.length; i++) {
						if(cookieArray[i].substring(0,6) == 'select') {
							//Changed to make the script accept more than one digit indexes in select boxes
							//document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1);
							document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(9, cookieArray[i].indexOf('t')+1);
			
						}
						else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }
						else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }
						else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
					}
				}
			}
			
		}

		if(mode == 'save') {	
			cookieValue = '';
			for(i=0; i<document[formName].elements.length; i++) {
				fieldType = document[formName].elements[i].type;
				if(fieldType == 'password') { passValue = ''; }
				else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
				else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
				else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
				else { passValue = document[formName].elements[i].value; }
				cookieValue = cookieValue + passValue + '#cf#';
			}
			cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
			SetCookie('saved_'+formName, cookieValue, exp);		
		}	
	}
}



//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//THIS IS TO BLOCK HIDDEN FIELDS DEPEENDING ON THE PREFILLED VALUES --------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function openhiddenfields() {  
	
	if(document.getElementById('Session.user.jobFunction')){
		if (document.getElementById('Session.user.jobFunction').value=="Other"){
			document.getElementById('otherJobFunction').style.display = 'block';
		}else{
			document.getElementById('otherJobFunction').style.display = 'none';
		}
	}
	
	if (document.getElementById('countrySelect').value=="United States"){
		document.getElementById('US-State-Field').style.display = 'block';
	}
	
	if (document.getElementById('countrySelect').value=="Canada"){
		document.getElementById('CA-State-Field').style.display = 'block';
	}
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//THIS IS SET A COOKIE FOR EACH CTA THE USER SIGNS UP FOR ETC. "createCookie('Zdemo','set','7');" ----------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}



//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//CHANGE DIV ON COMPLETE SCRIPT --------------------------------------------------------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

function showthx(){
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById('ftform').style.display = 'none';
	}else{
		if (document.layers){ // Netscape 4
			document.ftform.display = 'none';
		}else{ // IE 4
			document.all.ftform.style.display = 'none';
		}
	}
	if (document.getElementById){ // DOM3 = IE5, NS6
		document.getElementById('ftthx').style.display = 'block';
	}else{
		if (document.layers){ // Netscape 4
			document.ftthx.display = 'block';
		}else{ // IE 4
			document.all.ftform.style.display = 'block';
		}
	}
	
}



//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//HIDES AND BLOCKS SPECIFY FIELDS FOR INDUSTRY AND JOB FUNCTION ------------------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

function questionIndustry() {
	if(document.getElementById('Session.user.industry').value=="Other"){
		document.getElementById('otherIndustry').style.display='block';
		//alert("Others");
	}
	
	if(document.getElementById('Session.user.industry').value==""){
		document.getElementById('otherIndustry').style.display='none';
		//alert("Others");
	}
}

function questionJobFunction() {
	if(document.getElementById('Session.user.jobFunction').value=="Other"){
		document.getElementById('otherJobFunction').style.display='block';
		//alert("Others");
	}else{
		document.getElementById('otherJobFunction').style.display='none';
		document.getElementById('Session.user.jobFunction.specify').value='';
		//alert("Something else");
	}
}

	
	
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//STEP ONE: Validating fields and if oki submitting email for a token.
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



function dostuff(){
	
	
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//USE TO CHECK FOR VALUE IN ARRAY - ETC: pcode.inArray(postalcode)
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	
	if (!Array.prototype.inArray) {
		Array.prototype.inArray=function(val) {
			for (key in this) {
				if (this[key]===val) {
					//alert("YES");
					return true; // If you want the key of the matched value, change "true" to "key"
				}
			}
			//alert("NO");
			return false;
		}
	}
	
	
	
  	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//REGULAR EXPRESSIONS
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	
	var msg = "";
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	//var usphone = /^(\()?(\d{3})([\)-\. ])?(\d{3})([-\. ])?(\d{4})$/;
	//var regPostcode = /^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([ ])([0-9][a-zA-z][a-zA-z]){1}$/;
	
	
	
	//EMAIL VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(document.getElementById('required.email')){
		if (!emailFilter.test(document.getElementById('Session.user.email').value))
			msg += "Email address is invalid\n";
			
		if(document.getElementById('Session.user.email').value.match(illegalChars))
		msg += "Email address is invalid\n";
	}
		
	
	
	
	//NAME VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(document.getElementById('required.name')){
		if(document.getElementById('Session.user.name').value.length<1)
			msg += "Please enter a username\n";
	}
	
	//COMPANY VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(document.getElementById('required.company')){
		if(document.getElementById('Session.user.companyName').value.length<1)
			msg += "Please enter a company\n"
	}
	
	
	//PHONE VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//If Country is DK, NO or SE then do not validate phone
	if(document.getElementById('required.phone')){
			if(document.getElementById('Session.user.phone').value.length<5)
			msg += "Please enter a correct phone number\n";
			
			/*if(document.getElementById('countrySelect').value=="United States"){
				if (!usphone.test(document.getElementById('Session.user.phone').value))
				msg += "Phonenumber is not valid - use XXX XXX XXXX\n";
			}*/
	}
	
	
	//CONTACT MESSAGE VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//If Country is DK, NO or SE then do not validate phone
	if(document.getElementById('required.contactmessage')){
			if(document.getElementById('Session.user.message').value.length<5)
			msg += "Please enter a message\n";
	}
	
	
	//JOB FUNCTION VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(document.getElementById('required.jobFunction')){
		if(document.getElementById('Session.user.jobFunction').value.length<1)
			msg += "Please choose a job function\n";
			
		if(document.getElementById('Session.user.jobFunction').value == "Other" && document.getElementById('Session.user.jobFunction.specify').value.length<1)
			msg += "Please specify your job function\n";
	}
	
	
	//INDUSTRY VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(document.getElementById('required.industry')){
		if(document.getElementById('Session.user.industry').value.length<1)
			msg += "Please choose an industry\n";
			
		if(document.getElementById('Session.user.industry').value == "Other" && document.getElementById('Session.user.industry.specify').value.length<1)
			msg += "Please specify your industry\n";
	}
			
	//COUNTRY VALIDATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(document.getElementById('countrySelect')){
		if(document.getElementById('countrySelect').options[document.getElementById('countrySelect').selectedIndex].value=="")
			msg += "Please select a country\n";
	}
	
	if(document.getElementById('countrySelect')){
		if(document.getElementById('countrySelect').value=="United States" && document.getElementById('USstateSelect').value=="")
			msg += "Please select a state\n";
	}
	
	
	//IF ANY ERRORS - RESET BUTTON VALUE TO "GO!" AND ALERT ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	if(msg.length>0){
		document.getElementById('submitbut').value = "Go!";
		document.getElementById('submitbut').disabled=true;
		alert("Please fill in the form correctly!\n\nThe following errors where detected:\n"+ msg);
		document.getElementById('submitbut').disabled=false;
		return;
	}else{
		
		//Next two if's inserts the Us or Ca state into a third field which is posted to marketo
		if(document.getElementById('USstateSelect').value.length>1){
			document.getElementById('stateSelect').value = document.getElementById('USstateSelect').value;
			//alert(document.getElementById('stateSelect').value);
		}
		if(document.getElementById('CAstateSelect').value.length>1){
			document.getElementById('stateSelect').value = document.getElementById('CAstateSelect').value;
			//alert(document.getElementById('stateSelect').value);
		}
		setTimeout(redir,1000);
	}
}



//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//COUNTRY AND STATE SCRIPT --------------------------------------------------------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



var stateCA_array = {
	'' : "Select State",
	AB : "Alberta",
	BC : "British Columbia",
	MB : "Manitoba",
	NB : "New Brunswick",
	NF : "Newfoundland and Labrador",
	ON : "Ontario",
	SK : "Saskatchewan"
};

var stateUS_array = {
	'' : "Select State",
	AK : "Alaska",
	AL : "Alabama",
	AR : "Arkansas",
	AZ : "Arizona",
	CA : "California",
	CO : "Colorado",
	CT : "Connecticut",
	DC : "District of Columbia",
	DE : "Delaware",
	FL : "Florida",
	GA : "Georgia",
	HI : "Hawaii",
	IA : "Iowa",
	ID : "Idaho",
	IL : "Illinois",
	IN : "Indiana",
	KS : "Kansas",
	KY : "Kentucky",
	LA : "Louisiana",
	MA : "Massachusetts",
	MD : "Maryland",
	ME : "Maine",
	MI : "Michigan",
	MN : "Minnesota",
	MO : "Missouri",
	MS : "Mississippi",
	MT : "Montana",
	NC : "North Carolina",
	ND : "North Dakota",
	NE : "Nebraska",
	NH : "New Hampshire",
	NJ : "New Jersey",
	NM : "New Mexico",
	NV : "Nevada",
	NY : "New York",
	OH : "Ohio",
	OK : "Oklahoma",
	OR : "Oregon",
	PA : "Pennsylvania",
	RI : "Rhode Island",
	SC : "South Carolina",
	SD : "South Dakota",
	TN : "Tennessee",
	TX : "Texas",
	UT : "Utah",
	VA : "Virginia",
	VT : "Vermont",
	WA : "Washington",
	WI : "Wisconsin",
	WV : "West Virginia"
};




var country_array = {
	'' : "Select Country",
	'United Kingdom' : "United Kingdom",
	'United States' : "United States",
    Denmark : "Denmark",
	Canada : "Canada",
	Sweden : "Sweden",
	Norway : "Norway",
	Germany : "Germany",
	Australia : "Australia",
	Netherlands : "Netherlands",
	Afghanistan : "Afghanistan",
	Albania : "Albania",
	Algeria : "Algeria",
	Andorra : "Andorra",
	Angola : "Angola",
	Antarctica : "Antarctica",
	'Antigua and Barbuda' : "Antigua and Barbuda",
	Argentina : "Argentina",
	Armenia : "Armenia",
	Austria : "Austria",
	Azerbaijan : "Azerbaijan",
	Bahamas : "Bahamas",
	Bahrain : "Bahrain",
	Bangladesh : "Bangladesh",
	Barbados : "Barbados",
	Belarus : "Belarus",
	Belgium : "Belgium",
	Belize : "Belize",
	Benin : "Benin",
	Bermuda : "Bermuda",
	Bhutan : "Bhutan",
	Bolivia : "Bolivia",
	'Bosnia and Herzegovina' : "Bosnia and Herzegovina",
	Botswana : "Botswana",
	Brazil : "Brazil",
	Brunei : "Brunei",
	Bulgaria : "Bulgaria",
	'Burkina Faso' : "Burkina Faso",
	Burma : "Burma",
	Burundi : "Burundi",
	Cambodia : "Cambodia",
	Cameroon : "Cameroon",
	'Cape Verde' : "Cape Verde",
	'Central African Republic' : "Central African Republic",
	Chad : "Chad",
	Chile : "Chile",
	China : "China",
	Colombia : "Colombia",
	Comoros : "Comoros",
	Congo : "Congo",
	'Costa Rica' : "Costa Rica",
	'Cote d Ivoire' : "Cote d Ivoire",
	Croatia : "Croatia",
	Cuba : "Cuba",
	Cyprus : "Cyprus",
	'Czech Republic' : "Czech Republic",
	Denmark : "Denmark",
	Djibouti : "Djibouti",
	Dominica : "Dominica",
	'Dominican Republic' : "Dominican Republic",
	'East Timor' : "East Timor",
	Ecuador : "Ecuador",
	Egypt : "Egypt",
	'El Salvador' : "El Salvador",
	'Equatorial Guinea' : "Equatorial Guinea",
	Eritrea : "Eritrea",
	Estonia : "Estonia",
	Ethiopia : "Ethiopia",
	Fiji : "Fiji",
	Finland : "Finland",
	France : "France",
	Gabon : "Gabon",
	Gambia : "Gambia",
	Georgia : "Georgia",
	Ghana : "Ghana",
	Greece : "Greece",
	Greenland : "Greenland",
	Grenada : "Grenada",
	Guatemala : "Guatemala",
	Guinea : "Guinea",
	'Guinea-Bissau' : "Guinea-Bissau",
	Guyana : "Guyana",
	Haiti : "Haiti",
	Holland : "Holland",
	Honduras : "Honduras",
	'Hong Kong' : "Hong Kong",
	Hungary : "Hungary",
	Iceland : "Iceland",
	India : "India",
	Indonesia : "Indonesia",
	Iran : "Iran",
	Iraq : "Iraq",
	'Ireland, Northern' : "Ireland, Northern",
	Ireland : "Ireland",
	Israel : "Israel",
	Italy : "Italy",
	Jamaica : "Jamaica",
	Japan : "Japan",
	Jordan : "Jordan",
	Kazakhstan : "Kazakhstan",
	Kenya : "Kenya",
	Kiribati : "Kiribati",
	'Korea, North' : "Korea, North",
	'Korea, South' : "Korea, South",
	Kuwait : "Kuwait",
	Kyrgyzstan : "Kyrgyzstan",
	Laos : "Laos",
	Latvia : "Latvia",
	Lebanon : "Lebanon",
	Lesotho : "Lesotho",
	Liberia : "Liberia",
	Libya : "Libya",
	Liechtenstein : "Liechtenstein",
	Lithuania : "Lithuania",
	Luxembourg : "Luxembourg",
	Macedonia : "Macedonia",
	Madagascar : "Madagascar",
	Malawi : "Malawi",
	Malaysia : "Malaysia",
	Maldives : "Maldives",
	Mali : "Mali",
	Malta : "Malta",
	'Marshall Islands' : "Marshall Islands",
	Mauritania : "Mauritania",
	Mauritius : "Mauritius",
	Mexico : "Mexico",
	Micronesia : "Micronesia",
	Moldova : "Moldova",
	Mongolia : "Mongolia",
	Morocco : "Morocco",
	Monaco : "Monaco",
	Mozambique : "Mozambique",
	Namibia : "Namibia",
	Nauru : "Nauru",
	Nepal : "Nepal",
	'New Zealand' : "New Zealand",
	Nicaragua : "Nicaragua",
	Niger : "Niger",
	Nigeria : "Nigeria",
	Oman : "Oman",
	Pakistan : "Pakistan",
	Panama : "Panama",
	'Papua New Guinea' : "Papua New Guinea",
	Paraguay : "Paraguay",
	Peru : "Peru",
	Philippines : "Philippines",
	Poland : "Poland",
	Portugal : "Portugal",
	Qatar : "Qatar",
	Romania : "Romania",
	Russia : "Russia",
	Rwanda : "Rwanda",
	Samoa : "Samoa",
	'San Marino' : "San Marino",
	'Sao Tome' : "Sao Tome",
	'Saudi Arabia' : "Saudi Arabia",
	Senegal : "Senegal",
	'Serbia and Montenegro' : "Serbia and Montenegro",
	Seychelles : "Seychelles",
	'Sierra Leone' : "Sierra Leone",
	Singapore : "Singapore",
	Slovakia : "Slovakia",
	Slovenia : "Slovenia",
	'Solomon Islands' : "Solomon Islands",
	Somalia : "Somalia",
	'South Africa' : "South Africa",
	Spain : "Spain",
	'Sri Lanka' : "Sri Lanka",
	Sudan : "Sudan",
	Suriname : "Suriname",
	Swaziland : "Swaziland",
	Switzerland : "Switzerland",
	Syria : "Syria",
	Taiwan : "Taiwan",
	Tajikistan : "Tajikistan",
	Tanzania : "Tanzania",
	Thailand : "Thailand",
	'Togo, Tonga' : "Togo, Tonga",
	'Trinidad and Tobago' : "Trinidad and Tobago",
	Tunisia : "Tunisia",
	Turkey : "Turkey",
	Turkmenistan : "Turkmenistan",
	Uganda : "Uganda",
	Ukraine : "Ukraine",
	'United Arab Emirates' : "United Arab Emirates",
	Uruguay : "Uruguay",
	Uzbekistan : "Uzbekistan",
	Vanuatu : "Vanuatu",
	Venezuela : "Venezuela",
	Vietnam : "Vietnam",
	Yemen : "Yemen",
	Zambia : "Zambia",
	Zimbabwe : "Zimbabwe"
};


//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//INSERTS COUNTRY VALUES IN FORM----------------------------------------------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(document.getElementById('Country-Field')){
	var select1 = document.getElementById("countrySelect");
	for(index in country_array) {
		select1.options[select1.options.length] = new Option(country_array[index], index);
	}



	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//IP COUNTRY DETECT - SCRIPT FROM http://www.maxmind.com/app/javascript
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	var ip_country  = (geoip_country_name());
		
	if (document.getElementById('countrySelect').value<1){
		document.getElementById('countrySelect').value = ip_country;
	}

	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//INSERTS US STATE VALUES IN FORM----------------------------------------------------------------------------
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	var select2 = document.getElementById("USstateSelect");
	for(index in stateUS_array) {
		select2.options[select2.options.length] = new Option(stateUS_array[index], index);
	}

	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	//INSERTS CA STATE VALUES IN FORM----------------------------------------------------------------------------
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	var select3 = document.getElementById("CAstateSelect");
	for(index in stateCA_array) {
		select3.options[select3.options.length] = new Option(stateCA_array[index], index);
	}
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//HIDES AND BLOCK STATE/POSTAL FIELDS DEPENDING ON CHOSEN COUNTRY-----------------------------------------
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function checkCountry() {
	
	if(document.getElementById('countrySelect').value=="United States"){
		document.getElementById('US-State-Field').style.display='block';
	}
	if(document.getElementById('countrySelect').value!="United States"){
		document.getElementById('USstateSelect').value ='';
		document.getElementById('US-State-Field').style.display = 'none';
	}
	
	
	if(document.getElementById('countrySelect').value=="Canada"){
		document.getElementById('CA-State-Field').style.display='block';
	}
	if(document.getElementById('countrySelect').value!="Canada"){
		document.getElementById('CAstateSelect').value ='';
		document.getElementById('CA-State-Field').style.display = 'none';
	}
} 