var HeaderTxt = "";
var AllowPostback = true;

////Add click event to elements
//if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)
//HTMLElement.prototype.click = function() {
//var evt = this.ownerDocument.createEvent('MouseEvents');
//evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
//this.dispatchEvent(evt);
//} 
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return "";
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}
function validatePOBox(name)
{
//P.O. Box, Po Box, Post Office Box, Box, P0 Box
    //var r = /((P\.?O\.?(B\.?)?(\s+Box)?)|(Post\s+Office(\s+Box)?))+/gi;
    var r= /((P\.?O\.?([^A-Z])(\s+Box)?)|(Post\s+Office(\s+Box)?))+/gi;
    //var r = new RegExp("[p]{1}[.]*[o]{1}[.]*[ ]*[b]{1}[o]{1}[x]{1}","gi");
    //\b[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]\b
    if(name.value.match(r))
    {
        alert("P.O. Boxes are not allowed.");
        name.focus();
        return false;
    }
}
function validateFullName(name)
{
  // Check for Full name
     reName = new RegExp(/\S\s\S/);

     if (!reName.test(name.value)) {
          alert("Please enter a first name and last name.");
          name.focus();
          return false;
     }
}
function validateEmail(addr,man,db) 
{
    if(!validateEmailValue(addr,man,db))
        {
            var value = addr.value;
            event.returnValue=false;
            event.cancel = true;
            addr.focus();
            addr.value = value;
            return false;
           }
}
// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd
function validateEmailValue(addr,man,db) 
{
    var fieldValue = addr.value;
    if (fieldValue == '' && man) 
    {
        if (db){ alert('Please enter your email address.');
            return false;
            }
    }
    if (fieldValue == '') return true;
    var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
    for (i=0; i<invalidChars.length; i++) 
    {
        if (fieldValue.indexOf(invalidChars.charAt(i),0) > -1) 
        {
            if (db){ alert('Email address contains invalid characters.');
             return false;}
        }
    }
    for (i=0; i<fieldValue.length; i++) 
    {
        if (fieldValue.charCodeAt(i)>127) 
        {
            if (db){ alert("Email address contains non ascii characters.");
            return false;}
        }
    }

var atPos = fieldValue.indexOf('@',0);
if (atPos == -1) {
   if (db) {alert('Email address must contain an @');
            return false;}
}
if (atPos == 0) {
   if (db){ alert('Email address must not start with @');
            return false;}
}
if (fieldValue.indexOf('@', atPos + 1) > - 1) {
   if (db) {alert('Email address must contain only one @');
            return false;}
}
if (fieldValue.indexOf('.', atPos) == -1) {
   if (db) {alert('Email address must contain a period in the domain name');
           return false;}
}
if (fieldValue.indexOf('@.',0) != -1) {
   if (db) {alert('A period must not immediately follow @ in email address');
            return false;}
}
if (fieldValue.indexOf('.@',0) != -1){
   if (db) {alert('A period must not immediately precede @ in email address');
           return false;}
}
if (fieldValue.indexOf('..',0) != -1) {
   if (db){ alert('Two periods must not be adjacent in email address');
            return false;}
}
var suffix = fieldValue.substring(fieldValue.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) {alert('Invalid primary domain in email address');
            return false;}
}

return true;
}
function GetClientId(strid)
{
     var count=document.forms[0].length;
     var i = 0;
     var eleName;
     for (i=0;i<count;i++ )
     {
       eleName = document.forms[0].elements[i].id;
       pos=eleName.indexOf(strid);
       if(pos >= 0)  break;           
     }
    return eleName;
 }
function SumInnerHTML(tag,nTimes)
{
    var nTotal = 0;
    
    for(j=1;j<=nTimes;j++)
    {
     if(document.getElementById(tag + j))
        nTotal += parseInt(document.getElementById(tag + j).innerHTML); 
    }
    return nTotal;
}
function closeDefaultPOP()
{
    window.top.popup.HideWindow(window.top.popup.GetWindowByName('defpop'));return false;
}
function closePOP(name)
{
    window.top.popup.HideWindow(window.top.popup.GetWindowByName(name));return false;
}
function SetPopVisible(name,value) 
{
    var popupControl = GetPopupControl(name);
    var hintWindow = popupControl.GetWindowByName(name);
    
    if(value)
        popupControl.ShowWindow(hintWindow);
    else
        popupControl.HideWindow(hintWindow);
}

