﻿function setsessionfront(sid) {
    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }

    var url = "setajaxsessionfront.aspx?flag=sidfront&id=" + sid;

    if (XmlHttp) {
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("POST", url, false);

        //Sends the request to server
        XmlHttp.send();
    }
}

function setproductid(pid, qty) {
    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }

    var url = "setajaxsessionfront.aspx?flag=product&id=" + pid + "&qty=" + qty;

    if (XmlHttp) {
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("POST", url, false);

        //Sends the request to server
        XmlHttp.send();
    }
}

function CheckContactDetails() {
    var name = document.getElementById("ctl00_ContentPlaceHolder1_txtname");
    var email = document.getElementById("ctl00_ContentPlaceHolder1_txtemail");
    var phone = document.getElementById("ctl00_ContentPlaceHolder1_txtphoneno");

    if (name.value == "") {
        alert('Please enter your name');
        name.focus();
        return false;
    }

    if (email.value == "") {
        alert('Please enter your email address');
        email.focus();
        return false;
    }
    else {
        if (!validEmailId(email.value)) {
            alert('Please enter valid email address');
            email.value = "";
            email.focus();
            return false;
        }
    }

    if (phone.value == "") {
        alert('Please enter your phone number');
        phone.focus();
        return false;
    }
    else {
        if (!isNum(phone.value)) {
            alert('Please enter valid phone number');
            phone.value = "";
            phone.focus();
            return false;
        }
    }
}

function isNum(argvalue) {
    var c
    c = 0;
    argvalue = argvalue.toString();

    if (argvalue.length == 0) {
        return true;
    }

    for (var n = 0; n < argvalue.length; n++) {

        if (argvalue.substring(n, n + 1) == "0")
            continue;

        else if (argvalue.substring(n, n + 1) == "1")
            continue;

        else if (argvalue.substring(n, n + 1) == "2")
            continue;

        else if (argvalue.substring(n, n + 1) == "3")
            continue;

        else if (argvalue.substring(n, n + 1) == "4")
            continue;

        else if (argvalue.substring(n, n + 1) == "5")
            continue;

        else if (argvalue.substring(n, n + 1) == "6")
            continue;

        else if (argvalue.substring(n, n + 1) == "7")
            continue;

        else if (argvalue.substring(n, n + 1) == "8")
            continue;

        else if (argvalue.substring(n, n + 1) == "9")
            continue;

        else if (argvalue.substring(n, n + 1) == " ")
            continue;


        else if (argvalue.substring(n, n + 1) == ".")
            continue;

        else if (argvalue.substring(n, n + 1) == "-")
            continue;

        else if (argvalue.substring(n, n + 1) == "(")
            continue;

        else if (argvalue.substring(n, n + 1) == ")")
            continue;

        else
            return false;

    }
    return true;
}

function validEmailId(CheckEmptyEmail) {
    var inem1, inem2, lenem1, l, l1, lenem2, lensp, lechar;
    inem1 = CheckEmptyEmail.length;
    l = CheckEmptyEmail;
    l1 = l.lastIndexOf('.');
    lenem1 = l.lastIndexOf('@');
    lenem2 = l.indexOf('@');
    lensp = l.indexOf(' ');
    lechar = l.charAt(lenem1 + 1);

    if (lechar == '.') {
        return false;
    }

    if ((lenem1 + 1) == l1 || (l1 + 1) == inem1 || lenem1 > l1 || lenem2 != lenem1 || lensp != -1 || lenem1 == 0) {
        return false;
    }

    if (CheckEmptyEmail.indexOf('@') == -1 || CheckEmptyEmail.indexOf('.') == -1) {
        return false;
    }

    if (l.indexOf(',') != -1 || l.indexOf('/') != -1 || l.indexOf('(') != -1 || l.indexOf(')') != -1 || l.indexOf('*') != -1 || l.indexOf('&') != -1 || l.indexOf('^') != -1 || l.indexOf('%') != -1 || l.indexOf('$') != -1 || l.indexOf('&') != -1 || l.indexOf('#') != -1 || l.indexOf('!') != -1) {
        return false;
    }

    return true;
}

function checkqty(pid) {
    var qty = document.getElementById("ctl00_ContentPlaceHolder1_txtqty");
    if (qty.value == "") {
        alert("Please enter Quantity");
        qty.focus();
        return false;
    }
    else {
        if (!isNum(qty.value)) {
            alert("Please enter valid value for Quantity");
            qty.value = "";
            qty.focus();
            return false;
        }
    }

    setproductid(pid, qty.value);
}


function CheckandDisplay(id) {

    var url = "setajaxsessionfront.aspx?flag=productid&id=" + id;

    if (window.XMLHttpRequest) { // Mozilla, Safari, IE7... 
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE6 and older 
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    http_request.onreadystatechange = alertContents;
    http_request.open('POST', url, true);
    http_request.send(null);
}

function alertContents() {

    document.getElementById("divloadingPRINTING").innerHTML = "<img src='images/loading.gif' alt='loading' />"
    document.getElementById("divloadingPRINTING").style.display = "block";

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            //Set Response to div
            var displaydiv = document.getElementById("ctl00_ContentPlaceHolder1_div_display");
            displaydiv.innerHTML = http_request.responseText;
            //responsetext = http_request.responseText;
            document.getElementById("divloadingPRINTING").innerHTML = "";
            document.getElementById("divloadingPRINTING").style.display = "none";
        } else {
            alert('There was a problem with the request.');
            document.getElementById("divloadingPRINTING").innerHTML = "";
            document.getElementById("divloadingPRINTING").style.display = "none";
            return false;
        }
    }
}

function Projectgallery(id) {

    var url = "setajaxsessionfront.aspx?flag=projectid&id=" + id;

    if (window.XMLHttpRequest) { // Mozilla, Safari, IE7... 
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE6 and older 
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    http_request.onreadystatechange = alertContents;
    http_request.open('POST', url, true);
    http_request.send(null);
}

function alertContents() {

    document.getElementById("divloadingPRINTING").innerHTML = "<img src='images/loading.gif' alt='loading' />"
    document.getElementById("divloadingPRINTING").style.display = "block";

    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            //Set Response to div
            var displaydiv = document.getElementById("ctl00_ContentPlaceHolder1_div_display");
            var displayTitle = document.getElementById("ProductTitle");

            var resp = http_request.responseText;
            var srtGallery = resp.split("~~~");
            displaydiv.innerHTML = srtGallery[0];
            displayTitle.innerHTML = srtGallery[1];
            //responsetext = http_request.responseText;
            document.getElementById("divloadingPRINTING").innerHTML = "";
            document.getElementById("divloadingPRINTING").style.display = "none";
        } else {
            alert('There was a problem with the request.');
            document.getElementById("divloadingPRINTING").innerHTML = "";
            document.getElementById("divloadingPRINTING").style.display = "none";
            return false;
        }
    }
}
function isNumberKey(event) {
    var charCode = (event.which) ? event.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function SessionLogout() {

    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }

    var url = "logout.aspx";

    if (XmlHttp) {
        //Request URL and sets the request as asynchronous.
        XmlHttp.open("POST", url, false);

        //Sends the request to server
        XmlHttp.send();
        window.location = 'login.aspx';
        
    }

}




