function mailingListClick(error_msg) {
  var emailExpr = /^.+\@.+\..+$/;
  if (isblank(document.forms['mailForm'].elements['email'].value) || !emailExpr.test(document.forms['mailForm'].elements['email'].value) ){
    alert(error_msg);
    document.forms['mailForm'].elements['email'].focus();
    return false;
  }else{    
    var url = document.forms['mailForm'].action +'/?email=' + document.forms['mailForm'].email.value;
    window.open(url, 'MailForm', 'width=400,height=470,menubar=0,toolbar=0,resizable=0,scrollbars=0,status=0');
  }
}

function checkMailingForm(error_msg_1, error_msg_2, error_msg_3) {
  if( isblank(document.forms['mailingForm'].elements['firstName'].value) ) {
    alert(error_msg_1);
    document.forms['mailingForm'].elements['firstName'].focus();
    return false;
  }
  if( isblank(document.forms['mailingForm'].elements['lastName'].value) ) {
    alert(error_msg_2);
    document.forms['mailingForm'].elements['lastName'].focus();
    return false;
  }
  var emailExpr = /^.+\@.+\..+$/;
  if (isblank(document.forms['mailingForm'].elements['email'].value) || !emailExpr.test(document.forms['mailingForm'].elements['email'].value) ){
    alert(error_msg_3);
    document.forms['mailingForm'].elements['email'].focus();
    return false;
  }
  document.forms['mailingForm'].submit();
}

function isblank(s){
  for (var i=0 ; i < s.length; i++){
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;	
  }	
  return true;
}

function radioClick(name, id) {
  var previous;
  eval('previous = ' + name + '_on_id;');
  if (previous != id) {
    document.getElementById(name + previous).className = 'radioOff';
    document.getElementById(name + id).className = 'radioOn';
    eval( name + '_on_id = ' + id +';');
    document.getElementById(name).value = document.getElementById(name+id+'Value').innerHTML;
  }
}

function jobDescBlur(){
  if (document.jobForm.expirienceDesc)
  {
    var msg,mainMsg;
    msg="";mainMsg="";
    msg=document.jobForm.expirienceDesc.value;
    mainMsg=msg.substring(0,140);
    document.jobForm.expirienceDesc.value=mainMsg;
  }
}

function GetXmlHttpObject(){ 
  var objXMLHttp=null
  if (window.XMLHttpRequest)
  {     
    objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return objXMLHttp
}

function checkLoginForm(error_message) {
  if( isblank(document.forms['loginForm'].elements['username'].value) || isblank(document.forms['loginForm'].elements['password'].value)) {
    alert(error_message);    
    return false;
  }
  document.forms['loginForm'].submit();
}

function forgotForm() {
  if (document.getElementById('forgot').style.display != 'block') {
    document.getElementById('forgot').style.display = 'block';
  }
  else if (document.getElementById('forgot').style.display != 'none') {
    document.getElementById('forgot').style.display = 'none';
  }
}

function checkForgotForm(error_msg) {
  var emailExpr = /^.+\@.+\..+$/;
  if (isblank(document.forms['forgotForm'].elements['email'].value) || !emailExpr.test(document.forms['forgotForm'].elements['email'].value) ){
    alert(error_msg);
    document.forms['forgotForm'].elements['email'].focus();
    return false;
  }
  document.forms['forgotForm'].submit();
}

function registerForm() {  
  if (document.getElementById('register').style.display != 'block') {
    document.getElementById('register').style.display = 'block';
  }
  else if (document.getElementById('register').style.display != 'none') {
    document.getElementById('register').style.display = 'none';
  }
}

function checkRegisterForm(error_msg_1, error_msg_2, error_msg_3, error_msg_4, error_msg_5, error_msg_6, error_msg_7) {
  if( isblank(document.forms['registerForm'].elements['firstName'].value) ) {
    alert(error_msg_1);
    document.forms['registerForm'].elements['firstName'].focus();    
    return false;
  }
  if( isblank(document.forms['registerForm'].elements['lastName'].value) ) {
    alert(error_msg_2);
    document.forms['registerForm'].elements['lastName'].focus();    
    return false;
  }
  var emailExpr = /^.+\@.+\..+$/;
  if (isblank(document.forms['registerForm'].elements['email'].value) || !emailExpr.test(document.forms['registerForm'].elements['email'].value) ){
    alert(error_msg_3);
    document.forms['registerForm'].elements['email'].focus();
    return false;
  }
  if( isblank(document.forms['registerForm'].elements['username'].value) ) {
    alert(error_msg_4);
    document.forms['registerForm'].elements['username'].focus();    
    return false;
  }else if (document.forms['registerForm'].elements['username'].value.length < 6) {
    alert(error_msg_7);
    document.forms['registerForm'].elements['username'].focus();    
    return false;
  }
  if( isblank(document.forms['registerForm'].elements['password'].value) ) {
    alert(error_msg_5);
    document.forms['registerForm'].elements['password'].focus();    
    return false;
  }else if (document.forms['registerForm'].elements['password'].value.length < 6) {
    alert(error_msg_7);
    document.forms['registerForm'].elements['password'].focus();    
    return false;
  }else if(document.forms['registerForm'].elements['password'].value != document.forms['registerForm'].elements['confirm'].value){
    alert(error_msg_6);
    document.forms['registerForm'].elements['password'].focus();    
    return false;
  }
    
  document.forms['registerForm'].submit();
}

function bookmark(a_title, a_url){
    var title = a_title;
    var url = a_url;

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }

    else if( document.all ) window.external.AddFavorite( url, title);
}

