// Alfabet Features: Search Box Animation
$(document).ready(function(){
  if($("body.pc_Resources")[0]){
    alfabet.resources(); }
    
  if($("body.pc_EN, body.pc_DE")[0]){
    alfabet.homeP(); }
  /*if($("#mediaAssets")[0]){
    alfabet.mediaAssets(); }*/  
  if($("#mediaStage")[0]){
    mediaStage.run();  
  }
  
  alfabet.features();
  alfabet.system();
  $("h1").each(function(){
    if(this.innerHTML.match("alfabet")){
      var ht = this.innerHTML.replace("alfabet","<span class='lower'>alfabet</span>");
      this.innerHTML = ht;  
    }
    if(this.innerHTML.match("planningIT")){
      var ht = this.innerHTML.replace("planningIT","<span class='lower'>planning</span>IT");
      this.innerHTML = ht;  
    }
    //planningIT
  });
  $("h2").each(function(){
    if(this.innerHTML.match("alfabet's")){
      var ht = this.innerHTML.replace("alfabet's","<span class='lower'>alfabet's</span>");
      this.innerHTML = ht;  
    }
    if(this.innerHTML.match("alfabets")){
      var ht = this.innerHTML.replace("alfabets","<span class='lower'>alfabets</span>");
      this.innerHTML = ht;  
    }
    if(this.innerHTML.match("alfabet")){
      var ht = this.innerHTML.replace("alfabet","<span class='lower'>alfabet</span>");
      this.innerHTML = ht;  
    }
    if(this.innerHTML.match("planningIT's")){
      var ht = this.innerHTML.replace("planningIT's","<span class='lower'>planning</span>IT's");
      this.innerHTML = ht;  
    }
    if(this.innerHTML.match("planningIT")){
      var ht = this.innerHTML.replace("planningIT","<span class='lower'>planning</span>IT");
      this.innerHTML = ht;  
    }
    //planningIT
  });
});

var alfabet = {};
alfabet.rotateStat = 1;
alfabet.hIndex = 1;
alfabet.hstat = 0; //if slider function is running already or not

alfabet.homeP = function(){
  $("#hSlider").append("<a href='#' class='hprev'></a><a href='#' class='hnext'></a>");
  $("#hSlider .hprev, #hSlider .hnext").animate({"opacity":"1"},400);
  $("#hSlider .hprev").click(function(){
    alfabet.rotateStat = 0;
    alfabet.hSlide("0");return false;  
  });
  $("#hSlider .hnext").click(function(){
    alfabet.rotateStat = 0;
    alfabet.hSlide("1"); return false;          
  });
  if("body.lang_DE"){
    $(".sButtons .lnk2")[0].target="_blank";  
  }  
  var t = setTimeout("alfabet.hSlide()",30000);
    alfabet.hIndex = Math.round(Math.random()*$("#hSlider .panel").length); //()
  alfabet.hSlide();
}

alfabet.hSlide = function(change){
  if(alfabet.hstat == 0){
    alfabet.hstat = 1;
    switch(change){
      case "0":
        hnext = alfabet.hIndex-1;
        if(hnext<1){ hnext = $("#hSlider .panel").length;}
        
        $("#hSlider .panel").css({"z-index":"14"});
        $("#hSlider #hP"+alfabet.hIndex).css({"z-index":"15"});//"width":"0%",
        $("#hSlider #hP"+hnext).css({"z-index":"16"});
        $("#hSlider #hP"+hnext).css({"left":"0%","display":"block","opacity":"0"});
        $("#hSlider #hP"+hnext).animate({"width":"100%","opacity":"1"},600,function(){
          alfabet.hIndex = hnext;  
          alfabet.hstat = 0;
          alfabet.rotateStat = 0;
        });
        break
      case "1":
        hnext = alfabet.hIndex+1;
        if(hnext>$("#hSlider .panel").length){  hnext = 1;}
        
        $("#hSlider .panel").css({"z-index":"14"});
        $("#hSlider #hP"+alfabet.hIndex).css({"z-index":"15"});//"width":"0%",
        $("#hSlider #hP"+hnext).css({"z-index":"16"});
        $("#hSlider #hP"+hnext).css({"right":"0%","display":"block","opacity":"0"});
        $("#hSlider #hP"+hnext).animate({"width":"100%","opacity":"1"},600,function(){
          alfabet.hIndex = hnext;  
          alfabet.hstat = 0;
          alfabet.rotateStat = 0;
        });
        break;
      default:
        if(alfabet.rotateStat != 0){
          hnext = alfabet.hIndex+1;
          if(hnext>$("#hSlider .panel").length){  hnext = 1;}
          
          $("#hSlider .panel").css({"z-index":"14"});
          $("#hSlider #hP"+alfabet.hIndex).css({"z-index":"15"});//"width":"0%",
          $("#hSlider #hP"+hnext).css({"z-index":"16"});
          $("#hSlider #hP"+hnext).css({"right":"0%","display":"block","opacity":"0"});
          $("#hSlider #hP"+hnext).animate({"width":"100%","opacity":"1"},600,function(){
            alfabet.hIndex = hnext;  
            alfabet.hstat = 0;
          });
          var t = setTimeout("alfabet.hSlide()",30000);
        }else{
          alfabet.hstat = 0;  
        }
        break;
    }
  }  
}

