var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var isMozilla = (document.getElementById && navigator.appName == "Netscape")? true:false;

function MM_swapImgRestore() { //v3.0 
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
x.src=x.oSrc; } 

function MM_preloadImages() { //v3.0 
var d=document; if(d.images){ 
if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new 
Image; d.MM_p[j++].src=a[i];}} } 

function MM_findObj(n, d) { //v3.0 
var p,i,x; 
if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) 
{ d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) 
x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
x=MM_findObj(n,d.layers[i].document); return x; } 

function MM_swapImage() { //v3.0 
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
for(i=0;i<(a.length-2);i+=3) 
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; 
if(!x.oSrc) x.oSrc=x.src; 
x.src=a[i+2];} }

//*************************************************************************************
// trim - this function deletes spaces around the string.
//*************************************************************************************
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

	function OpenWin(sFileName,wwidth,wheight,window_name,bScroll,bResizable)
	{
	if(window_name=='') { window_name='justawindow'; }
	if(wwidth=='') { wwidth=600; }
	if(wheight=='') { wheight=700; }
	if(bScroll=='' ) { bScroll='yes'; }
	if(bResizable=='') { bResizable='no'; }
	ww=screen.width;
	hh=screen.height;
	if(wwidth>ww) { xx=0;} else {xx=Math.round((ww-wwidth)/2)-5; }
	if(wheight>hh) { yy=0;} else { yy=Math.round((hh-wheight)/2); }
	options='location=no, toolbar=no, status=no, left='+xx+', top='+yy+', menubar=no, height='+wheight+', width='+wwidth+', scrollbars ='+bScroll+', resizable='+bResizable+'';
	file=sFileName;
	window.open(file,window_name,options);
	}	

function GetNumbersAndLetters(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch >= 1488 && ch <= 1513) );
}


function getNumbers(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || ch ==46);
}

function checkEmail(checkThisEmail){

//  return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
   //return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}


return myEMailIsValid

}

/*CHECK PHONE NUMBER*/

// 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 = 9;

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 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 checkPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
/*END ofPHONE CHECHING*/

//Calendar function
function DoCal(elTarget) {
//alert('1')
  if (window.showModalDialog) {
  //alert('2')

    var sRtn;
    sRtn = showModalDialog("../include/calendar.asp",elTarget.value,"center=yes; dialogWidth=110pt; dialogHeight=144pt; status=0; help=0;");
    if (sRtn!="")
      elTarget.value = sRtn;
  } else
  {
  //alert('3')
  if(window.event)
  {
	x=window.event.x
	y=window.event.y
  }
  else
  {
	if( document.captureEvents ) {
		document.captureEvents( Event.KEYUP );
	}

	if (e.pageX) 
	{ // NS 4, Mozilla
		x = e.pageX;
		y = e.pageY;
	} 
	else { // IE, Opera
		var root = document.documentElement || document.body;
		x = e.clientX - root.scrollLeft;
		y = e.clientY - root.scrollTop;
	}
	
	window.captureEvents(Event.MOUSEMOVE); 
 }
  //alert('4')
	sRtn=window.open("../include/calendar.asp?f="+elTarget.name,"sRtn","top="+y+",left="+x+",width=110pt,height=134pt,scrollbars=no,resizable=no,toolbar=no,status=no,titlebar=no,modal=yes'")
  }
 return false;
 window.document.focus;   
}

//Calendar function
function DoCalAdm(elTarget) {
  if (showModalDialog) {
    var sRtn;
    sRtn = showModalDialog("../../include/calendar.asp",elTarget.value,"center=yes; dialogWidth=110pt; dialogHeight=134pt; status=0; help=0;");
    if (sRtn!="")
      elTarget.value = sRtn;
  } else
    alert("Internet Explorer 4.0 or later is required.")
 return false;
 window.document.focus;   
}