function KillWindow(name)
{
    var popupControl = GetPopupControl(name);
    for(var i = 0; i < popupControl.GetWindowCount(); i++) 
    {
		var window = popupControl.GetWindow(i);
		    window = null;
	}
}
function isPhoneNumber(s) 
{
     // Check for correct phone number
     if(!checkInternationalPhone(s.value))
     {
          alert("Please enter a valid phone number");
          s.focus();
          return false;
     }

return true;
}
/*
	Password Validator 0.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT License
*/
//var password = "password";
//var passed = validatePassword(password, {
//	length:   [8, Infinity],
//	lower:    1,
//	upper:    1,
//	numeric:  1,
//	special:  1,
//	badWords: ["password", "steven", "levithan"],
//	badSequenceLength: 4
//});
//// passed: false
function validatePassword(pw, options, message)
{
    if(!validatePasswordCheck(pw.value,options))
        {
            if(message)alert(message);
            else alert("Please enter a valid password.");
            pw.focus();
            return false;
         }
}
function validatePasswordCheck (pw, options) {
	// default options (allows any password)
	var o = {
		lower:    0,
		upper:    0,
		alpha:    0, /* lower + upper */
		numeric:  0,
		special:  0,
		length:   [0, Infinity],
		custom:   [ /* regexes and/or functions */ ],
		badWords: [],
		badSequenceLength: 0,
		noQwertySequences: false,
		noSequential:      false
	};

	for (var property in options)
		o[property] = options[property];

	var	re = {
			lower:   /[a-z]/g,
			upper:   /[A-Z]/g,
			alpha:   /[A-Z]/gi,
			numeric: /[0-9]/g,
			special: /[\W_]/g
		},
		rule, i;

	// enforce min/max length
	if (pw.length < o.length[0] || pw.length > o.length[1])
		return false;

	// enforce lower/upper/alpha/numeric/special rules
	for (rule in re) {
		if ((pw.match(re[rule]) || []).length < o[rule])
			return false;
	}

	// enforce word ban (case insensitive)
	for (i = 0; i < o.badWords.length; i++) {
		if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
			return false;
	}

	// enforce the no sequential, identical characters rule
	if (o.noSequential && /([\S\s])\1/.test(pw))
		return false;

	// enforce alphanumeric/qwerty sequence ban rules
	if (o.badSequenceLength) {
		var	lower   = "abcdefghijklmnopqrstuvwxyz",
			upper   = lower.toUpperCase(),
			numbers = "0123456789",
			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
			start   = o.badSequenceLength - 1,
			seq     = "_" + pw.slice(0, start);
		for (i = start; i < pw.length; i++) {
			seq = seq.slice(1) + pw.charAt(i);
			if (
				lower.indexOf(seq)   > -1 ||
				upper.indexOf(seq)   > -1 ||
				numbers.indexOf(seq) > -1 ||
				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
			) {
				return false;
			}
		}
	}
	// enforce custom regex/function rules
	for (i = 0; i < o.custom.length; i++) {
		rule = o.custom[i];
		if (rule instanceof RegExp) {
			if (!rule.test(pw))
				return false;
		} else if (rule instanceof Function) {
			if (!rule(pw))
				return false;
		}
	}

	// great success!
	return true;
}
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function EnterTabKeyPress(event)
{
	var keyChar = (window.event)? event.keyCode : event.which;
	if (keyChar == 13)
	{
		return false;
	}
	return true;
}
function DefaultButtonClick(btn)
{
    // process only the Enter key
    if (event.keyCode == 13)
    {
        // cancel the default submit
        event.returnValue=false;
        event.cancel = true;
        // submit the form by programmatically clicking the specified button
        btn.click();
    }
}

function openCentered (url, windowName, width, height, featureString, refreshParent)
{
  if(!windowName) windowName = '';
  if (!featureString)
    featureString = '';
  else
    featureString = ',' + featureString;
  
  var x = Math.round((screen.availWidth - width) / 2);
  var y = Math.round((screen.availHeight - height) / 2);
  featureString = 'left=' + x + ',top=' + y + ',width=' + width + ',height=' + height + featureString;
  //if eports, skip the refresh check
  if(url.indexOf("eReports")>0)
     return open (url, windowName, featureString);
     
  newWin = open ('pleasewait.htm', windowName, featureString);
  newWin.document.location = url;
  if(refreshParent==true)
    setTimeout("newWin.document.body.onunload = function r(){window.parent.location.reload(true);}",2000);
  
  return newWin
}



