﻿

function confirmDel(sURL, sV) {
    var answer = confirm("Are you sure you want to archive: " + sV + "?")
    if (answer) {                
        window.location = sURL;
    }
}

function doPop(u) {
    var pop = window.open(u, "winportal", "width=850,height=580,resizable=1,scrollbars=1,status=0,location=0");
    pop.focus();
}

function popup(url) {
    var width = 300;
    var height = 200;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open(url, 'windowname5', params);
    //if (window.focus) { newwin.focus() }
    //return false;
}


function popupRec(url) {
    var width = 1000;
    var height = 600;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=yes';
    params += ', scrollbars=yes';
    params += ', status=yes';
    params += ', toolbar=no';
    newwin = window.open(url, 'recPrint', params);
    //if (window.focus) { newwin.focus() }
    //return false;
}


function getKeyReturn() {
    if (window.event.keyCode == 13) {
        event.returnValue = false;
        doSearch();
    }
}

function doSearch() {
    var st = document.getElementById("txtSearch").value;
    if (st == "") {
        // do nada
    } else {
        st = escape(st);
        location = "/Searcher.aspx?st=" + st;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////


function stripHTML(sV) {
    var stripped = sV.replace(/(<([^>]+)>)/ig, "");
    return stripped;
}



function testEmail(src) {
    var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
    var regex = new RegExp(emailReg);
    return regex.test(src);
}


function clearErrorSpans() {
    document.getElementById("spnValName").innerHTML = "";
    document.getElementById("spnValEmail").innerHTML = "";
    document.getElementById("spnValMessage").innerHTML = "";
    document.getElementById("spnValPhone").innerHTML = "";
    document.getElementById("spnValAddress").innerHTML = "";
    document.getElementById("spnValCity").innerHTML = "";
    document.getElementById("spnValZipcode").innerHTML = "";
    document.getElementById("spnValState").innerHTML = "";
}

function doSubContact() {
    clearErrorSpans();
    var sM = ""

    if (document.getElementById(ctl + "txtName").value == "") {
        sM += " - Name cannot be blank\n";
        document.getElementById("spnValName").innerText = " * Name cannot be blank";
    }

    if (document.getElementById(ctl + "txtEmail").value == "") {
        sM += " - Email cannot be blank\n";
        document.getElementById("spnValEmail").innerText = " * Email cannot be blank";
    } else {
        if (!testEmail(document.getElementById(ctl + "txtEmail").value)) {
            sM += " - Email is invalid\n";
            document.getElementById("spnValEmail").innerText = " * Email is invalid";
        }
    }

    if (document.getElementById(ctl + "txtPhone").value == "") {
        sM += " - Phone cannot be blank\n";
        document.getElementById("spnValPhone").innerText = " * Phone cannot be blank";
    }

    if (document.getElementById(ctl + "txtAddress").value == "") {
        sM += " - Address cannot be blank\n";
        document.getElementById("spnValAddress").innerText = " * Address cannot be blank";
    }

    if (document.getElementById(ctl + "txtCity").value == "") {
        sM += " - City cannot be blank\n";
        document.getElementById("spnValCity").innerText = " * City cannot be blank";
    }

    if (document.getElementById(ctl + "drpState").value == "--") {
        sM += " - State cannot be blank\n";
        document.getElementById("spnValState").innerText = " * State cannot be blank";
    }

    if (document.getElementById(ctl + "txtZipCode").value == "") {
        sM += " - Zipcode cannot be blank\n";
        document.getElementById("spnValZipcode").innerText = " * Zipcode cannot be blank";
    }

    if (document.getElementById(ctl + "txtMessage").value == "") {
        sM += " - Message cannot be blank\n";
        document.getElementById("spnValMessage").innerText = " * Message cannot be blank";
    }

    if (sM == "") {
        return true;
    } else {
        //alert("Please correct the following:\n" + sM);
        return false;
    }
}


function doSubEmail() {

    var sM = ""

    if (document.getElementById(ctl + "txtUsername").value == "") {
        sM += " - Email cannot be blank\n";
    }

    if (sM == "") {
        return true;
    } else {
        alert("Please correct the following:\n" + sM);
        return false;
    }
}




