function processSiteChange(el) {
	var strLocation = el.options[el.selectedIndex].value;
	var re = 'http';
	if (strLocation!='') {
		if (strLocation.search(re) != -1) {
			window.open(strLocation, '');
		} else {
			window.location = "http://www.deloitte.com" +el.options[el.selectedIndex].value;
		}
	}
}

function replaceAll(strChk, strFind, strReplace) {
  var strOut = strChk;
  while (strOut.indexOf(strFind) > -1) {
    strOut = strOut.replace(strFind, strReplace);
  }
  return strOut;
} 

function validateEmail(email) {
  var at="@"
  var dot="."
  var lat=email.indexOf(at)
  var lstr=email.length
  var ldot=email.indexOf(dot)

  if (email.indexOf(at)==-1){
    return false;
  }
  if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
    return false;
  }
  if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
    return false;
  }
  if (email.indexOf(at,(lat+1))!=-1){
    return false;
  }
  if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
    return false;
  }
  if (email.indexOf(dot,(lat+2))==-1){
    return false;
  }
  if (email.indexOf(" ")!=-1){
    return false;
  }
  return true;
}

function validateForm () {
  var errors = '';
  if (document.info.company.value=="Enter a company" ||
      document.info.company.value=="Écrire le nom de votre société") document.info.company.value="";
  postal = new String(document.info.postalcode.value);
  postal = replaceAll(postal,' ','')
  var infostatus = (document.info.status.value == "Active" && document.getElementById('15').checked);
  if (get_cookie('language') == 'fr'){
    if (!document.info.firstname.value)                                                                 errors += 'Prénom requis \n';
    if (!document.info.lastname.value)                                                                  errors += 'Nom de famille requis \n';
    if (!document.info.emailaddress.value)                                                              errors += 'Adresse courriel requise \n'; 
    else if (!validateEmail(document.info.emailaddress.value))                                          errors += 'Adresse courriel non valide. Essayez à nouveau \n';
    if (!document.info.status.value)                                                                    errors += 'Situation requise \n';
    if (!document.info.company.value && infostatus)                                                     errors += 'Société requise \n';
    if (!document.info.industry.value && infostatus)                                                    errors += 'Secteur requis \n';
    if (!document.info.title.value && infostatus)                                                       errors += 'Titre du poste requis \n';
    myPass = new String(document.info.password.value);
    if (myPass.length < 4)                                                                              errors += 'La zone du mot de passe doit comporter au moins 4 caractères \n';
    if (document.info.password.value != document.info.password2.value)                                  errors += 'Les mots de passe ne correspondent pas \n';
    if(!(document.info.phone1.value && document.info.phone2.value && document.info.phone3.value)
        && infostatus)                                                                                  errors += 'Numéro de téléphone requise \n';

    if(!document.info.city.value)                                                                       errors += 'Ville requis \n';
    if(!document.info.state.value && 
      (document.info.country.value == "USA" || document.info.country.value == "Canada"))    errors += 'Prov/État requis \n';
    if (postal.length != 5 && postal.length != 9 && document.info.country.value == "USA")               errors += 'Code postal requis \n';
    else if (!(isNumeric(postal)) && document.info.country.value == "USA")                              errors += 'Code postal requis \n';
    if (postal.length != 6 && document.info.country.value == "Canada")                                  errors += 'Code postal requis \n'; 
    if(!(document.info.address1.value  && document.info.postalcode.value
      && document.info.country.value) && infostatus)                                                    errors += 'Adresse requise \n';
  }else{
    if (!document.info.firstname.value)                                                                 errors += 'First Name is required \n';
    if (!document.info.lastname.value)                                                                  errors += 'Last Name is required \n';
    if (!document.info.emailaddress.value)                                                              errors += 'E-mail Address is required \n'; 
    else if (!validateEmail(document.info.emailaddress.value))                                          errors += 'E-mail Address is invalid \n';
    if (!document.info.status.value)                                                                    errors += 'Status is required \n';
    if (!document.info.company.value && infostatus)                                                     errors += 'Company is required \n';
    if (!document.info.industry.value && infostatus)                                                    errors += 'Industry is required \n';
    if (!document.info.title.value && infostatus)                                                       errors += 'Job Title is required \n';
    myPass = new String(document.info.password.value);
    if (myPass.length < 4)                                                                              errors += 'Password field cannot be less than 4 characters long \n';
    if (document.info.password.value != document.info.password2.value)                                  errors += 'Passwords do not match \n';
    if(!(document.info.phone1.value && document.info.phone2.value && document.info.phone3.value)
        && infostatus)                                                                                  errors += 'Please Complete Phone Number \n';

    if(!document.info.city.value)                                                                       errors += 'City is required \n';
    if(!document.info.state.value && 
      (document.info.country.value == "USA" || document.info.country.value == "Canada"))    errors += 'Province/State is required \n';
    if (postal.length != 5 && document.info.country.value == "USA")                                     errors += 'Postal Code must be 5 or 9 digits in the United States \n';
    else if (!(isNumeric(postal)) && document.info.country.value == "USA")                              errors += 'Postal Code must be all numeric in the United States \n';
    if (postal.length != 6 && document.info.country.value == "Canada")                                  errors += 'Postal Code must be 6 alphanumerics in Canada \n'; 
    if(!(document.info.address1.value && document.info.postalcode.value
      && document.info.country.value) && infostatus)                                                    errors += 'Please Complete Full Address \n';
  }
  if (errors) {
    if (get_cookie('language') != 'fr'){
      alert("Errors \n\n" + errors);
    }else{
      alert(errors);
    }
    return false;
  }else{
    document.info.submit();
  }
}


