﻿function globallayer(){
    var od=$("gbalayer");
    if(od)return od;
    od=document.createElement("div");
    od.setAttribute("id","gbalayer");
    od.style.width=document.documentElement.offsetWidth+"px";
    od.style.height=document.documentElement.offsetHeight+"px";
    document.body.appendChild(od);
    return od;
}
function globalwaiting(){
    var oi=$("gbawaiting");
    if(oi)return oi;
    var oi=document.createElement("img");
    oi.setAttribute("id","gbawaiting");
    oi.setAttribute("src","/images/waiting.gif");
    oi.style.position="absolute";
    oi.style.zIndex=10;
    oi.style.top=(document.documentElement.offsetHeight+document.documentElement.scrollTop)/2+"px";
    oi.style.left=(document.documentElement.offsetWidth+document.documentElement.scrollLeft)/2+"px";
    document.body.appendChild(oi);
    return oi;
}
function globalform(w,t,c,f){
    var bx=$("formlayer");
    if(bx)return bx;

    bx=document.createElement("div");
    bx.setAttribute("id","formlayer");
    bx.className="layerbox";
    bx.style.marginLeft=-(w/2)+"px";
    bx.style.width=w+"px";
    bx.style.top=(document.documentElement.scrollTop+150)+"px";
    document.body.appendChild(bx);
    
    var tx=document.createElement("div");
    tx.className="t";
    bx.appendChild(tx);
    var sx=document.createElement("span");
    sx.innerHTML=t;
    tx.appendChild(sx);
    var ix=document.createElement("img");
    ix.setAttribute("src","/images/closethis.jpg");
    ix.onclick=function(){
        document.body.removeChild(bx);
        var od=$("gbalayer");
        if(od)document.body.removeChild(od);
    }
    tx.appendChild(ix);
    var se=document.createElement("div");
    se.style.padding=0;
    se.style.clear="both";
    tx.appendChild(se);
    
    var cx=document.createElement("div");
    cx.className="c";
    cx.innerHTML=c;
    bx.appendChild(cx);
    
    var nx=document.createElement("div");
    nx.className="n";
    bx.appendChild(nx);
    var bn=document.createElement("input");
    bn.setAttribute("type","button");
    bn.setAttribute("value","Submit");
    bn.onclick=f;
    nx.appendChild(bn);
    
    return bx;
}
function closelayer(){
    var f=$("formlayer");
    if(f)document.body.removeChild(f);
    
    var g=$("gbalayer");
    if(g)document.body.removeChild(g);
}

function learnmore(o,b){
    var p=o.parentNode.parentNode;
    if(b){
        var c=nextNode(p);
        if(c.style.display=="block"){
            c.style.display="none";
            o.innerHTML="Learn more";
        }
        else{
            c.style.display="block";
            o.innerHTML="Hide";
           
        }
    }
    else
    {
     p.style.display="none";
    }
}


function userlogin(){
    var title="User Login";
    var sb=new stringBuilder();
    sb.append("<label class='lblne'>Email:");
    sb.append("<input type='text' id='inpemail' class='tbxCss' style='margin-left:26px'/>");
    sb.append("<font color='red'>*</font></label>");
    sb.append("<label class='lblne'>Password: ");
    sb.append("<input type='password' id='inppwd' class='tbxCss'/>");
    sb.append("<font color='red'>*</font></label>");
    sb.appendFormat("<label class='lblfp'><a href='https://www.{0}/forgot-password.aspx'>Password forgotten?</a></label>",DOMAINNAME)
    globallayer();
    globalform(250,title,sb.toString(),
        function(){
            var ex=$("inpemail").value,px=$("inppwd").value;
            if(!ex){alert("email is not null.");return false;}
            if(!px){alert("password is not null.");return false;}
            if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(ex))
            {alert("email format is wrong.");return false;}
            
            var ob=gbaEvent.$get().element;
            ob.disabled=true;
            _userauthen(ex+"<|>"+px,ob);
        });
}
function userlogout(){
//    if(!confirm("Are you sure you logout?"))return false;
    _userauthen("",null);
}
function userauthenasync(rs,oc){
    if(rs)switch(rs.substr(0,2)){
        case "61":
        case "11":location.href='/';break;
        default:alert(rs.substring(2,rs.length));break;
    }
    if(oc)oc.disabled=false;
}

function joinusemail(){
    var ib=gbaEvent.$get().element;
    var ix=prevNode(ib);
    if(!ix.value)
    {
        //alert("email is not null.");
        jQuery(".cls_join_tips").html(requiredMsg);
        jQuery(".cls_join_tips").show();
        return false;
    }
    if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(ix.value))
    {
        //alert("email format is wrong.");
        jQuery(".cls_join_tips").html(invalidEmailMsg);
        jQuery(".cls_join_tips").show();
        return false;
    }
    jQuery(".cls_join_tips").hide();
    
   ib.src="/images/waiting.gif";
   _joinusemail(ix.value,ib);
}
function joinusemailasync(rs,oc){
    oc.src="/images/go.jpg";
    if(rs)
    {
        //alert(rs.substring(2,rs.length));
        jQuery(".cls_join_tips").html(rs.substring(2,rs.length));
        jQuery(".cls_join_tips").show();
    }
}

 function show_words(){
      var height_=jQuery(".div_height").height();
      if(height_=='115'){
        jQuery("#div_height1").css("height","227px");
        jQuery("#div_height2").css("height","216px");
        jQuery("#div_height3").css("height","225px");
        jQuery("#div_height4").css("height","206px");
        jQuery("#div_height5").css("height","317px");
        jQuery("#div_height6").css("height","278px");
        jQuery("#div_height7").css("height","300px");
        jQuery("#div_height8").css("height","242px");
        jQuery("#div_height9").css("height","224px");
        jQuery("#div_height10").css("height","223px");
        jQuery("#div_height11").css("height","260px");
        jQuery("#div_height12").css("height","134px");
        jQuery("#div_height13").css("height","202px");
        jQuery("#div_height14").css("height","163px");
        jQuery("#div_height15").css("height","308px");
        jQuery("#learn_letter").hide();
        jQuery("#learn_letter2").show();
        jQuery(".all_div").show();
      }
      else {
      jQuery(".div_height").css("height","115px");
      jQuery("#learn_letter").show();
      jQuery("#learn_letter2").hide();
      jQuery(".all_div").hide();
      }
      
      var letter_=jQuery("#learn_letter").html();
      if(letter_=='Learn More'){
      jQuery("#learn_letter").html('Hide');
      }
      else if(letter_=='Hide'){
      jQuery("#learn_letter").html('Learn More');
      }
    }
    
    function product_show()
    {
        jQuery("#div_content").show();
        jQuery("#span_learnmore").hide();
    }
    
    function product_hide()
    {
        jQuery("#div_content").hide();
        jQuery("#span_learnmore").show();
    }