function openPopUp(url, windowName, width, height, featureString, refreshParent)
{
    //set window size
    //set location
    //
}
function openReport(sn,f,r)
{
	window.open(sn + '/runreport.aspx?fid=' + f + "&rid=" + r,null,"height=600px,width=750px,status=yes,toolbar=yes,menubar=yes,location=no,resizable=yes,scrollbars=yes");
}
function doEmptyPostback()
{
	if(AllowPostback==true)
		__doPostBack('', '');
}
function FitPic() 
{ 
	 var NS=document.all;
     iWidth = (!NS)?window.innerWidth:document.body.clientWidth; 
     iHeight = (!NS)?window.innerHeight:document.body.clientHeight; 
     iWidth = document.images[0].width - iWidth; 
     iHeight = document.images[0].height - iHeight; 
     //window.resizeBy(iWidth, iHeight); 
     if(!NS){self.moveTo((self.screen.width - self.outerWidth) / 2, (self.screen.height - self.outerHeight) / 2);}
     else{self.moveTo((self.screen.width-document.body.clientWidth) / 2, (self.screen.height-document.body.clientHeight) / 2);}
     self.focus(); 
}
function wopen(url, name, w, h)
{
	w += 32;
	h += 96;
	var win = window.open(url,name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no');
	win.resizeTo(w, h);
	win.focus();
}
function OpenChild() 
{
    var ParmA = retvalA.value;
    var ParmB = retvalB.value;
    var ParmC = retvalC.value;
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    var WinSettings = "center:yes;resizable:no;dialogHeight:300px"
    //ALTER BELOW LINE - supply correct URL for Child Form
    var MyArgs = window.showModalDialog(
   "http://localhost/ModalWin/ChildWebForm.aspx", MyArgs, WinSettings);
    if (MyArgs == null)
    {
        window.alert(
          "Nothing returned from child. No changes made to input boxes")
    }
    else
    {
        retvalA.value=MyArgs[0].toString();
        retvalB.value=MyArgs[1].toString();
        retvalC.value=MyArgs[2].toString();
    }
}

function ChildDone() {
    var ParmA = tbParamA.value;
    var ParmB = tbParamB.value;
    var ParmC = tbParamC.value;
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    window.returnValue = MyArgs;
    window.close();
}
function ChilddoInit() {
    var ParmA = "Aparm";
    var ParmB = "Bparm";
    var ParmC = "Cparm";
    var MyArgs = new Array(ParmA, ParmB, ParmC);
    MyArgs =  window.dialogArguments;
    tbParamA.value = MyArgs[0].toString();
    tbParamB.value = MyArgs[1].toString();
    tbParamC.value = MyArgs[2].toString();
}
function addEmailToList(ctl)
{
	
	strRep = prompt("Enter an email address","");
	if(strRep != null)
	{
		if(document.getElementById(ctl).value.length > 0)
			document.getElementById(ctl).value = document.getElementById(ctl).value + ";" + strRep ;
		else
			document.getElementById(ctl).value = document.getElementById(ctl).value + strRep ;
	}
}
function HideShow(i)
{
	if(i.style.display == '')
		{i.style.display = 'none';}
	else
		{
			i.style.display = '';	
		}
}
function HideShowArray(i,ShowHide)
{
    var display ="";
    if(ShowHide=="hide")display="none";
    for(j=0;j < i.length; j++)
    {
        document.getElementById(i[j]).style.display = display;
	 }
}
function setInitialHideShow(i,isHide)
{
	try
	{
	    if(isHide == false)
		    i.style.display = 'none';
	    else
		    i.style.display = '';	
	}
	catch(e){}
}
function PerformPleaseWait()
{
	//var keyChar = (window.event)? event.keyCode : event.which;
	//if(keyChar == 13)
	//{
	//	var defaultButtonSetting = DefaultButtons[0].split(";");
	//	var re = new RegExp (':', 'gi') ;
	//	var newstr = defaultButtonSetting[1].replace(re, '_') ;
	//	if ( defaultButtonSetting.length != 3 ) { return; }
	//	//alert(newstr);
	//	var inputControl = document.getElementById(newstr);
	//	inputControl.click();
	//	//document.all.imageSRC.src = document.all.imageSRC.src;
	//	//_ctl0:_ctl2:imgbtnSearch
	//}
	return true;		
}
/****************************************************************/

// This function determines if the string passed in is a valid
// US zip code.  It accepts either ##### or #####-####.  If the
// string is valid, it returns true, else false.

function isZipcode(strZip)
{
	var s = new String(strZip);

	if (s.length != 5 && s.length != 10)
		// inappropriate length
		return false;


	for (var i=0; i < s.length; i++)
		if ((s.charAt(i) < '0' || s.charAt(s) > '9') && s.charAt(i) != '-')
			return false;

	return true;
}
function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}
function GetDiv(sDiv)
{
	var div;
	if (document.getElementById)
		div = document.getElementById(sDiv);
	else if (document.all)
		div = eval("window." + sDiv);
	else if (document.layers)
		div = document.layers[sDiv];
	else
		div = null;

	return div;
}
function HideDiv(sDiv)
{
	d = GetDiv(sDiv);
	if (d)
	{
		if (document.layers) d.visibility = "hide";
		else d.style.visibility = "hidden";
	}
}
function PleaseWait(sHide,sShow )
{
	sHide.style.display = "none";
	sShow.style.display = ""
	
}
function setFocus()
{
	try
	{
		defaultFocus.focus();
	}
	catch (ex)
	{
		//alert(defaultFocus);
	}
}
function SetHeaderTxt()
{
	//alert(HeaderTxt);
	if(HeaderTxt != '')logo_txt.innerHTML = HeaderTxt;
}

