﻿function openPopUp(url, width, height) {
    window.open(url, "", "scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
    return false;
}

function headernav(num) {
    $("#headbut_" + num).attr("class", "selected");
};

$(document).ready(function () {

    // homepage cold fusion
    //loadPageInfo(); magic();

    // homepage after slider images //////////////////////////////////////
    $("#after_img_1 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/dannonOn.jpg") });
    $("#after_img_1 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/dannon.jpg") });

    $("#after_img_2 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/cnnOn.jpg") });
    $("#after_img_2 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/cnn.jpg") });

    $("#after_img_3 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/lorealOn.jpg") });
    $("#after_img_3 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/loreal.jpg") });

    $("#after_img_4 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/loccitaneOn.jpg") });
    $("#after_img_4 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/loccitane.jpg") });

    $("#after_img_5 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/perryOn.jpg") });
    $("#after_img_5 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/perry.jpg") });

    $("#after_img_6 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/timewOn.jpg") });
    $("#after_img_6 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/timew.jpg") });

    $("#after_img_7 img").mouseover(function () { $(this).attr("src", "/new_bg/hp_pics/dknyOn.jpg") });
    $("#after_img_7 img").mouseout(function () { $(this).attr("src", "/new_bg/hp_pics/dkny.jpg") });


    // homepage slider //////////////////////////////////////
    $("#cube_1").animate({ width: 'toggle' }, 600);

    $(".cube_navigation a").attr("class", "");
    $(".cube_navigation #button_1").attr("class", "selected");
    $("#pic_1").show();
    $("#logo_1").show();
    $("#details_1").show();
    $("#text_testimonial_1").show();
    $("#link_more_1").show();

    $(".cube_navigation #seebutton_1").attr("class", "selected");
    $("#seedetails_1").show();
    $("#seepic_1").show();

    $("#jquery_banner ul .but").click(function () {
        $(".cube_navigation").hide();
        var current_slide = $(this).attr("id");
        var current_cube = $(this).attr("id").replace("slide", "cube");
        var current_cube_navigation = $(this).attr("id").replace("slide", "cube") + " .cube_navigation";
        var opened_cube
        $("#jquery_banner ul .cube").each(function () {
            if (current_cube == $(this).attr("id")) {
                if ($(this).is(":visible")) { opened_cube = $(this).attr("id"); };
            }
            else {
                $(this).css("display", "none");
            };
        });

        if (current_cube != opened_cube) {
            $("#" + current_cube).animate({ width: 'toggle' }, 600);
            $("#" + current_cube_navigation).animate({ width: 'toggle' }, 2400);
        };
    });

});

function readTestimonial(num)
{
    if (($("#pic_" + num).is(":visible"))) { }
    else {
        $("#cube_2 .pic").hide();
        $("#cube_2 .logo").hide();
        $("#cube_2 .details").hide();
        $("#cube_2 .text").hide();
        $("#cube_2 .link_more").hide();


        var pic = "pic_" + num
        var logo = "logo_" + num
        var details = "details_" + num
        var text = "text_testimonial_" + num
        var link_more = "link_more_" + num
        var button = "button_" + num

        $("#cube_2 .cube_navigation a").attr("class", "");
        $("#cube_2 #" + button).attr("class", "selected");
        $("#" + pic).fadeIn();
        $("#" + logo).fadeIn();
        $("#" + text).fadeIn();
        $("#" + details).fadeIn();
        $("#" + link_more).fadeIn();
    }
};

function see(num) {
    if (($("#seepic_" + num).is(":visible"))) { }
    else {
        $("#cube_1 .pic").hide();
        $("#cube_1 .details").hide();

        var pic = "seepic_" + num
        var details = "seedetails_" + num
        var button = "seebutton_" + num

        $("#cube_1 .cube_navigation a").attr("class", "");
        $("#cube_1 #" + button).attr("class", "selected");
        $("#" + pic).fadeIn();
        $("#" + details).fadeIn();
    }
};


