function our_confirm (param)
	{
		confirm (param);
	}

	function show_win(url,XX,YY){
		text = 'scrollbars=yes,resizable=yes,status=yes,width=' + XX + ',height=' + YY;
		var qWnd = window.open(url,"",text);
		if ((document.window != null) && (!qWnd.opener))
		qWnd.opener = document.window;
		qWnd.focus();
	}


	function show (url,XX,YY)
	{
		var text;
		text = 'scrollbars=1,resizable=1,status=yes,width=' + XX + ',height=' + YY;
		newwin=window.open(url,'_blank',text);
	}

	
	function PreviewPicture(picture, XX, YY) {
		XX1 = XX + 35;
		YY1 = YY + 130;
		text = 'scrollbars=1,resizable=1,status=0,width=' + XX1 + ',height=' + YY1;
    	prevWnd=window.open("", "prvw", text);
	    prevWnd.document.open();
	    prevWnd.document.writeln('<html><title>Picture Preview</title><body bgcolor=#ffffff><font size=+1 face="Verdana,Helvetica" ><b>Picture Preview</b></font>&nbsp;&nbsp;&nbsp;<a href="javascript:window.close()">Close</a><p><hr noshade width="100%">');
	    prevWnd.document.writeln('<img src=' + picture + ' alt= border=0 width=' + XX + ' height=' + YY + '>');
	    prevWnd.document.writeln('</body></html>');
	    prevWnd.document.writeln('<BR>');
	    prevWnd.document.close();
	}


function CheckTime(THISTIME) {
	var err=0
	a=THISTIME.value
	if ((a.length != 5)||(a.length != 0)) err=1
	b = a.substring(3, 5)// minutes
	c = a.substring(2, 3)// SA_NLS_TM_SEP
	d = a.substring(0, 2)// hours
	e = a.substring(5, 6)// SA_NLS_TM_SEP
	//f = a.substring(6, 8)// seconds
	if (b<0 || b>60 ) err = 1
	if (d<0 || d>24) err = 1
	//if (f<0 || f>60 ) err = 1
		
	if (err==1) {
		alert('\'' + THISTIME.value + '\'' + ' is not a valid time format. Please re-enter in format in HH:Mi' );
		THISTIME.value = "";
	}
}

function FormatHour(i, delKey,direction) {
  if (i.value.length < 2) {
  	if (delKey!=2) { //tab
	  	if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41)){ //if the delete, backspace, shift, are not the keys that caused the keyup event.
  			var fieldLen = i.value.length
   			if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) {
   				
   			} else {
   				if (direction == "up") {
     				if (i.value.length == 0) {
      					i.value = ""
	     			} else {
		      			i.value = i.value.substring(0,i.value.length-1)
	   				}
    			}
	 		}
  			i.focus()
	  	}
 	} else {
 		if (direction == "down") {
	 		CheckHour(i)
  		}
  	}
 }
}

function CheckHour(THISTIME) {
	var err=0
	a=THISTIME.value
	
	if (a>12 ) err = 1
	
	if (err==1) {
		alert('\'' + THISTIME.value + '\'' + ' is not a valid hour. Please re-enter input a number from 1 - 12' );
		THISTIME.value = "";
	}
}

function FormatMi(i, delKey,direction) {
  if (i.value.length < 2) {
  	if (delKey!=2) { //tab
	  	if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41)){ //if the delete, backspace, shift, are not the keys that caused the keyup event.
  			var fieldLen = i.value.length
   			if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) {
   				
   			} else {
   				if (direction == "up") {
     				if (i.value.length == 0) {
      					i.value = ""
	     			} else {
		      			i.value = i.value.substring(0,i.value.length-1)
	   				}
    			}
	 		}
  			i.focus()
	  	}
 	} else {
 		if (direction == "down") {
	 		CheckMi(i)
  		}
  	}
 }
}

function CheckMi(THISTIME) {
	var err=0
	a=THISTIME.value
	
	if (a>59 ) err = 1
	
	if (err==1) {
		alert('\'' + THISTIME.value + '\'' + ' is not a valid minite. Please re-enter input a number from 0 - 59' );
		THISTIME.value = "";
	}
}

