// JavaScript Document
statenames = new Array(51);
statenames[0] = "Alabama";
statenames[1] = "Alaska";
statenames[2] = "Arizona";
statenames[3] = "Arkansas";
statenames[4] = "California";
statenames[5] = "Colorado";
statenames[6] = "Connecticut";
statenames[7] = "Delaware";
statenames[8] = "Florida";
statenames[9] = "Georgia";
statenames[10] = "Hawaii";
statenames[11] = "Idaho";
statenames[12] = "Illinois";
statenames[13] = "Indiana";
statenames[14] = "Iowa";
statenames[15] = "Kansas";
statenames[16] = "Kentucky";
statenames[17] = "Louisiana";
statenames[18] = "Maine";
statenames[19] = "Maryland";
statenames[20] = "Massachusetts";
statenames[21] = "Michigan";
statenames[22] = "Minnesota";
statenames[23] = "Mississippi";
statenames[24] = "Missouri";
statenames[25] = "Montana";
statenames[26] = "Nebraska";
statenames[27] = "Nevada";
statenames[28] = "New Hampshire";
statenames[29] = "New Jersey";
statenames[30] = "New Mexico";
statenames[31] = "New York";
statenames[32] = "North Carolina";
statenames[33] = "North Dakota";
statenames[34] = "Ohio";
statenames[35] = "Oklahoma";
statenames[36] = "Oregon";
statenames[37] = "Pennsylvania";
statenames[38] = "Rhode Island";
statenames[39] = "South Carolina";
statenames[40] = "South Dakota";
statenames[41] = "Tennessee";
statenames[42] = "Texas";
statenames[43] = "Utah";
statenames[44] = "Vermont";
statenames[45] = "Virginia";
statenames[46] = "Washington";
statenames[47] = "Washington D.C.";
statenames[48] = "West Virginia";
statenames[49] = "Wisconsin";
statenames[50] = "Wyoming";

                         stateabbreviation = new Array(51);
                         stateabbreviation[0] = "AL";
                          stateabbreviation[1] = "AK";
                          stateabbreviation[2] = "AZ";
                  		 stateabbreviation[3] = "AR";
                          stateabbreviation[4] = "CA";
                          stateabbreviation[5] = "CO";
                          stateabbreviation[6] = "CT";
                          stateabbreviation[7] = "DE";
                          stateabbreviation[8] = "FL";
                          stateabbreviation[9] = "GA";
                          stateabbreviation[10] = "HI";
                          stateabbreviation[11] = "ID";
                          stateabbreviation[12] = "IL";
                          stateabbreviation[13] = "IN";
                          stateabbreviation[14] = "IA";
                          stateabbreviation[15] = "KS";
                          stateabbreviation[16] = "KY";
                          stateabbreviation[17] = "LA";
                          stateabbreviation[18] = "ME";
                          stateabbreviation[19] = "MD";
                          stateabbreviation[20] = "MA";
                          stateabbreviation[21] = "MI";
                          stateabbreviation[22] = "MN";
                          stateabbreviation[23] = "MS";
                          stateabbreviation[24] = "MO";
                          stateabbreviation[25] = "MT";
                          stateabbreviation[26] = "NE";
                          stateabbreviation[27] = "NV";
                          stateabbreviation[28] = "NH";
                          stateabbreviation[29] = "NJ";
                          stateabbreviation[30] = "NM";
                          stateabbreviation[31] = "NY";
                          stateabbreviation[32] = "NC";
                          stateabbreviation[33] = "ND";
                          stateabbreviation[34] = "OH";
                          stateabbreviation[35] = "OK";
                          stateabbreviation[36] = "OR";
                          stateabbreviation[37] = "PA";
                          stateabbreviation[38] = "RI";
                          stateabbreviation[29] = "SC";
                          stateabbreviation[40] = "SD";
                          stateabbreviation[41] = "TN";
                          stateabbreviation[42] = "TX";
                          stateabbreviation[43] = "UT";
                          stateabbreviation[44] = "VT";
                       		stateabbreviation[45] = "VA";
                       		stateabbreviation[46] = "WA";
                       		stateabbreviation[47] = "DC";
                          stateabbreviation[48] = "WV";
                          stateabbreviation[49] = "WI";
                          stateabbreviation[50] = "WY";
              
provincenames = new Array(13);           
provincenames[0] = "Alberta";
provincenames[1] = "British Columbia";
provincenames[2] = "Manitoba";
provincenames[3] = "New Brunswick";
provincenames[4] = "Newfoundland and Labrador";
provincenames[5] = "Northwest Territories";
provincenames[6] = "Nova Scotia";
provincenames[7] = "Nunavut";
provincenames[8] = "Ontario";
provincenames[9] = "Prince Edward Island";
provincenames[10] = "Quebec";
provincenames[11] = "Saskatchewan";
provincenames[12] = "Yukon";

provinceabbreviations = new Array(13);           
provinceabbreviations[0] = "AB";
provinceabbreviations[1] = "BC";
provinceabbreviations[2] = "MB";
provinceabbreviations[3] = "NB";
provinceabbreviations[4] = "NL";
provinceabbreviations[5] = "NT";
provinceabbreviations[6] = "NS";
provinceabbreviations[7] = "NU";
provinceabbreviations[8] = "ON";
provinceabbreviations[9] = "PE";
provinceabbreviations[10] = "QC";
provinceabbreviations[11] = "SK";
provinceabbreviations[12] = "YT";



