var submitSignupURLProd = 'https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=23&deploy=1&compid=915750&h=82984b2037a6207d1245';

function isEmail(value) {
	return value.match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i);
}
function isURL(value) {
	return value.match(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);
}


function submitInformation() {
	var submitInfo = true;
	if(($("#firstname").val() == '') || ($("#lastname").val() == '')) { $("#nameerror").show(); submitInfo = false; }
	else { $("#nameerror").hide(); }
	if(!isEmail($("#email").val())) { $("#emailerror").show(); submitInfo = false; }
	else { $("#emailerror").hide(); }
	if($("#companyname").val() == '') { $("#companyerror").show(); submitInfo = false; }
	else { $("#companyerror").hide(); }
	if($("#address").val() == '') { $("#addresserror").show(); submitInfo = false; }
	else { $("#addresserror").hide(); }
	if($("#city").val() == '') { $("#cityerror").show(); submitInfo = false; }
	else { $("#cityerror").hide(); }
	if($("#stateSelect").val() == '') { $("#stateerror").show(); submitInfo = false; }
	else { $("#stateerror").hide(); }
	if($("#zip").val() == '') { $("#ziperror").show(); submitInfo = false; }
	else { $("#ziperror").hide(); }
	//if($("#weburl").val() != '') {
		//alert($("#weburl").val());
		//var is_url = isURL($("#weburl").val());
		//alert(is_url);
		//if(!isURL($("#weburl").val())) { $("#weburlerror").show(); submitInfo = false; }
		//else { $("#weburlerror").hide(); }
	//}
	if(submitInfo) {
		$("#closeSubmitWindow").hide();
		var oldLinks = $("#submitSubmitWindow").html();
		$("#submitSubmitWindow").html("<img src='./img/35.gif''/>");
		$.getJSON(		submitSignupURLProd+'&callback=?',
						{	firstname: $("#firstname").val(),
							lastname: $("#lastname").val(),
							company: $("#companyname").val(),
							email: $("#email").val(),
							addressline1: $("#address").val(),
							city: $("#city").val(),
							state: $("#stateSelect").val(),
							country: $("#countrySelect").val(),
							zip: $("#zip").val(),
							webaddress: $("#weburl").val()
						},
						function (json) {
							var isOK = (json.result == 'ok');
							if(isOK) {
								$("#signupPageOne").hide();
								$("#thankyou").show();
								$("#submitError").hide();
							}
							else {
								$("#closeSubmitWindow").show();
								$("#submitSubmitWindow").html(oldLinks);
								$("#submitError").show();
							}
						});
	}
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
	else return true;
}