function sortProducts(column, type) 
{
  var order = orderList[column];
  if(order=='asc') {
    productList.sort(sortByColumnAsc(column,type));
  }else if(order=='desc') {
    productList.sort(sortByColumnDesc(column,type));
  }
  
  if(productList.length>0) {
    document.getElementById('pr').innerHTML="";
    x = productList[0];
    xLength=x.length;
      var inner = ""; 
    for(i=0;i<productList.length;i++) {
      inner += productList[i][xLength-1];
    }
      document.getElementById('pr').innerHTML = inner;
      
 }
 if(order=='asc') {
 
      if (previous_sorted != column)
        document.getElementById('sorted'+previous_sorted).className = 'notSorted'; 
        
      document.getElementById('sorted'+column).className = 'sortedAsc';        
  orderList[column]='desc';
 }else if(order=='desc') {
 
      if (previous_sorted != column)
        document.getElementById('sorted'+previous_sorted).className = 'notSorted'; 
        
      document.getElementById('sorted'+column).className = 'sortedDesc';
  orderList[column]='asc';
 }
 
   previous_sorted = column;
}

function sortByColumnAsc(c,t) {

  if (t == "Number") {
    return function (a, b) {
      var x = a[c].toLowerCase();
      var y = b[c].toLowerCase();
      if(x=='') {
        x=0;
      }
      if(y=='') {
        y=0;
      }
      return Math.ceil(parseFloat(x)-parseFloat(y));
    }
  }else {
    return function (a, b) {
      var x = a[c].toLowerCase();
      var y = b[c].toLowerCase();
      return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }
  }
}

function sortByColumnDesc(c,t) {
  if (t == "Number") {
    return function (a, b) {
      var x = a[c].toLowerCase();
      var y = b[c].toLowerCase();
      if(x=='') {
        x=0;
      }
      if(y=='') {
        y=0;
      }
      return Math.ceil(parseFloat(y)-parseFloat(x));
    }
  }else {
    return function (a, b) {
      var x = a[c].toLowerCase();
      var y = b[c].toLowerCase();
      return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    }
  }
}
function langArrowClick(direction) { 
  var left = parseInt(document.getElementById("langsContainer").style.left);
  var frame_width = parseInt(document.getElementById("langFrame").style.width);
  var container_width = parseInt(document.getElementById("langsContainer").style.width); 
  var entry_width = parseInt(document.getElementById("selectedLang").style.width);  
  if (direction == 'right') {   
    if (Math.abs(left) < container_width - frame_width)//othervise it would not be visible    
      left -= entry_width;
  }else{
    if (left < 0)//othervise it would not be visible
      left += entry_width;
  }
        
  document.getElementById("langsContainer").style.left = left;
}