function setFormValuesDialog(ctrlName,ctrl)
{

	if(dialogArguments.frmCtrlsIDs.length>0)
			for(j=0;j < dialogArguments.frmCtrlsIDs.length; j+=1)
			{
				if(dialogArguments.frmCtrlsIDs[j] == ctrlName)
					{
						ctrl.value = dialogArguments.document.getElementById(dialogArguments.frmCtrls[j]).value;
						break;
					}
					
			}
	
}
//Writes the values back to the opening form
function setFormValues(ctrlName,ctrl)
{

	if(window.opener.frmCtrlsIDs.length>0)
			for(j=0;j < window.opener.frmCtrlsIDs.length; j+=1)
			{
				if(window.opener.frmCtrlsIDs[j] == ctrlName)
					{
						ctrl.value = window.opener.document.getElementById(window.opener.frmCtrls[j]).value;
						break;
					}
					
			}
	
}
function SumArray(ary1)
{
    var rtn = 0;
    for(i=0;i<ary1.length;i++)
        rtn+= parseInt(document.getElementById(ary1[i]).value);
   return rtn;
}

function setCatalogItems(ary1,returnCtrl)
{
	var rValue = '';
	var intAddedCount = 0;
	IsSubmitted = true;
    if(ary1.length>0)
		for(j=0;j < ary1.length; j+=3)
		{
			var item1,item2,item3
			if(!isNaN(parseInt(ary1[j].value)))
			{
				if((j<ary1.length) && (intAddedCount!=0))
				{
					rValue += ",";
				}
	    		if(typeof(ary1[j].value)=="undefined")
					item1 = ary1[j];
				else
					item1 = ary1[j].value;
				if(typeof(ary1[j+1])=="object" && typeof(ary1[j+1].value)=="undefined")
					{
						item2 = ary1[j+1].innerHTML;
					}
				else if(typeof(ary1[j+1].value)=="undefined")
					item2 = ary1[j+1];
				else
					item2 = ary1[j+1].value;
				if(typeof(ary1[j+2].value)=="undefined")
					item3 = ary1[j+2];
				else
					item3 = ary1[j+2].value;
				rValue += item1 + '~' + item2 + '~' + item3;
				//alert(rValue);
				intAddedCount += 1;
			}
			
	//alert(rValue);
	returnCtrl.value = rValue;
	}
}
function reValidateDate(controltovalidate) 
{
	
	var oDate = controltovalidate;
	var sDate = oDate.value;

if(sDate != "" )	  
	if(validate_date(controltovalidate,"Date"))
	{
		if(isitToday(oDate.value,3))
			return true;
		else
			alert("Please enter a future date");
			controltovalidate.focus();
			return false;
	}
else
	return true;
}

function showLookUp(i,r,url,options, height, width,pop)
{
   if(!height)height=400;
   if(!width)width=550;

//    var x_win = window; 
//    var win2
//    if(x_win.parent.popup == "undefined")
//        while(x_win.parent.popup == "undefined") 
//        { 
//            x_win = x_win.parent;
//        } 
        
    ShowPop(window.top.popup,url,'lookwin',width,height);
//    var iframeElement = window.top.popup.GetWindowContentIFrame(window.top.popup.GetWindowByName('lookwin'));
//    iframeElement.contentWindow.name = "myWindow";
//    var frameIndex = GetFrameIndexByWindowName("myWindow");
//    if(frameIndex > -1)
//         win2 = window.top.frames[frameIndex];

    var iframeElement2 = window.top.popup.GetWindowContentIFrame(window.top.popup.GetWindowByName('defpop'));
    iframeElement2.contentWindow.name = "myWindow2";
    var frameIndex2 = GetFrameIndexByWindowName("myWindow2");
    window.top.mRef = r;
    window.top.mId = i; 
    window.top.mWin = frameIndex2;
    
}
function GetFrameIndexByWindowName(name){
  var count = window.top.frames.length;
for(var i = 0; i < count; i++){
       if(window.top.frames[i].window.name == name)
        return i;
}
return -1;
}

