﻿function doPop(u) {
    var pop = window.open(u, "winportal", "width=850,height=580,resizable=1,scrollbars=1,status=0,location=0");
    pop.focus();
}



function doSubPoll(sID) {
    var sV = document.getElementById("vID" + sID).value;
    if (sV != "") {
        location = "PollAdd.aspx?bid=" + BID + "&poid=" + sID + "&v=" + sV;
    } else {
        alert("Please choose an option");
    }
}

function doSubDP(sID) {
    var sV = document.getElementById("vID" + sID).value;
    if (sV != "") {
        location = "PollAdd.aspx?bid=" + BID + "&poid=" + sID + "&v=" + sV;
    } else {
        alert("Please choose an option");
    }
}

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 doSubComments() {

    var sM = ""

    if (document.getElementById(ctl + "txtUsername").value == "") {
        sM += " - Username cannot be blank\n";
    } else {
        if (!testEmail(document.getElementById(ctl + "txtUsername").value)) {
            sM += " - Username is invalid\n";
        }
    }

    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;
    }
}

function popEventLocation(sV) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
        var xMax = window.outerWidth, yMax = window.outerHeight;
    else
        var xMax = 640, yMax = 480;

    var xOffset = (xMax - 200) / 2, yOffset = (yMax - 200) / 2;

    var URL = "/EventLocation.aspx?st=" + sV;

    myRef = window.open(URL, 'portalpop', 'width=420,height=420,screenX=' + xOffset + ',screenY=' + yOffset + ',top=' + yOffset + ',left=' + xOffset + ',scrollbars=1,toolbar=0,resizable=0,status=0');
}

function doSub() {

    var sM = ""

    if (document.getElementById(ctl + "txtFirstname").value == "") {
        sM += " - First Name cannot be blank\n";
    }

    if (document.getElementById(ctl + "txtLastname").value == "") {
        sM += " - Last Name cannot be blank\n";
    }

    if (document.getElementById(ctl + "txtEmail").value == "") {
        sM += " - Email cannot be blank\n";
    } else {
        if (!testEmail(document.getElementById(ctl + "txtEmail").value)) {
            sM += " - Email is invalid\n";
        }
    }

    if (document.getElementById(ctl + "txtPassword").value != document.getElementById(ctl + "txtPassword2").value) {
        sM += " - Password do not match \n";
    }

    if (document.getElementById(ctl + "txtPassword").value.length < 6) {
        sM += " - Password must be at least 6 characters \n";
    }

    if (sM == "") {
        return true;
    } else {
        alert("Please correct the following:\n" + sM);
        return false;
    }
}


function doSubEvents() {

    var sM = ""

    if (document.getElementById(ctl + "txtTitle").value == "") {
        sM += " - Event Title cannot be blank\n";
    }    

    if (document.getElementById(ctl + "txtEmail").value == "") {
        sM += " - Email cannot be blank\n";
    } else {
        if (!testEmail(document.getElementById(ctl + "txtEmail").value)) {
            sM += " - Email is invalid\n";
        }
    }    

    if (sM == "") {
        return true;
    } else {
        alert("Please correct the following:\n" + sM);
        return false;
    }
}