/*
 * This is the main functions for the iMetrik Solutions corporate website
 * Copyrights iMetrik Solutions - 2010
 * 
 * @author fprevost
 */

changeLanguage = function(selectId){
  var sel = document.getElementById(selectId);
  var url = sel.options[sel.selectedIndex].value;
  document.location.href = url;
}

ajaxUpdate = function(divId, url){
  new Ajax.Updater(divId, url, {method:'get', evalScripts: true});
}

wpAjaxUpdate = function(divId, lang){
  ajaxUpdate(divId, lang + "/finance/wpdwl.html");
}

inWpAjaxUpdate = function(divId, lang){
  ajaxUpdate(divId, lang + "/insurance/inwpdwl.html");
}

setCookie = function(cName, cValue, expireDays){

  var exdate = new Date();
      exdate.setDate(exdate.getDate() + expireDays);

  document.cookie = cName + "=" + escape(cValue) + ";expires=" + exdate.toUTCString();
}

getCookie = function(cName){

  if(document.cookie.length > 0){
    var cStart = document.cookie.indexOf(cName + "=");
    if (cStart != -1){
      cStart = cStart + cName.length + 1;
      var cEnd = document.cookie.indexOf(";", cStart);
      if (cEnd == -1){
        cEnd = document.cookie.length;
      }
    return unescape(document.cookie.substring(cStart,cEnd));
    }
  }
return "";
}

checkCookie = function(cName, expectedValue){

  var c = getCookie(cName);

  if (c != null && c != ""){
    if(c == expectedValue){
      return true;
    }
  }
  return false;
}

checkWpCookie = function(){
  return checkCookie("WPDWL", "true");
}

checkInWpCookie = function(){
  return checkCookie("INWPDWL", "true");
}

logout = function(dUrl){
  //Thu, 01-Jan-70 00:00:01 GMT
  document.cookie = "udSessionId=null; path=/portal; expires=-1;";
  document.location.href=dUrl+"/partnerzone/overview.html";
}