function PopWindow(pop)
{

}
function refreshParent(e)
{
window.top.popup.RefreshWindowContentUrl(window.top.popup.GetWindowByName(e));
//window.top.popup.GetWindowByName(e).GetContentIFrame().contentWindow.location.reload(true);
}
function ShowPop(pop, url, popname, width, height, title)
{
    if(!popname)popname = 'defpop';
    if(!height)height=350;
    if(!width)width=300;
    if(!title)title="";
    var newpop = pop.GetWindowByName(popname);
    pop.SetWindowSize(newpop,width,height)
    pop.SetWindowContentUrl(newpop,url);
    newpop.SetHeaderText('<span class="popWindowTitle">' + title + '</span>');
    pop.ShowWindow(newpop);
    //window.top.popup.RefreshWindowContentUrl('defpop');
    return newpop;

}
function ShowMessageWindow(popelement,content,contenURL, width, height, title)
{
    var pop = window.top.messagePop;
    var popname = 'messagePop';
   
    if(!height)height=200;
    if(!width)width=400;
    if(!title)title="";
    if(content!="")
        pop.SetContentHtml(content);
    if(contenURL != "")
        pop.SetContentUrl(contenURL);
    pop.SetWindowSize(pop,width,height);
    pop.SetHeaderText('<span class="popWindowTitle"><b>' + title + '</b></span>');
    pop.Show();
}

function ShowToolTip(popelement,content,contenURL, width, height, title)
{
    var pop = window.top.toolpop;
    var popname = 'toolwin';
   
    if(!height)height=350;
    if(!width)width=300;
    if(!title)title="";
    if(content!="")
        pop.SetContentHtml(content);
    if(contenURL != "")
        pop.SetContentUrl(contenURL);
    pop.SetSize(width,height)
    pop.SetHeaderText('<span class="popWindowTitle">' + title + '</span>');
    pop.SetPopupElementID(popelement);
    pop.Show();
    pop.Target = "_top";
    //pop.ShowWindowAtElementByID(newpop,popelement); 
}
function checkOrder(msg)
{
	return confirm(msg);
}
function check()
{
	return confirm("Are you sure you want to cancel the current Order?");
}

function checkResume()
{
	return confirm("There are items in your current order.\nThese items will be removed, Continue?");
}

function OpenCalendar(Src)
{
	popUp = openCentered("controls/Calendar.aspx?src=" + Src, 'popupcal', 180,250);
}

function FilterNumeric(evt)
{
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt)
    {
        var charCode = (evt.charCode) ? evt.charCode :((evt.keyCode) ? evt.keyCode :((evt.which) ? evt.which : 0));
        var ch = String.fromCharCode(charCode);
        if(charCode == 13){
            if (window.event) 
                evt.returnValue = false;
            else 
                evt.preventDefault();
            return false;
            }
        if (charCode < 32)
        {
            return true;
        }
        if(charCode == 46)
            return true;
        if((charCode <= 57) && (charCode >= 48))
        {
            if (!evt.shiftKey)
            {
                return;
             }
        }
        if ((ch=='" + NumberFormatInfo.CurrentInfo.NegativeSign + "') || (ch=='" + NumberFormatInfo.CurrentInfo.NumberDecimalSeparator + @"'))
        {
           return;
        }
        
        if (window.event) 
            evt.returnValue = false;
        else 
            evt.preventDefault(); 
        return false;
    }
}

function NumberBoxKeyPress(event, dp, dc, n)
{
    return FilterNumeric(event);
    var ie = (window.event)? true: false;
    var srcElement = event.srcElement ? event.srcElement : event.target; 
	var myString = new String(srcElement.value);
	var pntPos = myString.indexOf(String.fromCharCode(dc));
	var keyChar = (window.event)? event.keyCode: event.which;
		if(keyChar != 13 && keyChar != 0 && keyChar != 8)
		{
			if ((keyChar >= 48 && keyChar <= 57) || (keyChar > 96 && keyChar <=105))
			    return true;
			else
			{
				if (keyChar == dc)
				{
					if ((pntPos != -1) || (dp < 1)) 
					{
						alert("Please enter only numeric values.");
						return false;
					}
					else 
						if((pntPos == -1) && (dp > 0)) 
						{
							return true;
						}
				}
				else 
					if (((keyChar == 45) && (!n || myString.length != 0)) || (keyChar != 45)) 
						{
							alert(" Please enter only numeric values.");
							
							return false;
						}
			}
		return EnterTabKeyPress(event);
		}
		return false;
	}


