﻿// JScript File
var mywindow;
var lwr = 'abcdefghijklmnopqrstuvwxyz ';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
var numb = '0123456789-+ ';
function MM_openBrWindow(theURL, winName, features) {
    // mywindow  = window.open(theURL,winName,features);
    //mywindow  = window.open(theURL,winName,"location=0,status=0,scrollbars=1,width=590,height=420");
    //alert(screen.width);
    if (parseFloat(navigator.appVersion) == 4)//IE 
        mywindow = window.open(theURL, winName, "location=No,status=No,scrollbars=Yes,width=500,height=510,left=" + (screen.width - 590) / 2 + "top=" + (screen.height - 420) / 2);
    else
        mywindow = window.open(theURL, winName, "location=0,status=0,scrollbars=1,width=500,height=495,left=" + (screen.width - 585) / 2 + "top=" + (screen.height - 480) / 2);
}
function MM_openDemoWindow(theURL, winName, features, w, h) {

    if (parseFloat(navigator.appVersion) == 4)//IE 
        mywindow = window.open(theURL, winName, "location=No,status=No,scrollbars=Yes,width=865,height=650,center");
    else
        mywindow = window.open(theURL, winName, "location=0,status=0,scrollbars=1,width=865,height=635,center");
}

function OpenRequiredURL(Url) {
    alert(Url);
}
var ip = '<!--#echo var="REMOTE_ADDR"-->';
function ipval() {
    alert(123);
    //document.myform.ipadd.value=ip;
    alert(ip);
}
function OnResetButtonClick() {

    if (document.getElementById('txtFirstName') != null)
        document.getElementById('txtFirstName').value = '';
    if (document.getElementById('emailFeild') != null)
        document.getElementById('emailFeild').value = '';
    if (document.getElementById('phoneNoFld') != null)
        document.getElementById('phoneNoFld').value = '';
    if (document.getElementById('organisationFld') != null)
        document.getElementById('organisationFld').value = '';
    if (document.getElementById('CountryLst') != null)
        document.getElementById('CountryLst').selectedIndex = 0;
    if (document.getElementById('hearDdl') != null)
        document.getElementById('hearDdl').selectedIndex = 0;
    if (document.getElementById('sourceTxtBx') != null)
        document.getElementById('sourceTxtBx').value = '';
    if (document.getElementById('cityTxtBx') != null)
        document.getElementById('cityTxtBx').value = '';
    document.getElementById('txtFirstName').focus();
}
function validateRequest() {

    if (document.getElementById('txtFirstName').value == "") {
        alert("Please enter your name");
        document.getElementById('txtFirstName').focus();
        return false;
    }
    else if (!CheckForSpecialChars()) {
        alert("Please enter a valid name");
        document.getElementById('txtFirstName').focus();
        return false;
    }
    else if (!isAlpha(document.getElementById('txtFirstName').value)) {
        alert("Please enter a valid name");
        document.getElementById('txtFirstName').focus();
        return false;
    }
    if (document.getElementById('professionalTxtBx').value == "") {
        alert("Please enter your Professional Title");
        document.getElementById('professionalTxtBx').focus();
        return false;
    }
    else if (document.getElementById('organisationFld').value == "") {
        alert("Please enter your organization");
        document.getElementById('organisationFld').focus();
        return false;
    }
    else if (document.getElementById('emailFeild').value == "") {
        alert("Please enter your E-mail");
        document.getElementById('emailFeild').focus();
        return false;
    }
    else if ((document.getElementById('emailFeild').value != "") && (!ValidateEmailAddress(document.getElementById('emailFeild').value))) {
        alert("Please enter valid E-mail");
        document.getElementById('emailFeild').focus();
        return false;
    }
    else if (document.getElementById('phoneNoFld').value == "") {
        alert("Please enter your phone number");
        document.getElementById('phoneNoFld').focus();
        return false;
    }
    else if (!isValidPhoneNum(document.getElementById('phoneNoFld').value)) {
        alert("Please enter a valid phone number");
        document.getElementById('phoneNoFld').focus();
        return false;
    }
    else if (document.getElementById('cityTxtBx').value == "") {
        alert("Please enter your city");
        document.getElementById('cityTxtBx').focus();
        return false;
    }
    else if (document.getElementById('CountryLst').selectedIndex == 0) {
        alert("Please select your country");
        document.getElementById('CountryLst').focus();
        return false;
    }
    else if (document.getElementById('areaOfInterestDdl').selectedIndex == -1) {
        alert('Please select Area of Interest');
        document.getElementById('areaOfInterestDdl').focus();
        return false;
    }
    else if (document.getElementById('hearDdl') != null && document.getElementById('hearDdl').selectedIndex == 0) {
        alert("Please select how you hear about us");
        document.getElementById('hearDdl').focus();
        return false;
    }
    else if (document.getElementById('sourceTxtBx').value == "") {
        alert("Please enter the source");
        document.getElementById('sourceTxtBx').focus();
        return false;
    }
    getListBoxSelections();
    var params = "";
    if (document.getElementById('hearDdl') != null) {
        params = "name=" + document.getElementById('txtFirstName').value + "&email=" + document.getElementById('emailFeild').value + "&PhoneNO=" + document.getElementById('phoneNoFld').value + "&org=" + document.getElementById('organisationFld').value + "&country=" + document.getElementById('CountryLst').value + "&heardId=" + document.getElementById('hearDdl').value + "&canContact=true" + "&RedirectUrl=" + document.getElementById('HiddenRedirectUrlContol').value + "&CountryName=" + document.getElementById('CountryLst').options[document.getElementById('CountryLst').selectedIndex].text + "&HeardAbout=" + document.getElementById('hearDdl').options[document.getElementById('hearDdl').selectedIndex].text + "&Source=" + document.getElementById('sourceTxtBx').value + "&ProfessionalTitle=" + document.getElementById('professionalTxtBx').value + "&City=" + document.getElementById('cityTxtBx').value + "&Comments=--" + "&areaOfInterest=" + document.getElementById('areaOfInterest').value + "&areaOfInterestIds=" + document.getElementById('areaOfInterestIds').value;
        var ajaxReq1 = new AJAXInteraction("SaveDownLoadRequests.aspx?" + params, afterSave, "error!");
    }
    var email = document.getElementById('emailFeild').value.toLowerCase();
    if (email.indexOf("semanticspace.com") == "-1") {
        ajaxReq1.doPost();
    }

    switch (document.getElementById('HiddenRedirectUrlContol').value) {
        case 'ProductDemo':
            window.open('PPMStudio_Library/PPM_Demo/PPM_Studio_Demo.htm', "", "location=0,status=0,scrollbars=0,width=855,height=640");
            break;
        case 'PPMStudio broucher':
            window.open('PPMStudio_Library/Brochures/ppmstudio_brochure_ver2.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break;
        case 'PPM SaaS broucher':
            window.open('PPMStudio_Library/Brochures/ppm_saas.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break;
        case 'PPMStudio Integration With SharePoint':
            window.open('PPMStudio_Library/Brochures/ppm_sharepoint_ver1.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
        case 'PPM Studio Document Management broucher':
            window.open('PPMStudio_Library/Brochures/document_mangt_ver1.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
        case 'Mortagage Case Study':
            window.open('PPMStudio_Library/Brochures/Mortgage lending firm.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
        case 'Entertainment Case Study':
            window.open('PPMStudio_Library/Brochures/Worlds largest media.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
        case 'Payment Case Study':
            window.open('PPMStudio_Library/Brochures/LeadingPaymentServices.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
        case 'Detailed Comparision Chart':
            window.open('PPMStudio_Library/PPMStudioDetailedComparisionChart.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
        case 'PPM SaaS Vs MS Project broucher':
            window.open('PPMStudio_Library/Brochures/PPM_MSProject.pdf', "", "location=0,status=0,scrollbars=1,width=1024,height=768");
            break
    }
    parent.close();
}

function getListBoxSelections() {
    var listBoxRef = document.getElementById("areaOfInterestDdl");
    var areaOfInterest = '';
    var areaOfInterestIds = '';

    for (var i = 0; i < listBoxRef.options.length; i++) {
        if (listBoxRef.options[i].selected) {
            if (areaOfInterest.length > 0) {
                areaOfInterest += ',';
                areaOfInterestIds += ',';
            }

            areaOfInterestIds += listBoxRef.options[i].value;
            areaOfInterest += listBoxRef.options[i].text;

        } //outer if
    } //for

    document.getElementById('areaOfInterest').value = areaOfInterest;
    document.getElementById('areaOfInterestIds').value = areaOfInterestIds;

}

function ValidateEmailAddress(sEmailAddress) {
    return ((sEmailAddress.length > 0) && (sEmailAddress.indexOf("@") > 0) && (sEmailAddress.indexOf(".", sEmailAddress.indexOf("@")) > 0));
}
function afterSave(response) {
}

var mikExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|]/;

function CheckForSpecialChars() {
    if (document.getElementById('txtFirstName').value.search(mikExp) == -1) {
        return true;
    }
    else {
        return false;
    }
}


function isNum(parm) {
    return isValid(parm, numb);
}
function isLower(parm) {
    return isValid(parm, lwr);
}
function isUpper(parm) {
    return isValid(parm, upr);
}
function isAlpha(parm) {
    return isValid(parm, lwr + upr);
}
function isAlphanum(parm) {
    return isValid(parm, lwr + upr + numb);
}
function isValidPhoneNum(parm) {
    for (i = 0; i < parm.length; i++) {
        if (numb.indexOf(parm.charAt(i), 0) == -1)
            return false;
    }
    if (parm.indexOf("--", 0) != -1)
        return false;
    if (parm.indexOf("++", 0) != -1)
        return false;

    return true;
}
function isValid(parm, val) {
    for (i = 0; i < parm.length; i++) {
        if (val.indexOf(parm.charAt(i), 0) == -1)
            return false;
    }
    return true;
}
