﻿var xmlHttp;
var xmlDoc=null;
var jpFfamily = "MS UI Gothic, MS PGothic, Osaka";
var nonjpFfamily = "Verdana, Arial, Helvetica, sans-serif;"
var HtmlTagList = ["HeaderDiv", "Menu_Bar", "Banner_Head", "plan_rate", "plan_discount", "plan_details_link", "descr", "links", "content", "getnow1", "getnow2", "footerNotes"];
function signUp(SignupAttrib)
{
    var data = "<SignupAttrib>";
    data += SignupAttrib;
    data += "</SignupAttrib>";
    setCookie(productOn, menuOn, "0");
    var url=getUpdatedUrl("Signup.aspx");
    NavigateToUrl(url,"POST",data,"","");
}

function NavigateToUrl(url,verb,data,soapAction,callbackmethod)
{
    xmlHttp=GetXmlHttpObject();
    showWait();
    if(xmlHttp==null)
    {
        alert("Your browser does not support Java Script!\n\rPlease enable JavaScript and try again");
        return;
    }
    try
    {
        if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        {
            xmlHttp.open(verb,url,false);
        }
        else
        {
            if(callbackmethod != null)
            {
               xmlHttp.onreadystatechange=callbackmethod;
            }
            xmlHttp.open(verb,url,true);
        }
    }catch(e1){}
    try
    {
        if(data == null || data == "")
        {
            xmlHttp.send(null);
        }
        else
        {
            if(soapAction!=null||soapAction!="")
            {
                xmlHttp.setRequestHeader("SOAPAction",soapAction);
            }
	    xmlHttp.setRequestHeader("Content-Type","text/xml");
	    xmlHttp.setRequestHeader("Content-Length",data.length);
            xmlHttp.send(data);
        }
    }
    catch(e){}
}