function validateItem()
{
	var editField
	for(i=0; i<aryRequired.length; i++)
	{
		try
		{
			editfield = aryRequired[i];
			if(editfield && Left(editfield.id,1)== "_" )
		    {
		        if((Trim(editfield.value) == "")||(editfield.value == null)||(editfield.value =="undefined"))
		        {
			        alert(aryMessage[i]);
			        try
			        {
				        editfield.focus();
			        }
			        catch (ex1){}
			        return false;
		        }
		    }
		    else
		    {
                if(editfield)
		        //Date
		            if(editfield.GetDate() == null || editfield.GetDate() == 'undefined')
		            {
		                alert(aryMessage[i]);
		                return false;
		            }
		    }
        }
		catch (ex)
		{
		    alert(ex);
			return false;
			//Field does not exist on page
		}
	}
	return true;
}
function validateForm(aRequired,aMessage)
{
	var editField
	for(i=0;i<aRequired.length;i++)
	{
		try
		{
		    //alert(editfield.id + " " + editfield.value);
			editfield = aRequired[i];
			if(editfield != null)
				if((Trim(editfield.value) == "")||(editfield.value == null)||(editfield.value =="undefined"))
				{
					alert(aMessage[i]);
					try
					{
						editfield.focus();
					}
					catch (ex1){}
					return false;
				}
		}
		catch (ex)
		{
			//Field does not exist on page
			//alert(ex);
		}
	}
	return true;
}

function ValidateString(event, RefString)  
{
	var InString = new String(event.srcElement.value);
	var keyChar = (window.event)? event.keyCode : event.which;

    //if(InString.length==0) return (true);
    //for (var Count=0; Count < RefString.length; Count++)  
    //{
    
  		//if(String.fromCharCode(keyChar)
        //var TempChar = InString.substring(Count, Count+1);
		if (RefString.indexOf (String.fromCharCode(keyChar), 0)> -1)  
		{
			alert("This field can not contain " + RefString );
			return (false);
		}
	//	}
	//}
   return (true);
}
function CheckNumber(buttonId){
	var reg = /^[0-9]+$/;
	if(!reg.test(buttonId.value))
	{
		alert("The value must be an integer number");
		return false;
	}

	return true;	
}
var whitespace = " \t\n\r";

/****************************************************************/

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
    //Response.Write(s)

}

/****************************************************************/
function isWhitespace (s)