// State table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var state = '\
US:AK:Alaska|\
US:AL:Alabama|\
US:AR:Arkansas|\
US:AS:American Samoa|\
US:AZ:Arizona|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DC:D.C.|\
US:DE:Delaware|\
US:FL:Florida|\
US:FM:Micronesia|\
US:GA:Georgia|\
US:GU:Guam|\
US:HI:Hawaii|\
US:IA:Iowa|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:MA:Massachusetts|\
US:MD:Maryland|\
US:ME:Maine|\
US:MH:Marshall Islands|\
US:MI:Michigan|\
US:MN:Minnesota|\
US:MO:Missouri|\
US:MP:Marianas|\
US:MS:Mississippi|\
US:MT:Montana|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:NE:Nebraska|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NV:Nevada|\
US:NY:New York|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:PR:Puerto Rico|\
US:PW:Palau|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VA:Virginia|\
US:VI:Virgin Islands|\
US:VT:Vermont|\
US:WA:Washington|\
US:WI:Wisconsin|\
US:WV:West Virginia|\
US:WY:Wyoming|\
US:AA:Military Americas|\
US:AE:Military Europe/ME/Canada|\
US:AP:Military Pacific|\
CA:AB:Alberta|\
CA:MB:Manitoba|\
CA:AB:Alberta|\
CA:BC:British Columbia|\
CA:MB:Manitoba|\
CA:NB:New Brunswick|\
CA:NL:Newfoundland and Labrador|\
CA:NS:Nova Scotia|\
CA:NT:Northwest Territories|\
CA:NU:Nunavut|\
CA:ON:Ontario|\
CA:PE:Prince Edward Island|\
CA:QC:Quebec|\
CA:SK:Saskatchewan|\
CA:YT:Yukon Territory|\
AU:AAT:Australian Antarctic Territory|\
AU:ACT:Australian Capital Territory|\
AU:NT:Northern Territory|\
AU:NSW:New South Wales|\
AU:QLD:Queensland|\
AU:SA:South Australia|\
AU:TAS:Tasmania|\
AU:VIC:Victoria|\
AU:WA:Western Australia|\
GB:Aberdeenshire:Aberdeenshire|\
GB:Angus:Angus|\
GB:Argyll:Argyll|\
GB:Avon:Avon|\
GB:Ayrshire:Ayrshire|\
GB:Banffshire:Banffshire|\
GB:Beds.:Bedfordshire|\
GB:Berks.:Berkshire|\
GB:Berwickshire:Berwickshire|\
GB:Bucks.:Buckinghamshire|\
GB:Caithness:Caithness|\
GB:Cambs.:Cambridgeshire|\
GB:Ches.:Cheshire|\
GB:Clackmannanshire:Clackmannanshire|\
GB:Cleveland:Cleveland|\
GB:Clwyd:Clwyd|\
GB:Cornwall:Cornwall|\
GB:Co Antrim:County Antrim|\
GB:Co Armagh:County Armagh|\
GB:Co Down:County Down|\
GB:Co Fermanagh:County Fermanagh|\
GB:Co Londonderry:County Londonderry|\
GB:Co Tyrone:County Tyrone|\
GB:Cumb.:Cumberland|\
GB:Cumbria:Cumbria|\
GB:Derbys.:Derbyshire|\
GB:Devon:Devon|\
GB:Dorset:Dorset|\
GB:Dumfriesshire:Dumfriesshire|\
GB:Dunbartonshire:Dunbartonshire|\
GB:Durham:Durham|\
GB:Dyfed:Dyfed|\
GB:E Lothian:East Lothian|\
GB:E Sussex:East Sussex|\
GB:Essex:Essex|\
GB:Fife:Fife|\
GB:Gloucs.:Gloucestershire|\
GB:London:Greater London|\
GB:Gwent:Gwent|\
GB:Gwynedd:Gwynedd|\
GB:Hants.:Hampshire|\
GB:Hereford:Herefordshire|\
GB:Herts.:Hertfordshire|\
GB:Hunts.:Huntingdonshire|\
GB:Inverness-shire:Inverness-shire|\
GB:Isle of Arran:Isle of Arran|\
GB:Isle of Barra:Isle of Barra|\
GB:Isle of Benbecula:Isle of Benbecula|\
GB:Isle of Bute:Isle of Bute|\
GB:Isle of Canna:Isle of Canna|\
GB:Isle of Coll:Isle of Coll|\
GB:Isle of Colonsay:Isle of Colonsay|\
GB:Isle of Cumbrae:Isle of Cumbrae|\
GB:Isle of Eigg:Isle of Eigg|\
GB:Isle of Gigha:Isle of Gigha|\
GB:Isle of Harris:Isle of Harris|\
GB:Isle of Iona:Isle of Iona|\
GB:Isle of Islay:Isle of Islay|\
GB:Isle of Jura:Isle of Jura|\
GB:Isle of Lewis:Isle of Lewis|\
GB:Isle of Mull:Isle of Mull|\
GB:Isle of North Uist:Isle of North Uist|\
GB:Isle of Rum:Isle of Rum|\
GB:Isle of Scalpay:Isle of Scalpay|\
GB:Isle of Skye:Isle of Skye|\
GB:Isle of South Uist:Isle of South Uist|\
GB:Isle of Tiree:Isle of Tiree|\
GB:Isle of Wight:Isle of Wight|\
GB:Kent:Kent|\
GB:Kincardineshire:Kincardineshire|\
GB:Kinross-shire:Kinross-shire|\
GB:Kirkcudbrightshire:Kirkcudbrightshire|\
GB:Lanarkshire:Lanarkshire|\
GB:Lancs.:Lancashire|\
GB:Leics.:Leicestershire|\
GB:Lincs.:Lincolnshire|\
GB:Merseyside:Merseyside|\
GB:M Glam:Mid Glamorgan|\
GB:Mid Lothian:Mid Lothian|\
GB:Middx.:Middlesex|\
GB:Morayshire:Morayshire|\
GB:Nairnshire:Nairnshire|\
GB:Norfolk:Norfolk|\
GB:N Humberside:North Humberside|\
GB:N Yorkshire:North Yorkshire|\
GB:Northants.:Northamptonshire|\
GB:Northumberland:Northumberland|\
GB:Notts.:Nottinghamshire|\
GB:Oxon.:Oxfordshire|\
GB:Peeblesshire:Peeblesshire|\
GB:Perthshire:Perthshire|\
GB:Powys:Powys|\
GB:Renfrewshire:Renfrewshire|\
GB:Ross-shire:Ross-shire|\
GB:Roxburghshire:Roxburghshire|\
GB:Rutland:Rutland|\
GB:Selkirkshire:Selkirkshire|\
GB:Shrops:Shropshire|\
GB:Somt.:Somerset|\
GB:S Glam:South Glamorgan|\
GB:S Humberside:South Humberside|\
GB:S Yorkshire:South Yorkshire|\
GB:Staffs.:Staffordshire|\
GB:Stirlingshire:Stirlingshire|\
GB:Suffolk:Suffolk|\
GB:Surrey:Surrey|\
GB:Sutherland:Sutherland|\
GB:Tyne & Wear:Tyne and Wear|\
GB:Warks:Warwickshire|\
GB:W Glam:West Glamorgan|\
GB:W Lothian:West Lothian|\
GB:W Midlands:West Midlands|\
GB:W Sussex:West Sussex|\
GB:W Yorkshire:West Yorkshire|\
GB:Wigtownshire:Wigtownshire|\
GB:Wilts:Wiltshire|\
GB:Worcs:Worcestershire|';

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