alfabet.features = function(){
  var num = 2;
  $(".subnavcon").addClass("dyc"+Math.round(Math.random()*num));  
  $("strong").each(function(){ 
    if(this.innerHTML=="planningIT"){
      this.innerHTML = "<strong class='red'>planning<em>IT</em></strong>";  
    }
  });
  $("#CareersList").bind("change",function(){
    location.assign($("#CareersList option")[this.selectedIndex].value);
  });

  //Search Behaviour
  $("#sbox").bind("focus",function(){
    $("#search .bgBlack2").css({"background":"url(/media/images/sbox_black.gif) top right no-repeat"});
    $("#search .scontainer").animate({"opacity":"0"},200,function(){
      //Reset Styles
      $("#search .sboxCon").css({"opacity":"1","color":"#ffffff","background":"url(/media/images/sbox-expand_black.gif) 0 0 no-repeat"});
      $("#sbox").css({"color":"#ffffff","opacity":"1","z-index":"100","width":"230px"});
      $("#search .scontainer").css({"opacity":"1","width":"284px","background":"url(/media/images/sbox_black.gif) top right no-repeat"});  
    });
    $("#sbox, #search .sboxCon, #search .bgBlack").animate({"width":"230px"},200);    
    $("#header .mainNav").animate({"right":"190px"},200);  
  });
  $("#sbox").bind("blur",function(){ //#sbox
    //set Styles
    $("#search .scontainer").css({"opacity":"0","background":"url(/media/images/sbox.gif) top right no-repeat"});
    $("#search .sboxCon").css({"color":"#111111","background":"url(/media/images/sbox-expand.gif) 0 0 no-repeat"});
    
    $("#search .scontainer").animate({"opacity":"1"},200,function(){
      //Reset Styles
      $("#sbox").css({"color":"#111111"});
      $("#search .scontainer").css({"opacity":"1","background":"url(/media/images/sbox.gif) top right no-repeat"});
      $("#search .sboxCon").css({"opacity":"1","color":"#111111","background":"url(/media/images/sbox-expand.gif) 0 0 no-repeat"});      
    });
    $("#sbox, #search .bgBlack, #search .sboxCon").animate({"width":"176px"},400,function(){
      $("#search .bgBlack2").css({"background":"url(/media/images/sbox.gif) top right no-repeat"});                                
    });    
    $("#header .mainNav").animate({"right":"140px"},400);  

  });
  homePageSwitch();
  // Media Assets
  $(".assetList .photo a").bind("mouseenter",function(){
    $(this).children(".hover").css({opacity:0});
    $(this).children(".hover").animate({opacity:1},300);    
  });
  $(".assetList .photo a").bind("mouseleave",function(){
    $(this).children(".hover").css({opacity:1});
    $(this).children(".hover").animate({opacity:0},300);
  });
  
  imgBox();
  skBox();
  
  $(".assetList .item .tags").each(function(){
    var cnt = "";
    for(var i=0;i<this.innerHTML.split(",").length;i++){
      cnt+="<a href='?tag="+this.innerHTML.split(",")[i]+"'>"+this.innerHTML.split(",")[i]+"</a> ";
    }
    this.innerHTML = cnt;
  });
}

