﻿// JScript File
//JNA011008: Generic confirmation popup with popup message as parameter.
function ConfirmAction(message)
{
if(confirm(message)==true)
    return true;
   else
    return false;
}

//JNA012308: Function to calculate the total number of seats in the EventCreate page.
function CalculateTotalSeats(rows, seats, lblId)
{
    var row = aspxGetControlCollection().Get(rows);
    var seat = aspxGetControlCollection().Get(seats);
    
    row = row.GetValue();
    seat = seat.GetValue();  


    var totalseats = 0;
    if(IsNumeric(row) && IsNumeric(seat))
    {
        totalseats = row * seat;    
    }
    document.getElementById(lblId).value = totalseats;
}

//JNA012308: Function to determine whether a value is numeric or not.
function IsNumeric(value)
{
    var regex = /^\d+$/;
    if(!regex.test(value))
    {
        return false;
    }
    else
    {
        return true;
    }
}

function MaxLength(clientId, maxLength)
{
    //alert('Testing]' + clientId + '[');
    var testValue = aspxGetControlCollection().Get(clientId);
    //alert(testValue.GetValue());
    
    var testValueLength = testValue.GetText();
    //alert(testValueLength.length);
    
    if (testValueLength.length > maxLength)
    {
        var cutValue = testValueLength.substring(0, maxLength);
        testValue.SetValue(cutValue);
        //alert(cutValue);
    }
         
}

function MaxLengthWC(clientId, maxLength)
{
    //alert('Testing]' + clientId + '[');
    var testValue = aspxGetControlCollection().Get(clientId + "_I");
    alert(testValue.GetValue());
    
    var testValueLength = testValue.GetText();
    //alert(testValueLength.length);
    
    if (testValueLength.length > maxLength)
    {
        var cutValue = testValueLength.substring(0, maxLength);
        testValue.SetValue(cutValue);
        //alert(cutValue);
    }
         
}
function SetMaxLength(clientId)
{
    alert('Hello!');
    document.getElementById(clientId).maxLength = 10;
}