{   var i;
    var bolEmpty = false;
    // whitespace characters
    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);

    if (whitespace.indexOf(c) != -1)
    {
		return true;
	}
	}
    
    // All characters are whitespace.
    return false;
}
function Trim(str)
{
        return RTrim(LTrim(str));
}
function RTrim(str)
{
        var swhitespace = new String(" \t\n\r");
        var s = new String(str);
        if (swhitespace.indexOf(s.charAt(s.length-1)) != -1) {
            var i = s.length - 1;       // Get length of string
            while (i >= 0 && swhitespace.indexOf(s.charAt(i)) != -1)
                i--;
            s = s.substring(0, i+1);
        }
        return s;
}
function LTrim(str)
{
        var swhitespace = new String(" \t\n\r");
        var s = new String(str);
        if (swhitespace.indexOf(s.charAt(0)) != -1) {
            var j=0, i = s.length;
            while (j < i && swhitespace.indexOf(s.charAt(j)) != -1)
                j++;
            s = s.substring(j, i);
        }
        return s;
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// The following functions were written by Tom Wittbrodt
// Copyright (c) 1998, 1999 Tom Wittbrodt
// License is granted if and only if this entire 
// copyright notice is included. 
function validate_date(date_field, desc) {
        if (!date_field.value)  
                return true;
        var in_date = stripCharString(date_field.value," ");
        in_date = in_date.toUpperCase();
        var date_is_bad = 0;  
        if (!allowInString(in_date,"/0123456789"))
                date_is_bad = 1; // invalid characters in date
        if (!date_is_bad) { 
                var has_rdi = 0;
                if (in_date.indexOf("T") >= 0){ 
                        has_rdi = 1;
                }
                if (!date_is_bad && has_rdi && (in_date.indexOf("T") != 0)) { 
                        date_is_bad = 2; // relative date index character is not in first position
                }
                if (!date_is_bad && has_rdi && (in_date.length == 1)) { 
                        var d = new Date();
						var return_month = parseInt(d.getMonth() + 1).toString();
						return_month = (return_month.length==1 ? "0" : "") + return_month; 
						var return_date =  parseInt(d.getDate()).toString();
						return_date = (return_date.length==1 ? "0" : "") + return_date; 
				        in_date = return_month + "/" + return_date + "/" + get_full_year(d);		
                        has_rdi = 0; // date doesn't have rdi char anymore (will also cause failure of add'l rdi checks, which is a good thing)
                }
                if (!date_is_bad && has_rdi && (in_date.length > 1) && !(in_date.charAt(1) == "+" || in_date.charAt(1) == "-")) {
                        date_is_bad = 3; // length of rdi string is greater than 1 but second char is not "+" or "-"
                }
                if (!date_is_bad && has_rdi && isNaN(parseInt(in_date.substring(2,in_date.length),10))) {
                        date_is_bad = 4; // rdi value is not a number
                }
                if (!date_is_bad && has_rdi && (parseInt(in_date.substring(2,in_date.length),10) < 0)) {
                        date_is_bad = 5; // rdi value is not a positive integer
                }
                if (!date_is_bad && has_rdi) {
                        var d = new Date();
                        ms = d.getTime();
                        offset = parseInt(in_date.substring(2,in_date.length),10);
                        if(in_date.charAt(1) == "+") {
                                ms += (86400000 * offset);
                        } else {
                                ms -= (86400000 * offset);
                        }
                        d.setTime(ms);
						var return_month = parseInt(d.getMonth() + 1).toString();
						return_month = (return_month.length==1 ? "0" : "") + return_month; 
						var return_date =  parseInt(d.getDate()).toString();
						return_date = (return_date.length==1 ? "0" : "") + return_date; 
				        in_date = return_month + "/" + return_date + "/" + get_full_year(d);	
                        has_rdi = 0;
                }
        } 
        if (!date_is_bad) {
                var date_pieces = new Array();
                date_pieces = in_date.split("/");
                if (date_pieces.length == 2) {
                        var d = new Date();
                        in_date = in_date + "/" + get_full_year(d);
                        date_pieces = in_date.split("/");
                }
                if (date_pieces.length != 3 || parseInt(date_pieces[0],10) < 1 || parseInt(date_pieces[0],10) > 12 
                                || parseInt(date_pieces[1],10) < 1 || parseInt(date_pieces[1],10) > 31 
                                || (date_pieces[2].length != 2 && date_pieces[2].length != 4)) {
                        date_is_bad = 6;  // date is not in format of m[m]/d[d]/yy[yy]
                }
        }
        if (date_is_bad) {
                alert("Date must be in the format of mm/dd/yy, mm/dd/yyyy.");
                date_field.focus();
                return (false);
        }
        
        var ms = Date.parse(in_date);
        var d = new Date();
        d.setTime(ms);
		var return_date = d.toLocaleString();
		var return_month = parseInt(d.getMonth() + 1).toString();
		return_month = (return_month.length==1 ? "0" : "") + return_month; 
		var return_date =  parseInt(d.getDate()).toString();
		return_date = (return_date.length==1 ? "0" : "") + return_date; 
        return_date = return_month + "/" + return_date + "/" + get_full_year(d);
        date_field.value = return_date;
        return true;
}       // normalize the year to yyyy

function get_full_year(d) {
		var y = ""
		if (d.getFullYear() != null)
		{
			y = d.getFullYear();
			if (y < 1970) y+= 100;		
		} else
		{	
	        y = d.getYear();
	        if (y > 69  && y < 100) y += 1900;
	        if (y < 1000) y += 2000;
		}
        return y;
}
// The following functions were written by Gordon McComb
// More information can be found here: http://www.javaworld.com/javaworld/jw-02-1997/jw-02-javascript.html
function stripCharString (InString, CharString)  {
        var OutString="";
   for (var Count=0; Count < InString.length; Count++)  {
        var TempChar=InString.substring (Count, Count+1);
      var Strip = false;
      for (var Countx = 0; Countx < CharString.length; Countx++) {
        var StripThis = CharString.substring(Countx, Countx+1)
         if (TempChar == StripThis) {
                Strip = true;
            break;
         }
      }
      if (!Strip)
        OutString=OutString+TempChar;
   }
        return (OutString);
}
function allowInString (InString, RefString)  {
        if(InString.length==0) return (false);
        for (var Count=0; Count < InString.length; Count++)  {
        var TempChar= InString.substring (Count, Count+1);
      if (RefString.indexOf (TempChar, 0)==-1)  
        return (false);
   }
   return (true);
}
function isitToday(dateString,dateType) 
{
var now = new Date();
var FY = parseInt(now.getYear());
var FM = parseInt(now.getMonth() + 1);
var d  = now.getDate();
var FD = (d < 10) ? '0' + d : d;
FD = parseInt(FD);

var YE = parseInt(Trim(dateString).substring(6,10));
var ME = dateString.substring(0,2);
if(ME.substring(0,1)==0)
{
	ME = ME.substring(1,2);
}
var DE = dateString.substring(3,5);
if(DE.substring(0,1)==0)
{
	DE = DE.substring(1,2);
}
DE=parseInt(DE);
ME=parseInt(ME);
 
   	if(FY< YE)
   		return true;
   	else
   		if(FY==YE)
   			if(FM < ME)
   				return true;
   			else
   				if(FM==ME)
   					if(FD<DE)
   					   return true;
   					else
   						if(FD==DE)
   							return true;
   						else if(FD>DE)
   							return false;
   						else
   							return false;
   				else
   					return false;
   		else
   			return false;	
   	
   	return false;
  
}



function changeImage3(imgSrc,imgObj)
{
	imgObj.src = imgSrc;
}

function changeImage(imgName,imgObj) { 
	if (document.images) 
	{ 
		document.images[imgName].src = eval(imgObj+".src") 
	}
}

function changeImage2(imgName,imgObj) { 
	if (document.images) 
	{ 
		imgName.src = eval(imgObj+".src") 
	}
}

<!-- Clock in Java Script .. Cameron Gregory  http://www.bloke.com/
// http://www.bloke.com/javascript/Clock/
var dateform
speed=1000
len=28
tid = 0;

function dodate()
{
  //f.innerHTML=new Date();
  ShowTimeandDate(f);
  tid=window.setTimeout("dodate()",speed);
}
 
function start(x) {
  f=x
  tid=window.setTimeout("dodate()",speed);
}
 
function cleartid() {
  window.clearTimeout(tid);
}
 
// for some reason on some pages this crashes netscape
function Clock()
{
document.write('<span id="date" name="date" size=')
document.write(len)
document.write(' ></span')
start(date);
}
// end-->



function ShowTimeandDate(x)
{
var thetime=new Date();

var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var nday=thetime.getDay();
var nmonth=thetime.getMonth();
var ntoday=thetime.getDate();
var nyear=thetime.getYear();
var AorP=" ";

if (nhours>=12)
    AorP="P.M.";
else
    AorP="A.M.";

if (nhours>=13)
    nhours-=12;

if (nhours==0)
   nhours=12;

if (nsecn<10)
 nsecn="0"+nsecn;

if (nmins<10)
 nmins="0"+nmins;

if (nday==0)
  nday="Sunday";
if (nday==1)
  nday="Monday";
if (nday==2)
  nday="Tuesday";
if (nday==3)
  nday="Wednesday";
if (nday==4)
  nday="Thursday";
if (nday==5)
  nday="Friday";
if (nday==6)
  nday="Saturday";

nmonth+=1;

if (nyear<=99)
  nyear= "19"+nyear;

if ((nyear>99) && (nyear<2000))
 nyear+=1900;

x.innerHTML=nhours+": "+nmins+": "+nsecn+" "+AorP+" "+nday+", "+nmonth+"/"+ntoday+"/"+nyear;

//setTimeout('startclock()',1000);

} 

 
 //Array methods
if (!Array.prototype.indexOf){  
Array.prototype.indexOf = function(elt /*, from*/)  {    
var len = this.length;    
var from = Number(arguments[1]) || 0;    
from = (from < 0)? Math.ceil(from): Math.floor(from);    
if (from < 0) from += len;    
    for (; from < len; from++)   
     {      
     if (from in this && this[from] === elt)
             return from;    
     }
     return -1;  };
 }
 


 function addItemToArray(ary,item)
 {
    var index = -1;
    for(i=0;i<ary.length;i++)
        {
            if(item.id == ary[i].id)
                {
                    index = i;
                    break;
                }
        }
    if(index == -1)
     ary[ary.length] = item;
    // alert(index);
 }
 
 function removeItemFromArray(ary,item)
 {
    ary.splice(item,1);
 }
 function removeRequiredField(fld)
 {
    var itemIndex = 0 //aryRequired.indexOf(item);
    var index = -1;
    for(i=0;i<aryRequired.length;i++)
        {
            if(fld.id == aryRequired[i].id)
                {index = i;break}
        }
        if(index>-1)
        {//alert('remove index ' + index);
            removeItemFromArray(aryRequired,index);
             removeItemFromArray(aryMessage,index);
        }
    
 }
  function addRequiredField(fld, message)
 {
    addItemToArray(aryRequired,fld);
    addItemToArray(aryMessage,message);
 }



var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
 	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