function homePageSwitch(){
  //183 //53
  var hl = "/";
  if($(".lang_DE")[0]){
    hl = "/de/";
  }
  var flashvars = { autostart:'false',controlbar:'over',homelink:hl};
  var params = { allowfullscreen:'false', allowscriptaccess:'always', wmode: 'transparent' };
  var attributes = { id:'hpflashSwitch_en', name:'player1' };
  swfobject.embedSWF("/media/flash/FlashAnim.swf",'hpflashSwitch_en','183','53','9.0.115','false', flashvars, params,attributes);
}

alfabet.resources = function()
{
  
  $("#browserLibrary a").each(function(){
    var value = this.href.substring(this.href.indexOf("?rt=")+4);
    var uvalue = location.href;
    if(uvalue.match(value)){
      $(this).addClass("active");
      this.href = "?";
    }
  });
   
  function urlDecode(a){
    a = a.replace(/%20/g," ");
    a = a.replace("%5","/");
    return a;
  }
  
  function urlEncode(str)
  {
    str = str.replace(" ","%20").replace(/\s/gi,"%20");
    str = str.replace("/","%5");
    return str;
  }
  function setVar(str,q){
    var a = "";
    if(str){
      if(str.indexOf(q+"=")>-1){
        a = str.substr(str.indexOf(q+"=")+(q.length+1));
        if(a.indexOf("&")>-1){
          a = a.substr(0,a.indexOf("&"));
        }
      }
    }return a;
   } 
   
  //function to reload page content without a refresh
  function newAssign(url){
    //Put up curtain
    $('#ResourcesContainer').animate({"opacity":"0"},200,function(){
      $("#hiddenResource").html(url);
      inpage = 1;
      $('#contentLoader').load(url+' #contentLoader',function(){
        $('#ResourcesContainer').animate({"opacity":"1"},200);
      });      
    });    
  }
  
  // function to add or remove the selected term to the query string
  function addWord(params,cvar){
    var a = "";
    if(cvar == ""){
      a = params[1];  
    }else{
      if(cvar.match(params[1])){
        a = cvar.replace(params[1],"");
        a = a.replace(",,",",").replace("=,","=");
      }else{
        a = cvar+","+params[1];
      }  
    }  
    return a;
  }
  
  //transform variables into parameter/value pairs
  function addSt(val,s,t){
    a = "";
    if(val!="" && val != ","){
      if(t==1){a += "&";}
      a += s+"="+val;
    }return a;
  }
}