function populateState() {
  var selObj = document.getElementById('stateSelect');
  var foundState = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
    selObj.options[0] = new Option('Select State','');
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray = state.split("|");  // Split into lines
  var optionCntr = 1;
  for (var loop = 0; loop < stateLineArray.length; loop++) {
    lineArray = stateLineArray[loop].split(":");
    countryCode  = TrimString(lineArray[0]);
    stateCode    = TrimString(lineArray[1]);
    stateName    = TrimString(lineArray[2]);
  	if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
    	// If it's a input element, change it to a select
      	if ( selObj.type == 'text' ) {
        	parentObj = document.getElementById('stateSelect').parentNode;
        	parentObj.removeChild(selObj);
        	var inputSel = document.createElement("SELECT");
        	inputSel.setAttribute("name","state");
        	inputSel.setAttribute("id","stateSelect");
       		parentObj.appendChild(inputSel) ;
        	selObj = document.getElementById('stateSelect');
        	selObj.options[0] = new Option('Select State','');
        	selObj.selectedIndex = 0;
      	}
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      foundState = true;
      optionCntr++
    }
  }
}

		$(document).ready(function () {
			if($.browser.msie)  { 
				$("img").pngfix(); 
			}
			$(".rollover, .scrollButtons").mousedown(function() {
				$(this).attr("src", $(this).attr("src").replace(/_rollover.jpg$/ig,"_clicked.jpg"));
			});
			$(".rollover, .scrollButtons").mouseup(function() {
				$(this).attr("src", $(this).attr("src").replace(/_clicked.jpg$/ig,"_rollover.jpg"));
			});
			$(".rollover, .scrollButtons").hover(function() {
				$(this).attr("src", $(this).attr("src").replace(/.jpg$/ig,"_rollover.jpg"));
				}, function() {
				$(this).attr("src", $(this).attr("src").replace(/_rollover.jpg$/ig,".jpg"));
			});
		//populateState();
	});