function activateState() {
  if (document.form.country.value.toLowerCase()=="canada" || document.form.country.value.toLowerCase()=="usa") {
    document.form.state.disabled=false;
	updateState();
  }
  else {
    document.form.state.disabled=true;
  }
}

function updateState() {
	document.form.state.length=0;
    var country = (document.form.country.value);
    document.form.state.options[0] = new Option("Select...");
    document.form.state.options[0].value = "";
    if ( country.toLowerCase()=="usa" )
    {
        for( var i = 0; i < statenames.length; i++)
        {
            document.form.state.options[i+1]= new Option(statenames[i]);
            document.form.state.options[i+1].value = stateabbreviation[i];
        }
    }
	else if ( country.toLowerCase()=="canada" ) {
		for( var i = 0; i < provincenames.length; i++)
        {
            document.form.state.options[i+1]= new Option(provincenames[i]);
            document.form.state.options[i+1].value = provinceabbreviations[i];
        }
	}
}


// Check against blacklist
function validateEmail(myEmail)
{
  email = myEmail.toLowerCase();
  blacklist = new Array("BORLAND.COM","RYMATECH.COM","RALLYDEV.COM",
      "FOCALPOINT.COM","TELELOGIC.COM","FEATUREPLAN.COM","SERENA.COM",
      "ALIGNENT.COM","COLLAB.NET","AGILE.COM","TRUEREQ.COM","VASOFTWARE.COM",
      "IRISE.COM","VERSIONONE.NET","SPEEDEV.COM","RAVENFLOW.COM","VISTAAR.COM",
      "AISC.COM","MATRIXONE.COM","DS-FR.COM","DS-US.COM","SMARTEAM.COM","AREASOLUTIONS.COM"
  );
  for (i=0;i<blacklist.length;i++) {
    myRE = new RegExp(blacklist[i], "i");
    results = email.match(myRE);
    if (results != null) {
      window.location="sorry-personal.html";
  	  return (false);
    }
  }
  blacklist = new Array("alltel.net", "att.net", "attglobal.net", "aol.com",
                  "bellsouth.net", 
                  "charter.net", "comcast.net", "cox.net", 
                  "dr.dk", 
                  "earthlink.net", "excite.com", 
                  "GMAIL.com", "gmx.de", "gmx.net", 
                  "hot.gr", "HOTMAIL.com", 
                  "laposte.net", 
                  "mindspring.com", "msn.com", "myrealbox.com", 
                  "pacbell.net", 
                  "sbcglobal.net", "simpatico.ca", "somtel.net", "sprintmail.com", 
                  "telus.net", 
                  "usa.net", 
                  "YAHOO.com"
  );
  for (i=0;i<blacklist.length;i++) {
    myRE = new RegExp(blacklist[i], "i");
    results = email.match(myRE);
    if (results != null) {
      window.location="sorry-personal.html";
  	  return (false);
    }
  }
  myRE = new RegExp("aol.com", "i");
  results = email.match(myRE);
  if (results != null) {
    if (document.form.company.value.toLowerCase()=="aol" || document.form.company.value.toLowerCase()=="america online") {
      return (true);
    }
    else {
      window.location="../../resource_library/sorry_comp.html";
      return (false);
    }
  }
  
  return (true);
}






function verify() {
var themessage = "Please fill in all require fields:\n";
if (Trim(document.form.first_name.value)=="") {
themessage = themessage + "First Name\n";
}
if (Trim(document.form.last_name.value)=="") {
themessage = themessage + "Last Name\n";
}
if (Trim(document.form.title.value)=="") {
themessage = themessage + "Title\n";
}
if (Trim(document.form.company.value)=="") {
themessage = themessage + "Company\n";
}
if (Trim(document.form.phone.value)=="") {
themessage = themessage + "Phone\n";
}

if (Trim(document.form.email.value)=="") {
themessage = themessage + "E-mail\n";
}

if (document.form.state.disabled==false && document.form.state.value=="") {
themessage = themessage + "State\n";
}

if (document.form.country.value=="") {
themessage = themessage + "Country\n";
}
else {
	if (document.form.state.disabled==true && document.form.country.value.toLowerCase()=="canada" || document.form.state.disabled==true && document.form.country.value.toLowerCase()=="usa") {
		document.form.state.disabled=false;
		updateState();
		themessage = themessage + "State\n";
	}
}


//alert if fields are empty and cancel form submit
if (themessage == "Please fill in all require fields:\n") {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.form.email.value)) {
    if (validateEmail(document.form.email.value)) {
		document.form.submit();
		
	
    }
	}
	else {
		alert("Please enter valid Email");
		return false;
	}
}
else {
alert(themessage);
return false;
   }
}


function Trim(str)
{
  while(str.charAt(0) == (" ") )
  {  
    str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  
    str = str.substring(0,str.length-1);
  }
  return str;
}


// 
function init() {
	activateState();
}

window.onload = init;