function hpbox2Text(num) {

    var textBox = "#box_left #text_" + num
    $("#box_left .text").hide();
    $(textBox).animate({ height: 'toggle' }, 600);

    if (num == 1) {
        $("#hpbox2Next img").attr("src", "/new_bg/hp_all/row_ltr_on.jpg")
        $("#hpbox2Back img").attr("src", "/new_bg/hp_all/row_rtl.jpg")
        $("#hpbox2Back").attr("onclick", "")
        $("#hpbox2Next").attr("onclick", "hpbox2Text(2)")
    };
    if(num==2){
        $("#hpbox2Next img").attr("src", "/new_bg/hp_all/row_ltr.jpg")
        $("#hpbox2Back img").attr("src", "/new_bg/hp_all/row_rtl_on.jpg")
        $("#hpbox2Back").attr("onclick", "hpbox2Text(1)")
        $("#hpbox2Next").attr("onclick", "")
    };
};


function footerForm() {
    var name = 0;
    var umail = 0;

    document.getElementById('newsname').style.backgroundColor = '#ffffa0';
    document.getElementById('Text5').style.backgroundColor = '#ffffa0';

    if (document.getElementById("newsname").value == "") { umail++; };
    if (document.getElementById("Text5").value == "") { name++; };

    if (umail != 0) {
        document.getElementById('newsname').style.backgroundColor = 'red';
    };

    if (name != 0) {
        document.getElementById('Text5').style.backgroundColor = 'red';
    };

    if (umail == 0 && name == 0) {
        document.newsletterForm.submit();
    };

};

function footerOriginalColor(el) { el.style.backgroundColor = '#ffffa0'; };


// kampyle////////////////////////////////////
var k_push_vars = {
    "display_after": 30,
    "view_percentage": 30,
    "popup_font_color": "#000000",
    "popup_background": "#D4E2F0",
    "header": "Your feedback is important to us!",
    "question": "Would you be willing to give us a short (1 minute) feedback?",
    "footer": "Thank you for helping us improve our website",
    "remind": "Remind me later",
    "remind_font_color": "#3882C3",
    "yes": "Yes",
    "no": "No",
    "text_direction": "ltr",
    "images_dir": "http://cf.kampyle.com/",
    "yes_background": "#76AC78",
    "no_background": "#8D9B86",
    "site_code": 6399130
};
//////////////////////////////////////////////

var inputs;
var imgFalse = '/Bg/false.png';
var imgTrue = '/Bg/true.png';
function magic() {
    inputs = document.getElementsByTagName('input');

    //cycle trough the input fields
    for (var i = 0; i < inputs.length; i++) {

        //check if the input is a checkbox
        if (inputs[i].getAttribute('type') == 'checkbox') {

            //create a new image
            var img = document.createElement('img');

            //place image in front of the checkbox
            inputs[i].parentNode.insertBefore(img, inputs[i]);

            //hide the checkbox
            inputs[i].style.display = 'none';
            //check if the checkbox is checked
            if (inputs[i].checked) { img.src = imgTrue; }
            else { img.src = imgFalse; }

            //set image ID and onclick action
            img.id = 'checkImage' + i;
            //set image
            img.onclick = new Function('checkChange(' + i + ')');
        }
    }

};

function loadPageInfo() {

    //var referredBy = set_session_referrer(document.referrer);

    if (!readTCookie('referredBy')) {
        createTCookie('referredBy', document.referrer, 0.04);

    }
    else {
        var referredBy = readTCookie('referredBy')
        createTCookie('referredBy', referredBy, 0.04);
    }
    if (!readTCookie('counter')) {
        createTCookie('counter', 1, 0.04);

    }
    else {

        var counter = parseInt(readTCookie('counter')) + 1
        //alert(counter)
        createTCookie('counter', counter, 0.04);
    };

    if (document.xform) {
        $("input[name=CurrPage]").val(location.href);
        $("input[name=referrer]").val(document.referrer);
        $("input[name=SessionReferrer]").val(referredBy);
        //alert(document.referrer);
        $("#form_submit").after('<input type="Hidden" name="bSpam" value="' + genHash() + '">');
        //alert(document.title);
    };
    //	alert(document.xform);
    //else 
    //alert(0)

};




