var cssClass = { '/':                 'idfront',
                 '/peptide/':         'idpeptide',
                 '/polyclonal/':      'idpolyclonal',
                 '/products/':        'idproducts',
                 '/FAQ/':             'idfaq',
                 '/monoclonal/':      'idmonoclonal',
                 '/purification/':    'idpurification',
                 '/services/':        'idservices',
                 '/protocols/':       'idprotocols',
                 '/IgY/':             'idigy',
                 '/distributors/':    'iddist',
                 '/contact/':         'idcontact'
               };

function mark_active_menu()
{

  var path = location.pathname;

  if (!cssClass[path]) {
    path = path.substring(0, path.lastIndexOf('/') + 1);
  }

/*  if (cssClass[path].indexOf('_') != -1) {
    document.getElementById(cssClass[path]).className =
        'choosenSubItem';
  } else*/ {
    document.getElementById(cssClass[path]).className =
        'choosenItem';
  }
}


function validateForm() {

         return names(document.forms.WebShopForm.Fornamn.value, document.forms.WebShopForm.Efternamn.value)
                && email(document.forms.WebShopForm.Epost.value)
                && (isValid(document.forms.WebShopForm.Ordernr.value, "1234567890ab", 1) && isValid(document.forms.WebShopForm.Attbetala.value, "1234567890,.", 2));
}
function isValid(str, ref, check){

         if(str.length==0){
            if (check == 2)
               alert("Please enter amount!");
            if (check == 1)
               alert("Please enter invoice number!");
            return false;
         }
         str = trimString(str);

         for (Count=0; Count<str.length; Count++){
              TempChar= str.substring (Count, Count+1);
              if (ref.indexOf (TempChar, 0)==-1){
                 if(check == 2){
                          alert("Invalid amount! No letters allowed!");
                          return false;
                 }
                 if(check == 1){
                          alert("Invalid invoice number!\n Allowed characters are '1234567890ab'");
                          return false
                 }


              }
         }

         return true;

}

function trimString (str) {
         str = this != window? this : str;
         str = str.replace(/^\s+/g, '').replace(/\s+$/g, '');
         return str;
}


function clearFields(){

         document.forms.WebShopForm.Fornamn.value = "";
         document.forms.WebShopForm.Efternamn.value = "";
         document.forms.WebShopForm.Epost.value = "";
         document.forms.WebShopForm.Attbetala.value = "";
         document.forms.WebShopForm.Ordernr.value = "";
}

function names(fname, lname){
         if(trimString(fname).length == 0 || trimString(lname).length == 0){
             alert("Please enter your first and last name!");
             return false;
         }
         else return true;
}

function email(mail){
         if(trimString(mail).length==0){
            alert("Please enter your e-mail address!");
            return false;
         }
         else return true;
}


/*function isValidInvoiceNum(inv){

         if(inv.length==0){
            alert("Invalid invoice number!");
            return false;
         }

         inv = trimString(inv);
         var refString = "1234567890ab";

         for (Count=0; Count<inv.length; Count++){
              TempChar= inv.substring (Count, Count+1);
              if (refString.indexOf (TempChar, 0)==-1){
                  alert("Invalid invoice number!");
                  return false;

              }
         }
         return true;
} */