function fetchPage(url,verb,data,soapAction,elemId)
{
    try
    {    
        NavigateToUrl(url,verb, data, soapAction, stateChanged);
        if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        {
            setHTML();
        }
    }
    catch(e)
    {}
}
function setHTMLById(elmId,HTMValue)
{
    var objHtm=document.getElementById(elmId);
    if(objHtm!=null)
    {
        objHtm.innerHTML=HTMValue;
    }
}
function setHtmlBkImg(elmId,HTMValue)
{
    try
    {
        var objHtm=document.getElementById(elmId);
        if(objHtm!=null)
        {
            objHtm.style.backgroundImage='url('+HTMValue+')';
        }
    }
    catch(e)
    {
    }
}
function setHTML()
{
    var response=xmlHttp.responseText;
    var titleVal=getNodeValue(response,"PageTitle");
    if(titleVal!=null&&titleVal!="")
        document.title=titleVal;
    var prodOn=getNodeValue(response,"ProductOn");
    if(prodOn != "")
    {
        ProductButtonClick(productOn,prodOn);
        productOn=prodOn;
    }
    var signupLnk = getNodeValue(response,"SignupLink");
    if(signupLnk != "")
    {
        try
        {
        document.getElementById("getnow1").href = signupLnk;
        document.getElementById("getnow2").href = signupLnk;
        }catch(e){}
    }
    setHtmlBkImg("banner",getNodeValue(response,"BannerImage"));
    setHtmlBkImg("logo",getNodeValue(response,"LogoImage"));
    setHTMLById("Banner_Head",getNodeValue(response,"BannerHeading"));
    setHTMLById("plan_details_link",getNodeValue(response,"PlanDetails"));
    var headerHTM=getNodeValue(response,"Header");
    if(headerHTM!="")
    {
        setHTMLById("HeaderDiv",headerHTM);
    }
    var tbsHTM=getNodeValue(response,"ProductTabs");
    if(tbsHTM!="")
    {
        setHTMLById("TabsMenu",tbsHTM);
        TabOn(menuOn);
    }
    var content=getNodeValue(response,"DetailsSection");
    setHTMLById("content",content);
    if(content==null||content=="")
    {
        document.getElementById("content").style.marginTop='0px';
        document.getElementById("content").style.marginBottom="0px";
        document.getElementById("prod_details").style.marginBottom="0px";
    }
    else
    {
        document.getElementById("content").style.marginBottom="25px";
        document.getElementById("prod_details").style.marginBottom="25px";
    }

    var desc=getNodeValue(response,"Description");
    var linksResponse=getNodeValue(response,"Links");
    setHTMLById("descr",desc);
    if(desc==null||desc=="")
    {
        document.getElementById("descr").style.marginLeft='0px';
        document.getElementById("descr").style.marginRight='0px'
        document.getElementById("descr").style.visibility="hidden";
        document.getElementById("links").style.visibility="visible";
        document.getElementById("links").style.width="550px";
        document.getElementById("links").style.left="-10px";
        if(document.all)
        {
            document.getElementById("descr").style.width="0%";
        }
        else
        {
            document.getElementById("descr").style.width='0px';
        }
    }
    else if(linksResponse==null||linksResponse=="")
    {
        document.getElementById("descr").style.marginLeft='10px';
        document.getElementById("descr").style.marginRight='15px';
        document.getElementById("links").style.width='0px';
        document.getElementById("links").style.visibility="hidden";
        document.getElementById("descr").style.left='0px';
        document.getElementById("descr").style.visibility="visible";
        document.getElementById("descr").style.width="550px";
    }
    else
    {
        document.getElementById("descr").style.marginLeft='0px';
        document.getElementById("descr").style.marginRight='0px';
        document.getElementById("links").style.visibility="visible";
        document.getElementById("descr").style.visibility="visible";
        document.getElementById("descr").style.width='325px';
        document.getElementById("links").style.width="280px";
        document.getElementById("links").style.left="10px";
    }
    setHTMLById("links",linksResponse);
    setHTMLById("plan_rate",getNodeValue(response,"PlanPrice"));
    setHTMLById("plan_discount",getNodeValue(response,"PlanDiscount"));
    document.getElementById("CAJoinSection").style.height = "0px";
    document.getElementById("CAJoinSection").style.width = "0px";
    if(doesNodeExist(response, "JoinNowSectionForCA"))
    {
        setHTMLById("planDetails","");
        setHTMLById("getITNow1","");
                setHTMLById("getITNow2","");
        document.getElementById("getITNow2").style.height= '0px';
        if(getNodeValue(response,"JoinNowSectionForCA")!= "")
        {
            document.getElementById("CAJoinSection").style.visibility = "visible";
            document.getElementById("CAJoinSection").visible = "true";
            document.getElementById("CAJoinSection").style.height = "100%";
            document.getElementById("CAJoinSection").style.width = "95%";
        }
        setHTMLById("CAJoinSection",getNodeValue(response,"JoinNowSectionForCA"));
    }
    else
    {
        document.getElementById("CAJoinSection").style.visibility = 'hidden';
        document.getElementById("CAJoinSection").style.position= 'absolute';
        document.getElementById("CAJoinSection").visible = "false";

    }
    setHTMLById("footerNotes",getNodeValue(response,"FooterNotes"));
}
function stateChanged()
{
    if(xmlHttp.readyState==4)
    {
        setHTML();
    }
}
function GetXmlHttpObject()
{
    xmlHttp=null;
    try
    {
        xmlHttp=new XMLHttpRequest();
    }
    catch(e)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function goToName(name)
{
    var url = location.href;
    var i=url.indexOf("#");
    if(i>0)
    {
        url=url.substring(0,i);
    }
    location.href = url + "#" + name;
    ReportEventsForCustomLinks(productOn+":"+menuOn+":InternalLinks#"+name,"");
}
function onLoadInit(productName)
{
    if(productOn==productName && !initialPageLoad)
    {
	return;
    }
    var prd = getCookieSection("PageSection","Product#","#");
    if(prd != "")
    {
        productOn = prd;
    }
    ProductButtonClick(productOn,productName);
    productOn = productName;
    var qp = getQP("tb");
    if(qp!="")
    {
        menuOn=qp;
        menuClick1(menuOn,"1","0");
    }
    else
    {
        menuOn="OverviewTab";
        menuClick1(menuOn,"1","1");
    }
    initialPageLoad = false;
    setFontForLang();
}
function productClick(productName)
{
    if(productOn == productName)
    {
        return;
    }
    ProductButtonClick(productOn,productName);
    productOn = productName;
    menuClick1("OverviewTab","1","0");
}
function setCookie(prodct,tb,gp)
{
    var cookie_string="PageSection=Product#"+prodct+"#"+gp+",Tab#"+tb;
    delete_cookie("PageSection");
    document.cookie=cookie_string;
}
function getCookieSection(cookiename,section_name,separator)
{
    var currcookie = get_cookie(cookiename);
    if(currcookie!=null&&currcookie!="")
    {
        var c_start=currcookie.indexOf(section_name);
        if(c_start!=-1)
        {
            c_start = c_start + section_name.length;
            c_end = currcookie.indexOf(separator,c_start);
            if(c_end == -1)
                c_end = currcookie.length;
            return currcookie.substring(c_start,c_end);
        }
    }
    return "";
}
function menuClick1(tab,fetchprdct,gettabfromcookie)
{
    var c_end;
    var currentSelectedTab=menuOn;
    if(gettabfromcookie=="1")
    {
        var tb=getCookieSection("PageSection","Tab#","#");
        if(tb!="")
            tab=tb;
    }
    setCookie(productOn,tab,"1");
    menuOn=tab;
    var url=getUpdatedUrl("ContentProvider.aspx");
    fetchPage(url,"GET",null,null,"body_Content");
    ReportEvents(productOn,"GetMsn:" + productOn, menuOn);
    TabClick(currentSelectedTab,menuOn);
}
function menuClick(tab)
{
    var currentSelectedTab=menuOn;
    if(menuOn==tab)
        return;
    menuOn=tab;
    setCookie(productOn,tab,"1");
    var url=getUpdatedUrl("ContentProvider.aspx");
    fetchPage(url,"GET",null,null,"body_Content");
    ReportEvents(productOn,"GetMsn:" + productOn, menuOn);
    TabClick(currentSelectedTab,menuOn);
}
function getUpdatedUrl(url)
{
    var qps = getAllQParams(window.location.toString());
    var urlQps = getAllQParams(url);
    if( url != "")
    {
        if(urlQps == qps)
        {
            url = url + "?" + qps;
        }
        else
        {
            url = url + "&" + qps;
        }        
    }
    return url;
}
function getAllQParams(refUrl)
{
    refUrl.match(/\?(.+)$/);
    var allparams=RegExp.$1;
    return allparams;
}
function getQP(paramName)
{
    paramName=paramName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS="[\\?&]"+paramName+"=([^&#]*)";
    var regex=new RegExp(regexS);
    var results=regex.exec(window.location.href);
    if(results==null)
    {
        return "";
    }
    else
    {
        return results[1];
    }
}
function doesNodeExist(xml, nodeName)
{
    var retValue = false;
    var nodeBegin = "<" + nodeName + ">";
    var nodeEnd = "</" + nodeName + ">";
    var beginIndex = xml.indexOf(nodeBegin);
    if(beginIndex != -1)
    {
        var endIndex = xml.indexOf(nodeEnd);
        if(endIndex != -1)
            retValue = true;
    }
    return retValue;
}
function get_cookie(cookie_name)
{
    if(document.cookie.length>0)
    {
        c_start = document.cookie.indexOf(cookie_name+"=");
        if(c_start!=-1)
        {
            c_start = c_start + cookie_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 doesNodeExist(xml, nodeName)
{
    var retValue = false;
    var nodeBegin = "<" + nodeName + ">";
    var nodeEnd = "</" + nodeName + ">";
    var beginIndex = xml.indexOf(nodeBegin);
    if(beginIndex != -1)
    {
        var endIndex = xml.indexOf(nodeEnd);
        if(endIndex != -1)
            retValue = true;
    }
    return retValue;
}

function delete_cookie(cookie_name)
{
    var cookie_date=new Date();
    cookie_date.setTime(cookie_date.getTime()-1);
    var cookie_string=cookie_name+="=;expires="+cookie_date.toGMTString();
    document.cookie=cookie_string;
}
function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i<ca.length;i++)
    {
        var c = ca[i];
        while(c.charAt(0) == '')
            c=c.substring(1,c.length);
        if(c.indexOf(nameEQ)==0)
        {
		return c.substring(nameEQ.length,c.length);
        }
    }
    return null;
}
function getNodeValue(xml,nodeName)
{
    var nodeBegin = "<" + nodeName + ">";
    var nodeEnd = "</" + nodeName + ">";
    var beginIndex = xml.indexOf(nodeBegin);
    if(beginIndex != -1)
    {
	var endIndex = xml.indexOf(nodeEnd);
        beginIndex+=nodeBegin.length;
        var stringlen=endIndex-beginIndex;
	var strToRet=xml.substr(beginIndex,stringlen);
		return strToRet;
    }
    return "";
}

function showWait()
{
    var description = document.getElementById('descr');
    description.innerHTML="";
    document.getElementById('links').innerHTML="";
    document.getElementById('content').innerHTML="";
    description.innerHTML = "<img src='" + waitImg + "'/>";
    return;
}

function setFontForLang()
{
    var i = 0;
    for(i; i< HtmlTagList.length; i++)
    {
        var htmElem = document.getElementById(HtmlTagList[i]);
        if(htmElem)
        {
            if(browserLanguage.toUpperCase() == "JA-JP")
               htmElem.style.fontFamily = jpFfamily;
            else
	       htmElem.style.fontFamily = nonjpFfamily;
        }
    }
}

function ReportEvents(channelName,pageName,prop3)
{
    s.channel = channelName;
    s.pageName=pageName;
    s.prop1=channelName;
    s.prop2=browserLanguage;
    s.prop3=prop3;
    s.t();
}

function ReportExternalLinks(LinkName, customInsight4)
{
    var s=s_gi(s_account);
    s.prop4 = customInsight4;
    s.linkTrackVars='prop1,prop2,prop3,prop4';
    s.tl(true,'e', LinkName);
    s.prop4 = "";
}

function ReportEventsForCustomLinks(LinkName, customInsight5)
{
    var s=s_gi(s_account);
    s.prop5 = customInsight5;
    s.linkTrackVars='prop1,prop2,prop3,prop5';
    s.tl(true,'o', LinkName);
    s.prop5 = "";
}