alfabet.system = function(){
  var user = {};
  user.name = getCookie("userfname");
  user.ln = getCookie("userlname");
  user.sal = getCookie("usersal");
  user.email = getCookie("useremail");
  user.phone = getCookie("userphone");
  user.company = getCookie("usercompany");
  user.city = getCookie("usercity");
  user.state = getCookie("userstate");
  user.country = getCookie("usercountry");
  user.industry = getCookie("userindustry");
  user.role = getCookie("userrole");
  user.memberID = getCookie("useremail");
  user.status = "beta";
  user.site = "http://"+location.hostname;
  
  var sys ={};
  sys.action = "";
  var subject = "Contact Inquiry";
  
  //---------  -------------------------  -------------------------
  //---------  Page Specific pre-actions  -------------------------
  //---------  -------------------------  -------------------------

  //Downloads (Resources) ----------------------------------------------------------------------------
  if($("#dForm .form")[0]){
    if(!$(".registrationRequired")[0]){
      $(".form #Campaign_ID")[0].value="70120000000h86f";
    }
    if($("#wrap .details .registrationRequired")[0]){
      if(user.email != ""){//allow download
        if(location.href.match("downloadFile=true")){
          $(".lang_EN #wrap #downloadSection").prepend("<h4>Thank you. You may now download this resource.<br/><br/></h4>");
          $(".lang_DE #wrap #downloadSection").prepend("<h4>Vielen Dank. Sie k&ouml;nnen das Dokument nun herunterladen.<br/><br/></h4>");
          window.open($("#downloadSection .dButton")[0].href,"_blank"); 
        }
      }else{
        downloadRegistration();
      }  
    }else{}//allow download
  }
  
  //Contact -------------------------------------------------------------------------------------------
  if($("#contactForm")[0]){
    prePop(".form");  
  }
  
  //Generic (newsletters, exchange, webinar) ------------------------------------------------
  if($("#secondForm .form")[0]){
    prePop("#secondForm .form");
  }
  // 
  if( $("#secondForm .exchangeForm")[0] ){
    $("#secondForm").css({"height":"1140"});
  }
  // 
  if( $("#secondForm .training2011")[0] ){
    $("#secondForm").css({"height":"680"});
  }
  //
  if( $("#secondForm .training2012")[0] ){
    $("#secondForm").css({"height":"800"});
  }
  // 
  if( $("#secondForm .BITMhouston")[0] ){
    $("#secondForm").css({"height":"530"});
  }
  // 
  if( $("#secondForm .leaderShipForums")[0] ){
    $("#secondForm").css({"height":"630"});
  }
  
    
  //Thank You ------------------------------------------------------------------------------------------
  if(location.href.match("sf=1")){
    if($("#contactForm")[0]){
      
      $("#contactForm").css({"display":"none"});
      if($("body")[0].className.match("lang_DE")){
        $("#contactForm").after("<div><h2>Vielen dank</h2><h4>Ihre Mitteilung wurde verschickt.</h4></div>");
      }else{
        $("#contactForm").after("<div><h2>Thank You</h2><h4>Your message has been sent.</h4></div>");
      }
    }
    if($("#secondForm .form")[0]){
      $("#secondForm").css({"height":"150px"});
      $("#secondForm div").css({"display":"none"});
      $("#secondForm h2").css({"display":"none"});
      if($("body")[0].className.match("lang_DE")){
        $("#secondForm").append("<h2>Vielen Dank f&uuml;r Ihre Anmeldung.</h2><h4>In K&uuml;rze werden Sie eine Best&auml;tigungsnachricht erhalten.</h4>");
      }else{
        $("#secondForm").append("<h2>Thank You for registering.</h2><h4>You should receive a confirmation email promptly.</h4>");
      }
      //prePop("#secondForm .form");
    }
  }
  
  
  //DO THIS ON PAGE LOAD ----------------------------------------------------------------------------
  if($(".form")[0]){
    $(".form").append("<input type='hidden' name='subj' value='"+subject+"' />");
    if($(".form")[0].retURL){
      if($("#downloadSection")[0]){
        $(".form")[0].retURL.value = location.href+"?downloadFile=true";
        
      }else if($("body")[0].className.match("lang_DE")){
        $(".form")[0].retURL.value = location.href+"?sf=1";// "http://"+location.hostname+"/de/thank-you.aspx";
      }else{
        $(".form")[0].retURL.value = location.href+"?sf=1";// "http://"+location.hostname+"/en/thank-you.aspx";
      }
    }
    if($("#secondForm .form")[0]){
      if($("#secondForm .form")[0].retURL){  
        if($("#downloadSection")[0]){
          $("#secondForm .form")[0].retURL.value = location.href+"?downloadFile=true";
        }else if($("body")[0].className.match("lang_DE")){
          $("#secondForm .form")[0].retURL.value = location.href+"?sf=1";// "http://"+location.hostname+"/de/thank-you.aspx";
        }else{
          $("#secondForm .form")[0].retURL.value = location.href+"?sf=1";// "http://"+location.hostname+"/en/thank-you.aspx";
        }
      }
    }
  }
    
  //Event Listeners -------------------------------------------------------=-------------------
  $(".contactpage #cSubmit input").click(function(){//alert("if statement with validation function");
    if(  validateSFDC(".form")==true){
      $(".form")[0].submit();  //this.form.submit();  
    }else{}  
    return false;  
  });
  $("#secondForm .form #cSubmit input").unbind();
  $("#secondForm .form #cSubmit input").click(function(){
    if(  validateSFDC("#secondForm .form")==true){
      $("#secondForm form")[0].submit();  //this.form.submit();  
    }else{}  
    return false;
  //Special PlanningIT form (eXchange 2011)
  });
  
  if($("#secondForm .form")[0]){
    
    $("#secondForm .exchangeForm .form #cSubmit input").unbind();
    $("#secondForm .exchangeForm .form #cSubmit input").click(function(){
      if(  validateSFDC("#secondForm .exchangeForm .form")==true){
        var a ="";
        a+= "masterClassAM="+$("#secondForm form #masterClasses")[0].value+",";
        a+= "masterClassPM="+$("#secondForm form #masterClasses2")[0].value+",";
        a+= "getTogether="+getRadioButtonValue($("#secondForm form")[0].getTogetherConfirm)+",";
        a+= "exchangeConfirm="+getRadioButtonValue($("#secondForm form")[0].exchangeConfirm)+",";
        a+= "awardsDinnerConfirm="+getRadioButtonValue($("#secondForm form")[0].awardsDinnerConfirm)+",";
        a+= "staff1-on-1="+$("#secondForm form #staff1on1")[0].value+",";
        a+= "comments="+$("#secondForm form #comments")[0].value+",";
        $("#secondForm form #description")[0].value = a;
        $("#secondForm .exchangeForm form")[0].submit();  //this.form.submit();  
      }else{}  
      return false;
    });
    
    if( $("#secondForm .BITMhouston")[0]){
      $("#secondForm .BITMhouston .form #cSubmit input").unbind();
      $("#secondForm .BITMhouston .form #cSubmit input").click(function(){
        if(  validateSFDC("#secondForm .BITMhouston .form")==true){
          var a =""; 
          a+= "attendingBaseballGame="+$("#secondForm form #attending")[0].value+",";
          a+= "Comments="+$("#secondForm form #comments")[0].value+",";
          $("#secondForm form #description")[0].value = a;
          $("#secondForm .BITMhouston form")[0].submit();
        }
      });
    }
    
    if( $("#secondForm .training2011")[0]){
      $("#secondForm .training2011 .form #cSubmit input").unbind();
      $("#secondForm .training2011 .form #cSubmit input").click(function(){
        if(  validateSFDC("#secondForm .training2011 .form")==true){
          var a ="";
          a+= "aDIF="+retCheckedNum($("#secondForm form .traningInput")[0])+",";
          a+= "ApplicationPortfolioGovernance="+retCheckedNum($("#secondForm form .traningInput")[1])+",";
          a+= "ApplicationRoadmapping="+retCheckedNum($("#secondForm form .traningInput")[2])+",";
          a+= "eXpandAdvanced="+retCheckedNum($("#secondForm form .traningInput")[3])+",";
          a+= "eXpandBasics="+retCheckedNum($("#secondForm form .traningInput")[4])+",";
          a+= "planningITAdministration="+retCheckedNum($("#secondForm form .traningInput")[5])+",";
          a+= "Reports="+retCheckedNum($("#secondForm form .traningInput")[6])+",";
          a+= "TechnologyPortfolioGovernance="+retCheckedNum($("#secondForm form .traningInput")[7])+",";
          
          $("#secondForm form .descField")[0].value = a;
          $("#secondForm .training2011 form")[0].submit();  //this.form.submit();    
        }else{}  
        return false;
      });
    }
    
if( $("#secondForm .training2012")[0]){
      $("#secondForm .training2012 .form #cSubmit input").unbind();
      $("#secondForm .training2012 .form #cSubmit input").click(function(){
        if(  validateSFDC("#secondForm .training2012 .form")==true){
          var a ="";
          a+= "ApplicationPortfolioGovernance="+retCheckedNum($("#secondForm form .traningInput")[0])+",";
          a+= "ITRoadmapping="+retCheckedNum($("#secondForm form .traningInput")[1])+",";
          a+= "TechnicalPortfolioGovernance="+retCheckedNum($("#secondForm form .traningInput")[2])+",";
          a+= "BusinessRelationshipManagement="+retCheckedNum($("#secondForm form .traningInput")[3])+",";
          a+= "ITPlanning="+retCheckedNum($("#secondForm form .traningInput")[4])+",";
          a+= "eXpandBasic="+retCheckedNum($("#secondForm form .traningInput")[5])+",";
          a+= "ReportingAdvanced="+retCheckedNum($("#secondForm form .traningInput")[6])+",";
          a+= "ReportingBasic="+retCheckedNum($("#secondForm form .traningInput")[7])+",";
          a+= "ReportingAdvanced="+retCheckedNum($("#secondForm form .traningInput")[8])+",";
          a+= "Administration="+retCheckedNum($("#secondForm form .traningInput")[9])+",";
          a+= "alfabetDataIntegrationFramework="+retCheckedNum($("#secondForm form .traningInput")[10])+",";
          
          $("#secondForm form .descField")[0].value = a;
          $("#secondForm .training2012 form")[0].submit();  //this.form.submit();    
        }else{}  
        return false;
      });
    }    
    
    if( $("#secondForm .leaderShipForums")[0]){
      $("#secondForm .leaderShipForums .form #cSubmit input").unbind();
      $("#secondForm .leaderShipForums .form #cSubmit input").click(function(){
        if(  validateSFDC("#secondForm .leaderShipForums .form")==true){
          var a ="";
          a+= "Workshop="+$("#secondForm form #workshop")[0].value+",";
          a+= "Comments="+$("#secondForm form #comments")[0].value+",";
          
          $("#secondForm form #description")[0].value = a;
          $("#secondForm .leaderShipForums form")[0].submit();  //this.form.submit();    
        }else{}  
        return false;
      });
    }
  }
  
  ////////// DOWNLOAD FUNCTIONALITY ////////// 
  function downloadRegistration(){//display form
    $("#dForm .form #description")[0].value = "Registered Download - "+$(".details h2")[0].innerHTML;
    $("#dForm .form .comments").remove();
    $("#uForumMasterForm").after("<div id='secondForm' class='downloadsForm'><h3>You need to regsiter through the form below in order to download this resource</h3>"+$("#dForm")[0].innerHTML+"</div>");
    $("#downloadSection .dButton").addClass("disable");
    $("#secondForm .hide").removeClass("hide");
    if($("#secondForm .form")[0].retURL.value){
      $("#secondForm .form")[0].retURL.value = location.href+"?downloadFile=true";
      $("#secondForm .form .comments").remove();
    }
    if( $("#secondForm .form #description")[0]){
      $("#secondForm .form #description")[0].value = "Registration for Download - "+$(".details h2")[0].innerHTML;}
    $("#dForm.hide").remove();//prevent download  
  }

  
  $("#downloadSection .dButton").click(function(){
    if($(".registrationRequired")[0]){
      sendBack("Registered Download");
    }else{
      $(".form #Campaign_ID")[0].value="70120000000h86f";
      sendBack("Free Download");
    }
    return true;
  });
  $("#downloadSection .dButton.disable").unbind();
  $("#downloadSection .dButton.disable").click(function(){
    return false;
  });
  
  //Pre-populate common fields
  function prePop(fv){
    $(fv+" #first_name")[0].value = user.name;
    $(fv+" #last_name")[0].value = user.ln;
    $(fv+" #salutation")[0].value = user.sal;
    $(fv+" #email")[0].value = user.email;
    $(fv+" #phone")[0].value = user.phone;
    $(fv+" #company")[0].value = user.company;
    $(fv+" #city")[0].value = user.city;
    $(fv+" #state")[0].value = user.state;
    $(fv+" #country")[0].value = user.country;
    $(fv+" #industry")[0].value = user.industry;
    if($(fv+" #role")[0]){
      $(fv+" #role")[0].value = user.role;
    }
  }
  
  //Validate forms ALL FINAL
  function validateSFDC(fn){
    var a = true;
    $(fn+" .emessage").remove();
    $(fn+" .gti").removeClass("error");
    if(validationHelper(fn+" #email",'email',"useremail")==false){ a = false;}
    if(validationHelper(fn+" #country",'sel',"usercountry")==false){ a = false;}
    if(validationHelper(fn+" #industry",'sel',"userindustry")==false){ a = false;}
    if(validationHelper(fn+" #role",'sel',"userrole")==false){ a = false;}
    
    setCookie("userfname",$(fn+" #first_name")[0].value,60);  
    setCookie("userlname",$(fn+" #last_name")[0].value,60);  
    setCookie("usercity",$(fn+" #city")[0].value,60);  
    setCookie("usersal",$(fn+" #salutation")[0].value,60);    
    setCookie("userphone",$(fn+" #phone")[0].value,60);    
    setCookie("userstate",$(fn+" #state")[0].value,60);    
    setCookie("usercompany",$(fn+" #company")[0].value,60);    
    
    if(a==false){
      var content = "<p><span class='error emessage'>Please note that your registration can only be submitted once all required fields are completed.</span></p>";  
      if($("body")[0].className.match("lang_DE")){
         content = "<p><span class='error emessage'>Die Anmeldung kann nur erfolgen, wenn alle Pflichtfelder ausgef&uuml;llt sind.</span></p>"; 
      }
      if($("#contactForm")[0]){
        content = "<p><span class='error emessage'>Please note that your information can only be submitted once all required fields are completed.</span></p>"; 
        if($("body")[0].className.match("lang_DE")){
           content = "<p><span class='error emessage'>Ihre Mitteilung kann nur &uuml;bermittelt werden, wenn alle Pflichtfelder ausgef&uuml;llt sind.</span></p>"; 
        }
      }
      //____________________________________
      /*if($(fn+" h2")[0]){
        $(fn+" h2").after(content);
      }else{
        $(fn).prepend(content);
      }*/
      $("#cSubmit").before(content);
      //$(fn+" .error")[0].focus();
    }
    
    return a;
  }

  //Check input field for errors, if valid, save to cookie (cvalue). types: "email".. other
  function validationHelper(loc,type,cvalue){
    var a = true;
    if($(loc)[0]){
      switch(type){
        case "email":
          if($(loc)[0].value == "" || $(loc)[0].value == null || $(loc)[0].value.indexOf("@") < 0 || $(loc)[0].value.indexOf(".") < 0){
            a = false;
            $(loc).addClass("error");
          }else{
            setCookie(cvalue,$(loc)[0].value,60);
          }
          break;
        default:
          if($(loc)[0].value == "" || $(loc)[0].value == "_" || $(loc)[0].value == null){
            a = false;  
            $(loc).addClass("error");
          }else{
            setCookie(cvalue,$(loc)[0].value,60);
          }
          break;
      }
    }else { a= false;}
    return a;
  }
  
  function retCheckedNum(obj){
    if( $(obj).children("input[type=checkbox]")[0].checked==false){
      if( $(obj).children(".smBox")[0].value!=""){
        return $(obj).children(".smBox")[0].value;
      }else{
        return 0;
      }
    }else{
      if( $(obj).children(".smBox")[0].value!=""){
        return $(obj).children(".smBox")[0].value;
      }else{
        return 1;  
      }
    }
    /*if( $(obj).children(".smBox")[0].value!=""){
        return $(obj).children(".smBox")[0].value;
      }else{
        return 1;  
      }*/
  }
  
  function getRadioButtonValue(group){
    var a = "";
    if(getSelectedRadio(group)>-1){
      var b=getSelectedRadio(group);
      a = group[b].value;
    }
    return a;
  }
  
  function getSelectedRadio(buttonGroup) {// returns the array number of the selected radio button or -1 if no button is selected
     if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
       if (buttonGroup[i].checked) {
        return i
       }
      }
     } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
     }// if we get to this point, no radio button is selected
     return -1;
  } 
  
  function sendBack(dPrefix){/*  subj: subject}  */  
    var pdata="fReq=aCC3S5&";
    pdata+="oid="+"00D20000000N7IV"+"&";
    pdata+="retURL="+"http://"+"&";
    pdata+="Campaign_ID="+$(".form #Campaign_ID")[0].value+"&";
    pdata+="first_name="+user.name+"&";
    pdata+="last_name="+user.ln+"&";
    pdata+="company="+user.company+"&";
    pdata+="email="+user.email+"&";
    pdata+="city="+user.city+"&";
    pdata+="state="+user.state+"&";
    pdata+="country="+user.country+"&";
    pdata+="phone="+user.phone+"&";
    pdata+="00N20000002YqZl="+user.role+"&";
    pdata+="00N20000002YdkU="+user.role+"&";
    pdata+="industry="+user.industry+"&";
    pdata+="description="+dPrefix+" - "+$(".details h2")[0].innerHTML;
    
    var url = "/process/post.aspx";
    //url = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8?callback=?";
    $.post(url, pdata, function(data){  });
  }
}


/* NO NAMESPACES */
function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/");
}