function CheckDate(THISDATE) {
	var err=0
	a=THISDATE.value
	if (a.length != 10) err=1
	b = a.substring(3, 5)// month
	c = a.substring(2, 3)// SA_NLS_DT_SEP
	d = a.substring(0, 2)// day
	e = a.substring(5, 6)// SA_NLS_DT_SEP
	f = a.substring(6, 10)// year
	if (b<1 || b>12) err = 1
	if (d<1 || d>31) err = 1
	if (f<1900) err = 1
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1
	}
	if (b==2){
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}
		if (d>29) err=1
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1
	}
	if (err==1) {
		alert(THISDATE.value + ' is not a valid date. Please re-enter in format .');
		THISDATE.value = "";
	}
}

 function getkey(e)
 {
   if (window.event)
   {
     return window.event.keyCode;
   }
   else if (e)
   {
      return e.which;
   }
   else
   {
      return null;
   }
 }

	function checkNames(e, goodkeys, msg)
 {
   var key, keychar;
   key = getkey(e);
   if (key == null) 
   {
     return true;
   }

   // get character
   keychar = String.fromCharCode(key);
   
   // check goodkeys
   if (goodkeys.indexOf(keychar) != -1 )
   {
   	return true;
   }

   // control keys
   if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   {
      return true;
   }

   // else return false
   alert (msg);
   return false;
 }


 function checkgoodkey(e, goodkeys, msg)
 {
   var key, keychar;
   key = getkey(e);
   if (key == null) 
   {
     return true;
   }

   // get character
   keychar = String.fromCharCode(key);
   
   // check goodkeys
   if (goodkeys.indexOf(keychar) != -1)
   {
   	return true;
   }

   // control keys
   if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   {
      return true;
   }

   // else return false
   alert (msg);
   return false;
 }

 function checkgoodkeys(e, goodkeys)
 {
   var key, keychar;
   key = getkey(e);
   if (key == null) 
   {
     return true;
   }

   // get character
   keychar = String.fromCharCode(key);
   keychar = keychar.toLowerCase();
   goodkeys = goodkeys.toLowerCase();

   // check goodkeys
   if (goodkeys.indexOf(keychar) != -1)
   {
   	return true;
   }

   // control keys
   if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   {
      return true;
   }

   // else return false
   alert ("Invalid key pressed - only numbers are allowed");
   return false;
 }


function emailCheck (emailStr) {
var checkTLD=1;

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
}

var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		alert("Ths username contains invalid characters.");
		return false;
	   }
}
for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
return false;
   }
}

if (user.match(userPat)==null) {
	alert("The username doesn't seem to be valid.");
	return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address
for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
return false;
   }
}


if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
	alert("This address is missing a hostname!");
	return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function isFutureDate(fd){
	//the string fd must be in format dd/mm/yyyy
	yyyy = parseInt(fd.substr(6,4),10);
	mm = parseInt(fd.substr(3,2),10)-1;
	dd = parseInt(fd.substr(0,2),10);
	
	if (isNaN(yyyy) || isNaN(mm) || isNaN(dd)){
		//error case
		return false;
	}
	
	user_date = new Date(yyyy,mm,dd,0,0,0);
	today_date = new Date();
	
	if (user_date > today_date){
		//future case
		alert("Date has a future value.");
		return true;
	}else{
		alert("Date has not a future value.");
		return false;
	}
}

function printIsNativeSupport() {
	var agent = window.navigator.userAgent;
	var i = agent.indexOf("MSIE ")+5;
	return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFrame(frame) {
	if ( !frame ) frame = window;

	if ( frame.document.readyState !== "complete" && !confirm("The document to print is not downloaded yet! Continue?")){
    	return;
	}

	if ( printIsNativeSupport() ) {
		var focused = document.activeElement; 
		frame.focus();
	    frame.self.print();
	return;
	}
}

function isFutureDate(fd){
	//the string fd must be in format dd/mm/yyyy
	yyyy = parseInt(fd.substr(6,4),10);
	mm = parseInt(fd.substr(3,2),10)-1;
	dd = parseInt(fd.substr(0,2),10)+5;
	
	if (isNaN(yyyy) || isNaN(mm) || isNaN(dd)){
		//error case
		return false;
	}
	
	user_date = new Date(yyyy,mm,dd,0,0,0);
	today_date = new Date();
	
	if (user_date > today_date){
		//future case
		return true;
	}else{
		return false;
	}
}