function set_session_referrer(referrer_val) {

    //will rerurn coupon check results 
    var url = "/Includes/cf_procs/checkSession.cfm?session_referrer=" + referrer_val //+"&pos1="+pos1+"&id2="+id2+"&pos2="+pos2
    //document.location.href = url
    var session_referrer = 0;
    try {
        if (document.implementation && document.implementation.createDocument) { //alert('mox')
            var xmlDoc = document.implementation.createDocument("", "", null)
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", url, false);
            if (navigator.appName != 'Microsoft Internet Explorer') {
                xmlhttp.overrideMimeType('text/xml');
            }
            xmlhttp.send(null);
            xmlDoc = xmlhttp.responseXML;
            //alert()
            session_referrer = xmlDoc.getElementsByTagName("session_referrer")[0].firstChild.nodeValue;
            //alert(session_referrer)
            return session_referrer
        }
        else if (window.ActiveXObject) {
            //alert('ms')
            // preform asp load for ie
            xmlObj = new ActiveXObject("Microsoft.XMLDOM");
            xmlObj.async = false;
            var exml = new ActiveXObject("Microsoft.XMLHTTP")

            exml.open("POST", url, false)
            exml.send(xmlObj.xml)
            xmlObj.loadXML(exml.responseText);
            session_referrer = xmlObj.documentElement.selectSingleNode("session_referrer").nodeTypedValue;
            //dup_res=xmlObj.documentElement.selectSingleNode("dup").nodeTypedValue;
            //	alert(session_referrer)
            return session_referrer
        }
    }
    catch (e) {

        return 0
        /*frames['actionFRM'].location.href = url
        frames['actionFRM'].location.href = "/shared/blank.htm"*/
    }
};
/*********************************************************		
*                functions for cookies										  *
/*********************************************************/

function createTCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
};

function readTCookie(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 getPositions(element) {
    var selectedPosX = 0;
    var selectedPosY = 0;
    while (element != null) {
        selectedPosX += element.offsetLeft;
        selectedPosY += element.offsetTop;
        element = element.offsetParent;
    }
    return [selectedPosX, selectedPosY];
};
function hiringBut(flag) {
    var position = getPositions(document.getElementById('main_box'));
    document.getElementById('hiring').style.right = position[0] - 52 + 'px';
    document.getElementById('hiring').style.top = 72 + 'px';
    document.getElementById('hiring').style.display = '';
};

function genHash() {
    var url = "/Includes/genHash.cfm"
    //document.location.href = url
    var check_result = 0;
    try {
        if (document.implementation && document.implementation.createDocument) { //alert('mox')
            var xmlDoc = document.implementation.createDocument("", "", null)
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", url, false);
            if (navigator.appName != 'Microsoft Internet Explorer') {
                xmlhttp.overrideMimeType('text/xml');
            }
            xmlhttp.send(null);
            xmlDoc = xmlhttp.responseXML;
            //alert()
            check_result = xmlDoc.getElementsByTagName("check_result")[0].firstChild.nodeValue;
            //alert(check_result)
            return check_result
        }
        else if (window.ActiveXObject) {
            //alert('ms')
            // preform asp load for ie
            xmlObj = new ActiveXObject("Microsoft.XMLDOM");
            xmlObj.async = false;
            var exml = new ActiveXObject("Microsoft.XMLHTTP")

            exml.open("POST", url, false)
            exml.send(xmlObj.xml)
            xmlObj.loadXML(exml.responseText);
            check_result = xmlObj.documentElement.selectSingleNode("check_result").nodeTypedValue;
            //check_result=xmlObj.documentElement.selectSingleNode("dup").nodeTypedValue;
            //alert(check_result)
            return check_result
        }
    }
    catch (e) {
        //alert('script error')
    }
};


