﻿
var xmlHttp = null;
function GetXmlHttpObject() {
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}



function disablePopup1(obj) {
    document.getElementById(obj).style.display = 'none';
    document.getElementById('backgroundPopup').style.display = 'none';
}

function Focus(objname, waterMarkText) {
    obj = objname;
    if (obj.value == waterMarkText) {
        obj.value = "";
        //obj.className = "NormalTextBox";
        if (obj.value == "" || obj.value == null) {
            //obj.style.color = "black";
        }
    }
}
function Blur(objname, waterMarkText) {
    obj = objname;
    if (obj.value == "") {
        obj.value = waterMarkText;
    }
    else {
        //obj.className = "NormalTextBox";
    }

    //    if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
    //        //obj.style.color = "gray";
    //    }
}

function textTextBox(obj, objTbl) {
    var strCntrl = document.getElementById(objTbl).getElementsByTagName('input');
    var cntrl, strText;
    strText = "<collection>";
    for (i = 0; i < strCntrl.length; i++) {
        cntrl = strCntrl[i];
        if (cntrl.type == 'text' || cntrl.type == 'checkbox') {
            if (cntrl.type == 'checkbox') {
                if (cntrl.checked == true) {
                    strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
                }
            }
            else {
                if (cntrl.value == '') {
                    alert('Please Provide ' + cntrl.name);
                    cntrl.focus();
                    return;
                }
                else {
                    strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
                }
            }
        }
    }
    strText = strText + "</collection>";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }

    try {
        var UrlLive = window.location.href;
        var spltLIve = UrlLive.split('/');
        if (spltLIve.length > 4)
            xmlHttp.open("POST", "../WebService.asmx/HelloWorld", true);
        else
            xmlHttp.open("POST", "WebService.asmx/HelloWorld", true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", strText.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.setRequestHeader("port", 80);
        xmlHttp.send("name=" + strText);
        if (obj != '') {
            xmlHttp.onreadystatechange = disablePopup1(obj);
        }
        else {
            xmlHttp.onreadystatechange = stateChanged(objTbl);
        }
    }
    catch (ex) {
        alert(ex);
    }
}

function sendMail(obj, objTbl) {
    var strCntrl = document.getElementById(objTbl).getElementsByTagName('input');
    var strCntrlSelect = document.getElementById(objTbl).getElementsByTagName('select');
    var strCntrltextArea = document.getElementById(objTbl).getElementsByTagName('textarea');
    var cntrl, strText;
    strText = "<collection>";
    for (i = 0; i < strCntrl.length; i++) {
        cntrl = strCntrl[i];
        if (cntrl.type == 'text' || cntrl.type == 'checkbox' || cntrl.type == 'select') {
            if (cntrl.type == 'checkbox') {
                if (cntrl.checked == true) {
                    strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
                }
            }
            else {
                if (cntrl.value == '') {
                    alert('Please Provide ' + cntrl.name);
                    cntrl.focus();
                    return;
                }
                else {
                    strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
                }
            }
        }
    }
    for (i = 0; i < strCntrlSelect.length; i++) {
        cntrl = strCntrlSelect[i];
        strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
    }
    for (i = 0; i < strCntrltextArea.length; i++) {
        cntrl = strCntrltextArea[i];
        strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
    }
    strText = strText + "</collection>";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    try {
        var UrlLive = window.location.href;
        var spltLIve = UrlLive.split('/');
        if (spltLIve.length > 4)
            xmlHttp.open("POST", "../WebService.asmx/sendMail", true);
        else
            xmlHttp.open("POST", "WebService.asmx/sendMail", true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", strText.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.setRequestHeader("port", 80);
        xmlHttp.send("name=" + strText);
        if (obj != '') {
            xmlHttp.onreadystatechange = disablePopup1(obj);
        }
        else {
            xmlHttp.onreadystatechange = stateChangedMSG(objTbl);
        }
    }
    catch (ex) {
        alert(ex);
    }
}

function sendMailOptional(obj, objTbl) {
  
    var strCntrl = document.getElementById(objTbl).getElementsByTagName('input');
    var strCntrlSelect = document.getElementById(objTbl).getElementsByTagName('select');
    var strCntrltextArea = document.getElementById(objTbl).getElementsByTagName('textarea');
    var cntrl, strText;
    strText = "<collection>";
    for (i = 0; i < strCntrl.length; i++) {
        cntrl = strCntrl[i];
        if (cntrl.type == 'text' || cntrl.type == 'checkbox' || cntrl.type == 'select') {
            if (cntrl.type == 'checkbox') {
                if (cntrl.checked == true) {
                    strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
                }
            }
            else {
                if (cntrl.value == '') {
                    alert('Please Provide ' + cntrl.name);
                    cntrl.focus();
                    return;
                }
                else {
                    strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
                }
            }
        }
    }
    for (i = 0; i < strCntrlSelect.length; i++) {
        cntrl = strCntrlSelect[i];
        strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
    }
    for (i = 0; i < strCntrltextArea.length; i++) {
        cntrl = strCntrltextArea[i];
        strText = strText + "<" + cntrl.name + ">" + cntrl.value + "</" + cntrl.name + ">";
    }
    strText = strText + "</collection>";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    try {
        var UrlLive = window.location.href;
        var spltLIve = UrlLive.split('/');
        if (spltLIve.length > 4)
            xmlHttp.open("POST", "../WebService.asmx/sendMailOptional", true);
        else
            xmlHttp.open("POST", "WebService.asmx/sendMailOptional", true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", strText.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.setRequestHeader("port", 80);
        xmlHttp.send("name=" + strText + "&emailId=mukesh@unitedworld.in");
        if (obj != '') {
            xmlHttp.onreadystatechange = disablePopup1(obj);
        }
        else {
            xmlHttp.onreadystatechange = stateChangedMSG(objTbl);
        }
    }
    catch (ex) {
        alert(ex);
    }
}

function stateChangedMSG(obj) {
    //    if (xmlHttp.readyState == 4) {
    //        if (xmlHttp.responseText != "") {
    var strCntrl = document.getElementById(obj).getElementsByTagName('input');
    var strCntrltextArea = document.getElementById(obj).getElementsByTagName('textarea');
    var cntrl;
    for (i = 0; i < strCntrl.length; i++) {
        cntrl = strCntrl[i];
        if (cntrl.type == 'text' || cntrl.type == 'checkbox') {
            if (cntrl.type == 'checkbox') {
                if (cntrl.checked == true) {
                    cntrl.checked = false;
                }
            }
            else {
                cntrl.value = '';
            }
        }
    }
    for (i = 0; i < strCntrltextArea.length; i++) {
        cntrl = strCntrltextArea[i];
        cntrl.value = '';
    }
    alert('Thank You for your Feedback. We will get back to you soon');
    //        }
    //    }
}


function stateChanged(obj) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.responseText != "") {
            var strCntrl = document.getElementById(obj).getElementsByTagName('input');
            var cntrl;
            strText = "<collection>";
            for (i = 0; i < strCntrl.length; i++) {
                cntrl = strCntrl[i];
                if (cntrl.type == 'text' || cntrl.type == 'checkbox') {
                    if (cntrl.type == 'checkbox') {
                        if (cntrl.checked == true) {
                            cntrl.checked = false;
                        }
                    }
                    else {
                        cntrl.value = cntrl.name;
                    }
                }
            }
        }
    }
}
