﻿/* General.js this file contains general javascript functions*/

var regionIsSet = false;


function toggle(el) {
    Obj = document.getElementById(el);
    if (Obj.style.display == '' || Obj.style.display == 'none') {
        Obj.style.display = 'block';
    }
    else {
        Obj.style.display = 'none';
    }
}

function setClassOn(el, cl) {
    Obj = document.getElementById(el);
    if (Obj.className != cl) {
        Obj.className = cl;
    }
}

function setClassOff(el, cl) {
    Obj = document.getElementById(el);
    if (Obj.className == cl) {
        Obj.className = '';
    }
}

function setClass(el, cl) {
    Obj = document.getElementById(el);
    if (Obj.className != cl) {
        Obj.className = cl;
    }
    else {
        Obj.className = '';
    }
}

function setRegionSelect(el1, el2, cl) {
    if (regionIsSet == false) {
        regionIsSet = true;
    }
    else {
        regionIsSet = false;
    }
    toggle(el1);
    setClass(el2, cl);
}

function cancelRegionSelect(el1, el2, cl) {
    if (regionIsSet == true) {
        regionIsSet = false;
        toggle(el1);
        setClass(el2, cl);
    }
}

/* ------------ Javascript Cookie ------------------ */

/*
function getCookie(name)
{ 
var start = document.cookie.indexOf(name+"="); 
var len = start+name.length+1; 
if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
if (start == -1) return null; 
var end = document.cookie.indexOf(";",len); 
if (end == -1) end = document.cookie.length; 
return unescape(document.cookie.substring(len,end)); 
} 

function setCookie(name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
*/

function getexpirydate(nodays) {
    var UTCstring;
    Today = new Date();
    nomilli = Date.parse(Today);
    Today.setTime(nomilli + nodays * 24 * 60 * 60 * 1000);
    UTCstring = Today.toUTCString();
    return UTCstring;
}

function getcookie(cookiename) {
    var cookiestring = "" + document.cookie;
    var index1 = cookiestring.indexOf(cookiename);
    if (index1 == -1 || cookiename == "") return "";
    var index2 = cookiestring.indexOf(';', index1);
    if (index2 == -1) index2 = cookiestring.length;
    return unescape(cookiestring.substring(index1 + cookiename.length + 1, index2));
}

function setcookie(name, value, path, duration) {
    //cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
    cookiestring = name + "=" + escape(value) + ";path=" + escape(path) + ";EXPIRES=" + getexpirydate(duration);
    //alert(cookiestring);
    document.cookie = cookiestring;
    if (!getcookie(name)) {
        return false;
    }
    else {
        return true;
    }
}



function rollHomePageImages(img_name, img_src) {
    document[img_name].src = img_src;
}



function DetectEnd() {



    nDiv = document.getElementById('formTermsAndConditions');


    var pos = nDiv.scrollTop + nDiv.scrollHeight;



    var divPos = (nDiv.scrollHeight - nDiv.scrollTop);

    var divPosPixels = divPos + 'px';

    //alert(nDiv.style.height);

    if (divPosPixels == nDiv.style.height) {

        divCheckBox = document.getElementById('checkBoxDiv');

        divCheckBox.style.display = 'block';

    }

}

function OpenRegistration() {


    var _clientagentname = ""; //getQuerystring('_clientagentname')
    var _clientagentid = ""; //getQuerystring('_clientagentid')


    var HiFX_Cookie = getcookie('HiFX_ClientAffiliate');


    if (HiFX_Cookie != "") {
        var cookieKeys = HiFX_Cookie.split("&");

        var key1Values = cookieKeys[0].split("=");

        var key2Values = cookieKeys[1].split("=");
        _clientagentname = key1Values[1];
        _clientagentid = key2Values[1];
        window.open("https://www.hifxonline.co.uk/registration?_clientagentname=" + _clientagentname + "&_clientagentid=" + _clientagentid);
    }
    else {
        window.open("https://www.hifxonline.co.uk/registration");
    }
}
 
