﻿function ajax(type,url,dataValues,callback) {
    $.ajax({
        type: type,
        url: url,
        data: dataValues,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(data) {
            try{
            callback(data);
            }
            catch(ex){}
        }
    });
}
function importScriptFiles(src) {
    var scriptElem = document.createElement('script');
    scriptElem.setAttribute('src', src);
    scriptElem.setAttribute('type', 'text/javascript');
    document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function importStyleFiles(src) {
    var scriptElem = document.createElement('link');
    scriptElem.setAttribute('href', src);
    scriptElem.setAttribute('type', 'text/css');
    scriptElem.setAttribute('rel', 'stylesheet');
    document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function showPopup(divID) {
    if (divID == "divReg1") {
        renderRegPopup();
        $("#frmReg").attr("src", serverPath + "/register.aspx?EditMode=0&SC=1&RF=1&PW=1&NewReg=");
    }
    document.getElementById("divGrayBG").className = "hfVisible";
    $("#divGrayBG").height(getPageSize()[1]);
    $("#divGrayBG").width(getPageSize()[0]);
    $("object,embed").hide();
    document.getElementById(divID).style.display = "block";
    return false;
}
function closePopup(divID) {
    document.getElementById('divGrayBG').className = 'hfNone';
    document.getElementById(divID).style.display = "none";
    $("object,embed").show();
}
function getPageSize() {
    // handle IE 6
    if ($.browser.msie && $.browser.version < 7) {
        var scrollHeight = Math.max(
				document.documentElement.scrollHeight,
				document.body.scrollHeight
			);
        var offsetHeight = Math.max(
				document.documentElement.offsetHeight,
				document.body.offsetHeight
			);
        if (scrollHeight < offsetHeight) {
            pageHeight = $(window).height();
        } else {
            pageHeight = scrollHeight;
        }
        // handle "good" browsers
    } else {
        pageHeight = $(document).height();
    }
    return new Array('100%', pageHeight);
}
function loginClick() {
    renderLoginPopup();
    window.frames['frmLogin'].location.href = serverPath+"/Marketing/Login.aspx?menu=false&ClientCSS=y&domain="+domain+"&SCID=1";
    showPopup('divLogin');
    return false;
}
function personalizeClick() {
    renderPersonalizePopup();
//    ajax("GET", "/AjaxService.svc/GetRoleIndustry", null, function(data) {
//        $("#tdIndustry").html(data.d[0]);
//        $("#tdRole").html(data.d[1]);
//        showPopup('divPersonalize');
    //    });
    var url = "/AjaxPage.aspx?getRoleIndustry=true" + "&time=" + new Date();
    $.get(url, {}, function(resposeText) {
        var objMsg = resposeText.split('__');
        $("#tdIndustry").html(objMsg[0]);
        $("#tdRole").html(objMsg[1]);
        showPopup('divPersonalize');
    });
    return false;
}
function setRI() {
    var url = "/AjaxPage.aspx?SetRoleIndustry=true&industry=" + $("#ddlIndustry").val() + "&role=" + $("#ddlRole").val() + "&time=" + new Date();
    $.get(url, {}, function(resposeText) {
        window.location.reload();
        //    ajax("POST", "/AjaxService.svc/SetRoleIndustry", '{"industry":"' + $("#ddlIndustry").val() + '","role":"' + $("#ddlRole").val() + '"}', function(data) {
        //        window.location.reload();
    });
}
function btnMyAccount_Click() {
    window.location = "/Login.aspx?domain=" + domain + "&scid=1";
    return false;
}
function btnSignOut_Click() {
    var logoutURL = serverPath+"/Marketing/LoginStatus.aspx?op=logout&domain="+domain;
    var eleFrame = document.getElementById("ifrmStatus");
    eleFrame.src = logoutURL;
    setTimeout("goToLogin()", 1000);
    return false;
}
function goToLogin() {
    window.location = "./main.aspx?domain="+domain+"&scid=1";
}
function hideElement() {
    $("object,embed").show();
    document.getElementById('divLogin').style.display = "none";
}
function showElement() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    myWidth = (myWidth / 2) - 202;
    myHeight = (myHeight / 2) - 160;
    document.getElementById('divLogin').style.left = myWidth + 'px';
    document.getElementById('divLogin').style.top = myHeight + 'px';
    document.getElementById('divLogin').style.display = "block";
}
function SaveTo247(dataType, dataValue, scid) {
    try {
        var URL = document.getElementById("247URL").value;
        var sURL = document.location.href.split('/');
        sURL.length = 3;
        var domain = sURL.join('/');
        window.window.frames['frmLogin'].location.href = URL + '/Marketing/SaveTo247.aspx?domain=' + domain + '&dataType=' + dataType + '&dataValue=' + dataValue + '&source=hideframe' + '&SCID=' + scid;
        showPopup('divLogin');
    }
    catch (err) {
        alert("This functionality is not available from the backend");
    }
}
function saveSurvey(responseID) {
    SaveTo247("SaveSurvey", responseID, 1);
}
function renderRenderChallengePopup() { 
    if(!$("#divRenderingChallengePop").length){
        var html = '<div id="divRenderingChallengePop" style="display:none; width: 404px; position: absolute; top:200px;left:50%; margin-left:-202px; z-index:4000;">\
            <div style="height:100%;border-color: #FFFFFF; background-color:#ffffff; border-style: solid; border-width: thick;">\
                <div style="height:100%;padding:40px;color:Black;font-family:arial;" >\
                    <div id="divNotCorrect">\
                       <div style="font-weight:bold;margin:10px 0 10px 0;color:#4a9cd6;">You\'ve just proven that renderings work!</div>\
                       <div>Aareas\' 3D Architectural Renderings and Architectural Animation use the latest lighting effects in the industry to ensure that every architectural rendering we create is as realistic as possible.</div>\
                       <div> <span id="spPercent"></span>of all people who take the challenge choose one of the Aareas\' award winning 3D architectural renderings.</div>\
                    </div>\
                    <div id="divCorrect">\
                        <div>Congratulations, you have selected the correct image. You are one of a select few who can spot the difference between a real photograph and a photo realistic 3D architectural rendering.</div>\
                        <div style="margin-top:10px;">\
                            Aareas\' 3D architectural renderings and virtual reality tours use the latest lighting effects in the industry to ensure that every rendering we create is as realistic as possible.\
                        </div>\
                    </div>\
                    <img id="Img1" src="' + crossIcon + '" onclick="closePopup(\'divRenderingChallengePop\');" style="cursor: pointer;position: absolute; left: 330px; top: 240px" alt="" />\
                </div>\
            </div>\
    </div>';
    $('body').append(html);
    }
}
function renderLoginPopup() { 
    if(!$("#divLogin").length){
    var html = '<div id="divLogin" class="modalPopup" style="width: 470px; overflow:hidden;">\
        <div class="border">\
            <img id="img2" src="'+crossIcon+'" onclick="closePopup(\'divLogin\');" style="cursor: pointer;position: absolute; left: 380px; top: 300px" alt="" />\
            <div class="popupBody" >\
                <iframe frameborder="0" id="frmLogin" name="frmLogin" width="100%" height="320px"  src="">\
            </iframe>\
            </div>\
        </div>\
    </div>';
    $('body').append(html);
    }
}
function renderRegPopup() {
    if (!$("#divReg1").length) {
        var html = '<div id="divReg1" class="regModalPopup" style="width: 800px;">\
        <div class="border">\
            <img id="imgReg1" src="' + crossIcon + '" onclick="closePopup(\'divReg1\');" style="cursor: pointer;position: absolute; left: 690px; top:620px;" alt="" />\
            <div class="popupBody" >\
                <iframe id="frmReg" frameborder="0" scrolling="no" width="100%" src="" style="margin-top:10px;height:660px;"></iframe>\
            </div>\
        </div>\
    </div>';
    $('body').append(html);
    }
}
function renderPersonalizePopup() {
    if (!$("#divPersonalize").length) {
        var html = '<div id="divPersonalize" style="display:none; background-color: #ffffff; z-index: 40000;\
        width: 404px; height:270px; position: absolute;top:200px;left:35%;">\
        <div style="height:270px; background-color: #ffffff; border-color: white; border-style: solid;\
            border-width: thick;">\
            <div style="background-color: #ffffff;padding:40px;" >\
                    <table width="100%">\
                        <tr><td colspan="2" style="color:#000000; font-size:9pt;font-family:arial;">Welcome to aareas.com, in order to provide you with the most relevant browsing experience please select your Industry Sector and Role below.</td></tr>\
                        <tr><td colspan="2" style="height:5px;">&nbsp;</td></tr>\
                        <tr><td style="color:#4a9cd6; font-size:9pt;font-family:arial;font-weight:bold;">Industry :</td><td id="tdIndustry"></td></tr>\
                        <tr><td style="width:160px;color:#4a9cd6;font-size:9pt;font-family:arial;font-weight:bold;">Role :</td><td id="tdRole"></td></tr>\
                        <tr><td style="height:10px;"></td></tr>\
                          <tr><td   colspan="2" align="right"><img src="' + submitIcon + '" onclick="setRI()" /></td></tr>\
                    </table>\
            </div>\
            <div style="width:390px;">\
                <img id="btnCancel" src="' + crossIcon + '" onclick="closePopup(\'divPersonalize\');" style="cursor: pointer;\
                    position:absolute; right:20px; top:250px" alt=""/>\
            </div>\
        </div>\
    </div>';
    $('body').append(html);
    }
}