﻿// JavaScript Document
function PopupWin(page, IEWidth, IEHeight, NNWidth, NNHeight) {

    var MyBrowser = navigator.appName;

    if (MyBrowser == "Netscape") {
        var myWinWidth = (window.screen.width / 2) - (NNWidth / 2);
        var myWinHeight = (window.screen.height / 2) - ((NNHeight / 2) + 50);

        var myWin = window.open(page, "MainWin", "width=" + NNWidth + ",height=" + NNHeight + ",screenX=" + myWinWidth + ",screenY=" + myWinHeight + ",left=" + myWinWidth + ",top=" + myWinHeight + ",scrollbars=yes,toolbar=0,status=1,menubar=0,resizable=0,titlebar=no");

    } else {
        var myWinWidth = (window.screen.width / 2) - (IEWidth / 2);
        var myWinHeight = (window.screen.height / 2) - ((IEHeight / 2) + 50);

        var myWin = window.open(page, "MainWin", "width=" + IEWidth + ",height=" + IEHeight + ",screenX=" + myWinWidth + ",screenY=" + myWinHeight + ",left=" + myWinWidth + ",top=" + myWinHeight + ",scrollbars=yes,toolbar=0,status=1,menubar=0,resizable=0,titlebar=no");

    }
    myWin.focus();

}
//    Registration Form Functions   ///
////////////////////////////////////////////////////////////////////////////////////////////
function checkRegistrationValue(oElement, varName){
     var messageLabel = document.getElementById('lblMessage');

     if (oElement.value == "") {
         messageLabel.innerText = "Please enter " + varName + ".";
         oElement.focus();
         disableButton(true);
         return false;
     }
     else {
         messageLabel.innerText = "";
         disableButton(false);
         return true;
     }
 }

 function disableButton(result) {
     if (result == true) {
         document.getElementById('submit').disabled = true;
     }
     else { document.getElementById('submit').disabled = false; }
 }

 function checkRegistrationForm() {
     var result;
     result = checkRegistrationValue(document.getElementById('txtName'), 'Name');
     if (result == false) { return false; }
     checkRegistrationValue(document.getElementById('txtOrganization'), 'Organization');
     if (result == false) { return false; }
     checkRegistrationValue(document.getElementById('txtPhone'), 'Phone');
     if (result == false) { return false; }
     checkRegistrationValue(document.getElementById('txtAddress'), 'Address');
     if (result == false) { return false; }
     checkRegistrationValue(document.getElementById('txtEmail'), 'Email');
     if (result == false) { return false; }
    
     result = IsValidRegistrationName(document.getElementById('txtName').value);
     if (result == false) { return false; }
     result = IsValidRegistrationEmail(document.getElementById('txtEmail').value);
     if (result == false) { return false; }
     result = IsValidRegistrationPhone(document.getElementById('txtPhone').value);
     if (result == false) { return false; }

     return true;
 }
 
 function enableRegistrationButton() {
      document.getElementById('submit').disabled = false;
 }

function IsValidRegistrationEmail(email) {
    var regex = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/g;
    if (regex.test(email)) {
        disableButton(false);
        return true;
    }
    else {
        document.getElementById('lblMessage').innerText = "Please enter valid email address.";
        document.getElementById('txtEmail').focus();
        disableButton(true);
        return false;
    }
}

function IsValidRegistrationPhone(phone) {
    var regex = /^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/g;
    if (regex.test(phone)) {
        disableButton(false);
        return true;
    }
    else {
        document.getElementById('lblMessage').innerText = "Phone number format: 9999999999.";
        document.getElementById('txtPhone').focus();
        disableButton(true);
        return false;
    }
}
function IsValidRegistrationName(name) {
    var regex = /^[a-zA-Z.]{1,25}$/;
    if(regex.test(name))
    {disableButton(false); return true;}
    else{
     document.getElementById('lblMessage').innerText = "Name can not consist of numbers or special characters.";
        document.getElementById('txtName').focus();
        disableButton(true);
        return false;}
 }