//RFR012308: Function to call when UpdatePanel is updating
 function onUpdating(wizardClientId, updateProgressDivId){
 
        // get the update progress div
        var updateProgressDiv = $get(updateProgressDivId); 
        // make it visible
        updateProgressDiv.style.display = '';

        //  get the wizard element        
        var wizard = $get(wizardClientId);
         
        
        // get the bounds of both the wizard and the progress div
        var wizardBounds = Sys.UI.DomElement.getBounds(wizard);
        var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
        
        //	do the math to figure out where to position the element (the center of the gridview)
        var x = wizardBounds.x + Math.round(wizardBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
        var y = wizardBounds.y + Math.round(wizardBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
        
        //	set the progress element to this position
        Sys.UI.DomElement.setLocation (updateProgressDiv, x, y);        
    }

//RFR012308: Function to call when UpdatePanel has finished updating 
function onUpdated(updateProgressDivId) {
    // get the update progress div
    var updateProgressDiv = $get(updateProgressDivId); 
    // make it invisible
    updateProgressDiv.style.display = 'none';
}

//RFR04022008: opens a new window in modal mode
function fn_openModal(url,parent,h,w){	
	if(window.showModalDialog)
		showModalDialog(url,parent,'dialogHeight:'+h+'px;dialogWidth:'+w+'px;scroll:yes;help:no;status:no;menubar:yes;');		
	else{
		var left = Math.round((screen.availWidth-w)/2);
		var top = Math.round((screen.availHeight-h)/2);
		w = Math.round(w * .99);
		h = Math.round(h * .85);
		window.open(url,'','status=no,toolbar=no,menubar=yes,scrollbars=yes,location=no,resizable=1,modal=yes,height='+h+',width='+w+',left='+left+',top='+top);
	}				
}

function ValidateEmail(strEmail){
//var isValid = false;
var input_str=strEmail;
var input_len1=input_str.length;
var iserror=0;

    input_len1=input_str.length;

    if (input_len1 <= 5) {
        //alert("You must enter a Valid Email Address!\n");
        iserror=1;
    }

    var lastdot=-1;
    var lastat=-1;
    var numberat=0
    for (var j = 0; j < input_len1; j++) {
         var ch2 = input_str.substring(j, j + 1);
         if (((ch2 < "a") ||  (ch2 > "z")) && ((ch2 < "A") || (ch2 > "Z")) && ((ch2 < "0") ||  (ch2 > "9")) && (ch2 != "@" ) && (ch2 != ".") && (ch2 != "_") && (ch2 != "-")){
             //alert("Please input a valid email address!\nValid characters include A-Z, a-z, 0-9, -, _, . and @");
             iserror=1;
         }
         if (ch2==".") {
             if ( j == lastdot + 1) {
                 //alert("Please input a valid email address!\nYou can't have two dots next to\neach other'..'.");
                 iserror=1;
             }
             lastdot=j;
         }
         if (ch2=="@") {
             lastat=j;
             numberat=numberat+1
         }
         if (ch2==" ") {
             //alert("Please input a valid email address!\nYou can't have any spaces in the address.");
             iserror=1;
         }
    }
    if (lastat == -1) {
         //alert("Please input a valid email address!\nYou don't have an '@'.");
         iserror=1;
    }
    if (lastat == 0) {
         //alert("Please input a valid email address!\nYou don't have a name before the '@'.");
         iserror=1;
    }
    if (numberat > 1) {
         //alert("Please input a valid email address!\nYou may have only one '@'.");
         iserror=1;
    }
    if ((lastdot <= lastat) || (lastdot > input_len1 - 3 ) || (input_len1 - lastdot > 10)) {
         //alert("Please input a valid email address!\nYou don't have a proper domain name!\nUse .com, .org, .net, .cc, etc");
         iserror=1;
    }
    if (lastdot == lastat + 1) {
         //alert("Please input a valid email address!\nYou don't have a proper organization name!\nUse name@organization.domain");
         iserror=1;
    }
    if (iserror==1) {
         return false;
    }
    else
	   return true;
}

//JRMT05202008: Function to redirect search
function RedirectSearch(urlRedirect)
{
    var qstring = document.getElementById('txtSearch').value;
    location.href = urlRedirect + '?keyword=' + qstring;
}

    
  //RFR062508: Function to redirect to search when pressing enter key
  function GoSearch (e, urlRedirect) {
        //user press an enter key
        
        var keynum;
        
        //if IE
        if (window.event) 
        {
            keynum = e.keyCode;
            if (keynum == 13) {
                RedirectSearch(urlRedirect);
             }
            
        }
        //if  Netscape/Firefox/Opera
        else if (e.which) 
        {
            keynum = e.which;

            if (keynum == 13) {
                RedirectSearch(urlRedirect);
            }
        
        }
         
         return true;   
            
    }

//JNA062608: Function to redirect to login when pressing enter key
function GoLogin (e)
{
    var keynum;
        
        //if IE
        if (window.event) 
        {
            keynum = e.keyCode;
            if (keynum == 13) {
                document.frmLogin.submit();
             }
            
        }
        //if  Netscape/Firefox/Opera
        else if (e.which) 
        {
            keynum = e.which;

            if (keynum == 13) {
                document.frmLogin.submit();
            }
        
        }
         
         return true;   
}

//AAD022309: Function to check if string is a potentially dangerous script or html
function ValidateString(controlId)
{
    var control = aspxGetControlCollection().Get(controlId);
    var strVal = "";
    if(control.GetValue() == null)
    {
        strVal = "";
    }
    else
    {
        strVal =  control.GetValue();
    }
    
	var regX = /<(\S+).*(>)?(.*)(<\/\1>)?/;
	//checks if string is a script or html
	//var strMatch = strVal.match(regX);
	//if(strMatch == null || strMatch == '')
	if(!regX.exec(strVal))
	{
        return true;
    }
    else
    {
        return false;
    }
}