function submitenter(myfield,e){
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13){
    isValidUser();
    return true
  }else{
    return true;
  }
}


function get_cookie(cookie_name)
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results ) 
    return ( unescape ( results[1] ) );
  else
    return null;
}


function isNumeric(sText){
  var ValidChars = "0123456789";
  var IsNumber=true;
  var Char;

 
  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1)
      IsNumber = false;
  }
  return IsNumber;
   
}



var win = null;
function open_window(page, name, details) {
  win = window.open(page,name,details);
}

function changeLanguage(lang){
  var today = new Date();
  var expire = new Date();
  expire.setTime(today.getTime() + 3600000*24*30); // 3600000 ms/hour * 24 hour/day * 30 days
  document.cookie = "language="+lang+ ";expires="+expire.toGMTString()+";path=/";
}

function isBlank(){
  if (document.info.company.value=="Enter a company" || document.info.company.value=="Écrire votre société"){
    document.info.company.value='';
  }
}

function mouseX(evt) {
  if (evt.pageX) {
    return evt.pageX + 10;
  }
  else if (evt.clientX) {
    return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + 10;
  }
  else {
    return null;
  }
}

function mouseY(evt) {
  if (evt.pageY) {
    return evt.pageY + 10;
  }
  else if (evt.clientY) {
    return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + 10;
  }
  else {
    return null;
  }
}


function showMonths (event,frcms) {
  if (frcms){
    document.getElementById('frmonthpopup').style.left=mouseX(event)+'px';
    document.getElementById('frmonthpopup').style.top=mouseY(event)+'px';
    document.getElementById('frmonthpopup').style.display='block';
  }else{
    document.getElementById('monthpopup').style.left=mouseX(event)+'px';
    document.getElementById('monthpopup').style.top=mouseY(event)+'px';
    document.getElementById('monthpopup').style.display='block';
  }
}

function closeMonths (id,frcms) {
  if (frcms) document.getElementById('frmonthpopup').style.display='none';
  document.getElementById('monthpopup').style.display='none';
}

function showPopup (id,event,description) {
  id.className='in';
  document.getElementById('mypopup').style.left=mouseX(event)+'px';
  document.getElementById('mypopup').style.top=mouseY(event)+'px';
  var tempText = '<span class="mediumText">' + description + '</span>';
  document.getElementById('mypopup').innerHTML=tempText;
  document.getElementById('mypopup').style.display='block';
}

function closePopup (id) {
  id.className='out';
  document.getElementById('mypopup').style.display='none';
}

function checkParent(parent){
  par = document.getElementById(parent);
  if (document.getElementById('January').checked || document.getElementById('February').checked || document.getElementById('March').checked ||
      document.getElementById('April').checked || document.getElementById('May').checked || document.getElementById('June').checked ||
      document.getElementById('July').checked || document.getElementById('August').checked || document.getElementById('September').checked ||
      document.getElementById('October').checked || document.getElementById('November').checked || document.getElementById('December').checked)
          par.checked = true;
  else
    par.checked = false;
}

function isValidUser() {
  var ajax = new thajax();
  clearWindowContents();
  loguser = document.login.loginusername.value;
  logpass = document.login.loginpassword.value;
  ajax.onError=function(){
    alert(this.error);
  }
  ajax.request("?_nox_&command=AJAX_getUser&loguser="+escape(loguser)+"&logpass="+escape(logpass), getCallBack);
}

function confirmDelete(){
  if (confirm("Are you sure you want to delete this profile?"))
    return true;
  else
    return false;
}

function isEmailInUse() {
  var ajax = new thajax();
  clearWindowContents();
  emailaddress = document.info.emailaddress.value;
  id = document.info.contactId.value;
  ajax.onError=function(){
    alert(this.error);
  }
  ajax.request("?_nox_&command=AJAX_getEmail&email="+escape(emailaddress)+"&id="+escape(id), getBack);
}

function isEmailInUseCMS() {
  var ajax = new thajax();
  clearWindowContents();
  emailaddress = document.info.emailaddress.value;
  id = document.info.contactId.value;
  ajax.onError=function(){
    alert(this.error);
  }
  ajax.request("?_nox_&alias=preferences&command=AJAX_getEmail&email="+escape(emailaddress)+"&id="+escape(id), getBack);
}

function getBack(ajax) {
  var xml = ajax.responseXML;
  var acct = xml.getElementsByTagName("a")[0];
  if (getNodeText(acct) == 'true'){
    if (get_cookie('language') == 'fr'){
      alert ("Cette adresse e-mail est déjà dans l'usage");
    }else{
      alert ("This email address is already in use.");
    }
  }else{
    validateForm();
  }
  
}

function getCallBack(ajax) {
  var xml = ajax.responseXML;
  var acct = xml.getElementsByTagName("a")[0];
  if (getNodeText(acct) == 'false'){
    if (get_cookie('language') == 'fr'){
      alert ("Combinaison courriel/mot de passe non trouvée");
    }else{
      alert ("Email / Password combination not found");
    }
  }else{
    document.login.submit();
  }
  
}