// mel.js version 1.40 from 09/10/2004 
// ------------------------------------------------------------------
// convert string to trimed not-null string, ignoring spaces
function StoS(str_in) {
	var str_out = "";
	if ( (!str_in) || (str_in == null) || (trim(str_in) == "") ) { return str_out; }
	else { str_out = "" + trim(str_in); } 
	return str_out;		
} // end StoS
// ------------------------------------------------------------------------------
// convert string to integer, ignoring spaces & leading zeroes, & rounding up
function StoI(str) {
	str       = StoS(str);
	var i     = 0;
	if ( (str == "-") || (str == "+") ) { return i; }
	var flag1 = 0;
	var flag2 = 0;
	var flag3 = 0;
	var bad   = 0;
	if ( str != "" ) { // if zero
		FOR1: for (var k = 0; k < str.length; k++) { // FOR1
			var sub = str.substring(k,k+1);
			if ( sub == "-" ) { flag1++ ; continue FOR1; }
			else { // if "-"
				if ( (sub == "+") || (isNumeric(sub)) || (sub == ".") ) { 	
					if ( sub == "+" ) { flag2++; } 
					if ( sub == "." ) { flag3++; }	
					continue FOR1; 
				} else {
					bad = 1;
					break FOR1;
				} // end if "+"
			} // end if "-"
		} // end FOR1
		if ( (bad == 0) && (flag1 < 2) && (flag2 < 2) && (flag3 <2) ) { // if bad
			i = 1 * str;			
		} // end if bad 
	} // end if zero
	return 1*i;		
} // end StoI()
// -------------------------------------------------------------------------------
// convert number to string 
function ItoS(n_in) {
	var str_out = "";
	if ( n_in == 0 ) { return "0"; }
	if ( (n_in == null) || (trim(n_in) == "") ) { 
		return str_out; }
	else { 
		str_out =  "" +  trim(n_in); 
		} 
	return str_out;		
} // end ItoS
// ------------------------------------------------------------------------------
// convert number to number 
function ItoI(n_in) {
	if ( n_in == 0 ) { return "0"; }
	var n_out = 1 * 0;
	if ( (n_in == null) || (trim(n_in) == "") ) { return n_out; }
	else { n_out = 1 * StoI(ItoS(n_in)); } 
	return n_out;		
} // end ItoI
// ------------------------------------------------------------------------------
// check_date for valid date from format 2001-12-31  YYYY-MM-DD          
function isDate(str) {
var b = false;
	str = StoS(str);
	if ( (str != "") && (str.length == 10) ) { // if zero
		var YYYY = str.substring(0,4);
		var MM   = str.substring(5,7);
		var DD   = str.substring(8,10);
		if ( (str.substring(4,5) != "-") || (str.substring(7,8) != "-") || 
		(!isNum(YYYY)) || (!isNum(MM)) || (!isNum(DD)) ) { return b; } // if 1
		else { // else 1
			var y = StoI(YYYY);
			var m = StoI(MM);
			var d = StoI(DD);
			if ( (y > 2150) || (y < 1900) || (m > 12) || (m < 1) || (d > 31) || (d < 1) ) { return b; } // if 2
			else { // else 2
				if (((m == 4) || (m == 6) || (m == 9) || (m == 11)) && (d > 30)) {
					return b;  // if 3
				} else { 
					if ( (m == 2) && (d > 29) )	{ // if 29
						return b; 
					} else {
						if ( (m == 2) && (d > 28) && ( (y % 4) > 0) ) {
							return b;
						}
					} // end if 29
					b = true; 
				} // else if 3
			} // end if 2
		} // end if 1
	} // end if zero
	return b;
} // end isDate()
//-------------------------------------------------------------------------------
// check_dates validates if date range is valid for str-date in format
// yyyy-mm-dd ;  fromdate must be <= todate
function check_dates(fromday, frommonth, fromyear, today, tomonth, toyear) {
	var b = false;
	if ( !isDate(StoS(fromyear)+"-"+StoS(frommonth)+"-"+StoS(fromday)) || 
		!isDate(StoS(toyear)+"-"+StoS(tomonth)+"-"+StoS(today)) ) {return b;}// if 1
	else { // else 1
		var y1 = StoI(fromyear);
		var m1 = StoI(frommonth);
		var d1 = StoI(fromday);
		var y2 = StoI(toyear);
		var m2 = StoI(tomonth);
		var d2 = StoI(today);
		if ( (y1 > y2) || ((y1 == y2) && (m1 > m2)) || ((y1 == y2) && (m1 == m2) 
		  && (d1 > d2)) ) { return b; }
		b = true;
	} // end if 1
	return b;
} // end check_dates()
//----------------------------------------------------------------------------
// check_dates validates if date range is valid for str-date in format yyyy-mm-dd
// -10 (if wrong arg)  -1 (if fromdate < todate)  0 (if equal)  1 (fromdate > todate)
function check_dates_eq(fromday, frommonth, fromyear, today, tomonth, toyear) {
	var b = -10;
	if ( isDate(StoS(fromyear)+"-"+StoS(frommonth)+"-"+StoS(fromday)) && 
		isDate(StoS(toyear)+"-"+StoS(tomonth)+"-"+StoS(today)) ) { // if OK
		b      = -1;
		var y1 = StoI(fromyear);
		var m1 = StoI(frommonth);
		var d1 = StoI(fromday);
		var y2 = StoI(toyear);
		var m2 = StoI(tomonth);
		var d2 = StoI(today);
		if ( y1 >= y2 ) { // if y1>=
			if ( y1 == y2 ) { // if y1=
				if ( m1 >= m2 ) { // if m1>=
					if ( m1 == m2 ) { // if m1=
						if ( d1 >= d2 ) { // if d1>=
							if ( d1 == d2 ) { // if d1=
								b = 0; 
							} else { b = 1; } // end if d1=
						} // end if d1>=
					} else { b = 1; } // end if m1=
				} // end if m1>=
			} else { b = 1; } // end if y1=
		} // end if y1>=
	} // end if OK
	return b;
} // end check_dates_eq()
//----------------------------------------------------------------------------
// to determine if arg = Numeric
function isNum(numVal) {
	numVal = StoS(numVal);
	var b  = false;
	if ( numVal != "" ) { // if ""
	    for ( i = 0; i < numVal.length; i++ ) {
			if (numVal.charAt(i) < "0" || numVal.charAt(i) > "9") { return b; }
		} // end for;
		b = true;
	} // end if ""
	return b;
} // end isNum() 
// ------------------------------------------------------------------
// to determine if arg = Numeric or supplied add
function isNum(numVal, add) {
	numVal   = StoS(numVal);
	add      = StoS(add);
	var b    = false;
	var temp = "";
	if ( numVal != "" ) { // if ""
	    for ( i = 0; i < numVal.length; i++ ) {
			temp = numVal.charAt(i);
			if ( temp < "0" || temp > "9") { 
				if ( temp != add ) { return b; }
			}
		} // end for;
		b = true;
	} // end if ""
	return b;
} // end isNum() 
// ------------------------------------------------------------------
function isLetter(str) {
	var b = false;
	if ( (str != null) || ( !(trim(str) == "")) ) { // not zero or empty str
		str = trim(str).toUpperCase();
		if ( str == "A" || str == "B" || str == "C" || str == "D" || str == "E" || str == "F" || str == "G" || str == "H" || str == "I" || str == "J" || str == "K" || str == "L" || str == "M" || str == "N" || str == "O" || str == "P" || str == "Q" || str == "R" || str == "S" || str == "T" || str == "U" || str == "V" || str == "W" || str == "X" || str == "Y" || str == "Z" ) { b = true; }
	}
	return b;
} // end isLetter()
// -------------------------------------------------------------------		
// is letter case sensetive
function isLetter_case(str) {
	var b = false;
	str = StoS(str);
	if ( (str != null) || ( !(trim(str) == "")) ) { // not zero or empty str
		if ( str == "A" || str == "B" || str == "C" || str == "D" || str == "E" || str == "F" || str == "G" || str == "H" || str == "I" || str == "J" || str == "K" || str == "L" || str == "M" || str == "N" || str == "O" || str == "P" || str == "Q" || str == "R" || str == "S" || str == "T" || str == "U" || str == "V" || str == "W" || str == "X" || str == "Y" || str == "Z" ) { b = true; }
	}
	return b;
} // end isLetter_case()
// -------------------------------------------------------------------		
function ltrim(str_in) {
	str_in = "" + str_in;
	var str_out = "";
	var e = " ";
	if ( !((str_in == null) || (str_in == e) || (str_in == "")) ) { // if nul
		str_out = str_in;
		var len = str_out.length;
		var wlen = len;
		FOR1: for (var i=0; i< len; i++) {
			if (str_out.indexOf(e,0) == 0) { // if ==0
				if (wlen > 1) {	str_out = str_out.substr(1,wlen); 
				} else { break; }
			} else { break;  } // end if ==0
			wlen = str_out.length;
		} // end FOR1
	} // end if nul
	return str_out;
} // end ltrim()
// -----------------------------
function rtrim(str_in) {
	str_in = "" + str_in;
	var str_out = "";
	var e = " ";
	if ( !((str_in == null) || (str_in == e) || (str_in== ""))  ) { // if nul
		str_out = str_in;
		var len = str_out.length;
		var wlen = len;
		FOR1: for (var i=0; i< len; i++) {
			if (wlen > 1) { // if wlen>1
				if (str_out.indexOf(e,wlen-1) == wlen-1) {
					str_out = str_out.substr(0,wlen-1) 
				} else {
				 break; }
			} else { // else wlen>1
				if ( str_out == e ) { str_out = "";}
				break;
			} // end if wlen>1

			wlen = str_out.length;
		} // end FOR1
	} // end if nul
	return str_out;
} // end ltrim()
// -----------------------------
function trim(str_in) {
	var str_out = rtrim(ltrim(str_in));
	return str_out;
} // end trim()
// ------------------------------
function isNumeric(str) {
	var b = false;
	if ( (str != null) || ( !(trim(str) == "")) ) { // not zero or empty str
		str = trim(str);
		if ( str == "0" || str == "1" || str == "2" || str == "3"
		|| str == "4" || str == "5" || str == "6" || str == "7"
		|| str == "8" || str == "9" ) { b = true; }
	}
	return b;
} // end isNumeric()
// -------------------------------------------------------------------		
function isDecNumber(str_in) {
	var str_out   = ""; 
	var dots  = 0;
	var first = 0;
	var decs  = 0;
	var len   = 0;
	if ( (str_in == null) || (trim(str_in) == "") ) { // zero str_in
		str_out = ""; return false;
	} else {  // else zero
		str_out = trim(str_in);
		var sub = null;
		len = str_out.length; 
		var wlen = len;
		
		FOR1: for ( var i=0; i<len; i++) { // FOR1
		
			if (wlen > 1) { // if wlen>1
		
				sub = str_out.substring(0,1);
				
				if (isNumeric(sub)) { // if	isNum 						

					if (dots == 1) { decs++; }
					else { first++; }
				} else { // else isNum

					if ( sub == "." ) { // if .
						dots++;
						if (dots > 1) { return false; }
					} else { return false; } // end if .						
				} // end if-else isNum
	
				str_out = str_out.substr(1,wlen-1);

			} else { // else wlen >1
			
				sub = str_out;
				
				if (isNumeric(sub)) { // if	isNum2 	

					if (dots == 1) { decs++; }
					else { first++; }
				} else { // else isNum2

					if ( sub == "." ) { // if .
						dots++;
						if (dots > 1) { return false; }
					} else { return false; } // end if .						
				} // end if-else isNum2					
			
			str_out = "";						
			} // end wlen>1
	
			wlen = str_out.length;
		} // end FOR1:
	} // end if-else zero
	if ( (dots > 1) || ((dots == 1) && (first == 0) && (decs == 0)) ) { return false; }
	return true;
} // end IsDecNumber()	
// ----------------------------------------------------------------------
// to check if number supplied is valid decimal number 
// if qty_after_dot = 2:  1  1.  1.0  1.02 are valid   1.023 - invalid number
function isDecNumber(str_in, qty_after_dot) {

	str_in        = StoS(str_in);
	var str_out   = str_in; 
	var dots	  = 0;
	var first	  = 0;
	var decs	  = 0;
	var len		  = 0;

	if ( (str_in == null) || ( str_in == "" ) ) { // zero str_in
		return false;
	} else {  // else zero

		var sub          = null;
		len              = str_out.length; 
		var wlen         = len;
		var dot_position = str_in.indexOf("."); // position of 1st dot
		
		FOR1: for ( var i=0; i < len; i++ ) { // FOR1
		
			if (wlen > 1) { // if wlen>1
		
				sub = str_out.substring(0,1);
				
				if (isNumeric(sub)) { // if	isNum 						

					if (dots == 1) { decs++; }
					else { first++; }
				} else { // else isNum

					if ( sub == "." ) { // if .
						dots++;
						if (dots > 1) { return false; }
					} else { return false; } // end if .						
				} // end if-else isNum
	
				str_out = str_out.substr(1,wlen-1);

			} else { // else wlen >1
			
				sub = str_out;
				
				if (isNumeric(sub)) { // if	isNum2 	

					if (dots == 1) { decs++; }
					else { first++; }
				} else { // else isNum2

					if ( sub == "." ) { // if .
						dots++;
						if (dots > 1) { return false; }
					} else { return false; } // end if .						
				} // end if-else isNum2					
			
			str_out = "";						
			} // end wlen>1
	
			wlen = str_out.length;
		} // end FOR1:
	} // end if-else zero
	if ( (dots > 1) || ((dots == 1) && (first == 0) && (decs == 0)) ) { return false; }
	if ( (dots == 1) && (dot_position >= 0) ) { // if =1
		var how_far = (len - 1) - dot_position; // how far is dot from left side
		if ( how_far > qty_after_dot ) { return false; }
	} // end if =1
	return true;
} // end IsDecNumber(str, qty)	
// ----------------------------------------------------------------------
function isNumDot(numVal) {
    for (i = 0; i < numVal.length; i++) {
        if ( !isNumericDot(numVal.charAt(i)) ) { return false; }
	}
    return true;
} // to determine if arg = Numeric
// ------------------------------------------------------------------
// simple e-mail validation: to find @ within
function check_email(email) {
	var valid = 0;
	var reg  = new RegExp("@");
	if ( email != null && email.search(reg) > 0 ) {
		valid = 1;
	}
	return valid;
}
// ------------------------------------------------------------------
function IsEmailValid(email){
  var emailOk = true;
  var temp   = email;
  var atSym  = temp.value.indexOf('@');
  var dot1   = temp.value.indexOf('.');
  var dot2   = temp.value.lastIndexOf('.');
  var space  = temp.value.indexOf(' ');
  var length = temp.value.length - 1;	// Array is from 0 to length-1

  if ((atSym < 1) ||			// '@' cannot be in first position
      (dot2 <=  atSym+1) ||		// Must be at least one valid char btwn '@' and '.'
      (dot2   == length) ||		// Must be at least one valid char after '.'
      (space != -1)      ||			// No empty spaces permitted
	  (dot1 < 1)         ||      // no . or leading .
	  (length < 5) )             // min e-mail length
    {
      emailOk = false;
    }
  return emailOk;
}  // end of IsEmailValid()
// ------------------------------------------------------------------
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];}
}
//------------------------------------------------------------------------------------
// to display status msg
function MM_displayStatusMsg(msgStr) { //v2.0
	status = msgStr;
	document.MM_returnValue = true;
}
//------------------------------------------------------------------------------
// isCC # valid: CDRTN_01 check digit routine 01 = BPAY # W01M101F3
function isCreditCard(ref) {

	var b			= false;				// return result
	ref				= StoS(ref);
	var len			= ref.length;			// length    
	var checkDigit	= ref.charAt(len - 1);	// last cd
	var currDigit   = "";					// temp char
	var weight      = 0;					// weight
	var product     = 0;					// product 
	var sum         = 0;					// sum        

	//alert("ref=" + ref + "\nlen=" + len + "\ncheckDigit=" + checkDigit);

	if ( (ref != ("")) && (len >= 14) && (len <= 16) && isNum(ref) ) { // if OK

		var cctype = cardType(ref);

		if (  ( ((cctype == "Visa") || (cctype == "MasterCard") || (cctype == "Bankcard")) && (len != 16) ) ||  ( (cctype == "Amex") && (len != 15) ) || ( (cctype == "DinersClub") && (len != 14) ) ) { return b; }

		if ( ref.substring(0,10) == "0123456789") { return true; }
	
		for ( var i = 1; i < len; i++ ) {  // for i = counter

			currDigit = ref.charAt(len - 1 - i);

			// alert("in cycle i= " + i + " char at " + (len-1-i) + " currDigit=" + currDigit);

			if ( (i % 2) != 0 ) { // if rightmost or next odd

				weight = 2;

			} else { 

				weight = 1; 

			} // end if rightmost

			product = weight * currDigit;    

			// alert("weight=" + weight + "\nproduct=" + product);

			if ( 1 * product > 9 ) { // for 2-digits product

				sum = 1 * sum + 1 * 1 + (product % 10);
				// alert(" product=" + product + " > 9\nproduct % 10 =" + (product % 10) + "\nsum=" + sum);
	
			} else { 

				sum = 1 * sum + 1 * product; 
				// alert(" product=" + product + " < 9\nsum=" + sum);

			} // end if 2-digits product    

		} // end for i

		// alert("final sum=" + sum); 

		var remainder  = sum  % 10;
		var finalCheck = 0;

		if ( remainder == 0 ) { finalCheck = 0; }

		else {                  finalCheck = 10 - remainder; }

		// alert("remainder=" + remainder + "\nfinalCheck=" + finalCheck);

		if ( 1 * StoI(finalCheck) == 1 * StoI(checkDigit) ) { b = true; } 

	} // end if OK
	return b;
} // end isCreditCard()
//-------------------------------------------------------------------
// return true for valid Credit card #  VI & MC - ok, check on DI, AX, BA, rent c
function isCreditCard_old(str) {
	var b = false;
	str = trim(str);
	var len = str.length;
	if ( (str == null) || (str == ("")) || (len < 11) || (len > 17) || !isNum(str)) 
	{ return b; } 
	else { // else ""

	if ( str.substring(0,10) == "0123456789") { return true; }

  		a  = new Array;	c  = new Array;	
		a1 = new Array;	c1 = new Array;	a2 = new Array;

		var k = 0;
		for (var i=len-2; i >= 0 ; i--) {
			a[k] =  str.charAt(i);
			a1[k] = 2 * a[k];
			a2[k] = a1[k] + "";
			i--; k++;
		} 

		a1[k] = 0;
		a2[k] = "0";

		k = 0;
		for (var i=len-3; i >= 0 ; i--) {
			c[k]  = str.charAt(i);
			c1[k] = 1*c[k];
			i--; k++;
		} // end for
		c1[k] = 0;

		var sum = 0;
		for (var i=0; i < len/2 ; i++)
		{
			if ( a2[i].length == 2 ) { 
				var f1 = a2[i].substr(0,1);
				var f2 = a2[i].substr(1);
				a1[i] = 1*f1 + 1*f2;
			}
			sum = 0 + sum + a1[i] + c1[i];
		} // end for

		var sumS = "" + sum;
		var ss2  = "" + sumS.substr(0,1);
	
		var ss3 = 0;
		if (sumS.substring(1) == "0") { ss3 = 1*ss2; }
		else { ss3 = 1*ss2 + 1; }
			
		var first = 10 * ss3;
		var last_char = str.substr(len-1);

		if ( (first - sum ) == (1*last_char) ) { b = true; }

	} // end if ""
return b;
} // end isCreditCard_old()
//-------------------------------------------------------------------
// return selected value for element selectObject (<select>,<checkbox>, etc)
function getSelectedValue(selectObject) { 
	return selectObject.options[selectObject.selectedIndex].value;
} // end getSelectedValue()
//--------------------------------------------------------------------
// return credit card type from CC #, for non-defined = "". Carefull - work out with isCreditCard() required for correct card # + find out length of card
function cardType(ccno) { 
	var cardtype = "";
	ccno = StoS(ccno);
	if ( (ccno.length >= 14) && (ccno.length <= 16) ) { // if > 13

		SW: switch ( ccno.substring(0,1) ) { // switch main
			case "1" :
				cardtype = "JCB";
				break SW;
			case "2" :
                cardtype = "JCB";
				break SW;
            case "3" :

				SW2: switch ( ccno.substring(0,2) ) { // switch2
					case "30" :      
						cardtype = "DinersClub";
						break SW;
					case "36" :                        
						cardtype = "DinersClub";
						break SW;
					case "38" :                          
						cardtype = "DinersClub";
						break SW;
					case "34" :                         
						cardtype = "Amex";
						break SW;
					case "37" :                            
						cardtype = "Amex";
						break SW;
					case "35" :                        
						cardtype = "JCB";
						break SW;
				} // end switch2

				break;

				case "4" :
					cardtype = "Visa";
					break SW;	
				case "5" :
					if ( ccno.substring(0,4) == "5610" ) { // if 5610
						cardtype = "Bankcard";
						break SW;
					} else { // else 5610
						if ( ccno.substring(0,3) == "560" ) { 
							cardtype = "DebitCard";
							break SW;
						}
					} // end if 5610

					SW3: switch ( ccno.substring(0,2) ) { // switch3
						case "51" :      
							cardtype = "MasterCard";
							break SW;
						case "52" :                        
							cardtype = "MasterCard";
							break SW;
						case "53" :                        
							cardtype = "MasterCard";
							break SW;
						case "54" :                        
							cardtype = "MasterCard";
							break SW;
						case "55" :                       
							cardtype = "MasterCard";
							break SW;
						case "50" :                        
							cardtype = "DebitCard";
							break SW;
						default :
							cardtype = "DebitCard";
							break SW;
						
					} // end switch3
                  
				case "6" :
					cardtype = "Discover";
					break SW;
		} // end switch main
	} // end if > 13
	return cardtype;
} // end cardType()
//----------------------------------------------------------------
// get day as word from dd                      
function getDay(dd) {
	var day = "";
	dd      = prezero(dd, 2);      
	if ( (dd.length == 2) && isNum(dd) && (1*dd >= 0) && (1*dd <= 6) ) { // if day
		switch (dd) { // switch
			case "00" : day = "Sunday";    break;
			case "01" : day = "Monday";    break;
			case "02" : day = "Tuesday";   break;
			case "03" : day = "Wednesday"; break;
			case "04" : day = "Thursday";  break;
			case "05" : day = "Friday";    break;
			case "06" : day = "Saturday";  break;
		} // end switch
	} // end if day
	return day;    
} // end getDay()
//----------------------------------------------------------------
// get month as word from mm                      
function getMonth(mm) {
	var month = "";
	mm        = prezero(mm, 2);
	if ( (mm.length == 2) && isNum(mm) && (1*mm >= 1) && (1*mm <= 12) ) { // if mm
		switch (mm) { // switch
			case "01" : month = "January";   break;
			case "02" : month = "February";  break;
			case "03" : month = "March";     break;
			case "04" : month = "April";     break;
			case "05" : month = "May";       break;
			case "06" : month = "June";      break;
			case "07" : month = "July";      break;
			case "08" : month = "August";    break;
			case "09" : month = "September"; break;
			case "10" : month = "October";   break;
			case "11" : month = "November";  break;
			case "12" : month = "December";  break;
		} // end switch
	} // end if mm
	return month;
} // end getMonth()
//----------------------------------------------------------------
// return last day of the supplied month in year
function getLastDay(mm, yyyy) {
	var lastDay = "28";
	mm   = prezero(mm, 2);
	yyyy = StoS(yyyy);
	if ( (mm.length == 2) && isNum(mm) && (yyyy.length == 4) && isNum(yyyy) ) { // if mm
		if ((1 * mm >= 1) && (1*mm <= 12) && (1*yyyy >= 1900) && (1*yyyy <= 2100)) { //if 1
			if ( (mm == "01") || (mm == "03") || (mm == "05") || (mm == "07") || (mm == "08") || (mm == "10") || (mm == "12") ) { // if 01
				lastDay = "31";
			} else { // else 01
				if ( (mm == "04") || (mm == "06") || (mm == "09") || (mm == "11") ) { // if 04
					lastDay = "30";
				} else { // else 04
					if ( (yyyy % 4) == 0 ) { lastDay = "29"; }
				} // end if 04
			} // end if 01 
		} // end if 1
	} // end if mm
	return lastDay;
} // end getLastDay()
//----------------------------------------------------------------
// pre zero (add leading zeroes) to string become il-characters long . Let il=5
// prezero(null) = ~("") = ~("") = ~("   ") = "00000" 
// prezero("12") = "00012"  ~(" 123") = "00123"  ~("12345") = "12345" ~("123456") = "123456"
// prezero("   1234567") = "1234567" - careful: return truncated
function prezero(str_in, il) {
	var str_out = ""; 
	str_in = StoS(str_in);
	il = 1 * il;
	if ( str_in == "" ) { // zero or empty str_in
		if ( il <= 0 ) { return str_out; } // negative-zero il-parameter
		else {
			for ( i = 0; i < il; i++) { str_out = "0" + str_out; } //creates "00"
		}
	} else {  // if some str supplied 
		str_out = str_in;
		var len = str_out.length;
		if ( len >= il) { return str_out; } // if length is already greater - return as is
		else { // working case - 
			for ( i = len; i < il; i++) { str_out = "0" + str_out; } // pre-zero string
		}
	}
	return str_out;
} // end prezero()
//-------------------------------------------------------------------------------------
// prespace("123", 5) = "  123" - careful: return truncated
function prespace(str_in, il) {
	var str_out = ""; 
	str_in = StoS(str_in);
	il = 1 * il;
	if ( str_in == "" ) { // zero or empty str_in
		if ( il <= 0 ) { return str_out; } // negative-zero il-parameter
		else {
			for ( i = 0; i < il; i++) { str_out = " " + str_out; } //creates " "
		}
	} else {  // if some str supplied 
		str_out = str_in;
		var len = str_out.length;
		if ( len >= il) { return str_out; } // if length is already greater - return as is
		else { // working case - 
			for ( i = len; i < il; i++) { str_out = " " + str_out; } // pre-space string
		}
	}
	return str_out;
} // end prespace()
//-------------------------------------------------------------------------------------
// today date time constructor  : careful - year (which ends in 9x) assumed to be 199x
function getToday() { 
	var currDateTime = new Date();
	var year = StoS(currDateTime.getYear());
	var len = year.length;
	var yy = year.substring(len-2);
	if ( (1 * yy >= 90) && (1 * yy <= 99) ) { yyyy = "19" + yy; }
	else { yyyy = "20" + yy; }

	this.dd          = prezero(currDateTime.getDate(), 2);      // date: 31 
	this.mm          = prezero(currDateTime.getMonth() + 1, 2); // month as 02 for Feb
	this.month       = getMonth(this.mm);                       // month as March for 03
	this.yyyy        = yyyy;                                    // yyyy
	this.dow         = prezero(currDateTime.getDay(), 2);       // dayOfWk: start from 0 = Sun
	this.day         = getDay(this.dow);                        // day as Monday for 1
	this.sec         = prezero(currDateTime.getSeconds(), 2);   // seconds: 59
	this.min         = prezero(currDateTime.getMinutes(), 2);   // minutes: 41
	this.hours       = prezero(currDateTime.getHours(), 2);     // hours:   23
return this;
} // end getToday()
//-----------------------------------------------------------------------
// date constructor : null for wrong args
function constructDate(dd, mm, yyyy) { 
	var currDateTime;
	dd   = prezero(dd, 2);
	mm   = prezero(mm, 2);
	yyyy = prezero(yyyy, 4);

	if ( isDate(yyyy + "-" + prezero(ItoS((1*StoI(mm) + 1)),2) + "-" + dd) ) { // if OK
		currDateTime = new Date(yyyy, mm, dd);

		this.dd          = prezero(currDateTime.getDate(), 2);      // date: 31 
		this.mm          = prezero(currDateTime.getMonth() + 1, 2); // month as 02 for Feb
		this.month       = getMonth(this.mm);                       // month as March for 03
		this.yyyy        = yyyy;                                    // yyyy
		this.dow         = prezero(currDateTime.getDay(), 2);       // dayOfWk: start from 0 = Sun
		this.day         = getDay(this.dow);                        // day as Monday for 1
		this.sec         = prezero(currDateTime.getSeconds(), 2);   // seconds: 59
		this.min         = prezero(currDateTime.getMinutes(), 2);   // minutes: 41
		this.hours       = prezero(currDateTime.getHours(), 2);     // hours:   23

//alert("this.dd=" + this.dd + "\nthis.mm=" + this.mm + "\nthis.month=" + this.month + "\nthis.yyyy=" + this.yyyy + "\nthis.dow=" + this.dow + "\nthis.day=" + this.day + "\nthis.sec=" + this.sec + "\nthis.min=" + this.min + "\nthis.hours=" + this.hours);

	} // if OK
return this;
} // end constructDate()
//-----------------------------------------------------------------------
// get tomorrow String as "2001-12-31" from today str as "2001-12-30"
function gettomorrow(today) {
	var tomorrow = "";
	today = StoS(today);
	if ( (today != ("")) && isDate(today) ) { // if ""
		var YYt = today.substring(0,4);  
		var MMt = today.substring(5,7);
		var DDt = today.substring(8,10);
		var iYYt   = StoI(YYt);
		var iMMt   = StoI(MMt);
		var iDDt   = StoI(DDt);
		var YYy  = "";   var MMy  = "";   var DDy  = "";  // YYy, MMy, DDy - tomorrow
		var iYYy = iYYt; var iMMy = iMMt; var iDDy = iDDt;

		if (iDDt < 28) { // if  qty_days < 28
			iDDy = iDDt + 1;
		} else { // else qty_days < 28
			if ( (iDDt == 28) && (iMMt == 2) && ((iYYt % 4) == 0) ) { //vis
				iMMy = 2; iDDy = 29;
			} else { // else vis
				if ( (iDDt == 28) && (iMMt == 2) && ((iYYt % 4) != 0) ) { //non-vis
					iMMy = 3; iDDy = 1;
				} else { // else non-vis
					if ( iDDt == 28 ) { // if qty_days = 28 
						iDDy = 29; 
					} else { // else if qty_days = 28 
						if ( iDDt == 29 ) { // if qty_days = 29
							iDDy = 30;
						} else { // else qty_days = 29
							if ( iDDt == 30 ) { // if qty_days = 30
								if ( (iMMt == 1) || (iMMt == 3) || (iMMt == 5) || (iMMt == 7) || (iMMt == 8) || (iMMt == 10) || (iMMt == 12) ) { // if 31-month
									iDDy = 31;
								} else { // else 31-moth
									if ( (iMMt == 4) || (iMMt == 6) || (iMMt == 9) || (iMMt == 11)) { // if 30 Apr, 30 Jun, 30 Sep, 30 Nov
									iDDy = 1; iMMy = iMMt + 1;
									} // end if 30 Apr
								} // end 31-month
							} else { // else qty_days = 30
								if ( iDDt == 31 ) { // if qty_days = 31
									if ( (iMMt == 1) || (iMMt == 3) || (iMMt == 5) || (iMMt == 7) || (iMMt == 8) || (iMMt == 10) ) { // if first31
										iDDy = 1; iMMy = iMMt + 1;
									} else { // else first31
										if ( iMMt == 12 ) { // if 31 Dec
											iDDy = 1; iMMy = 1; iYYy = iYYt + 1;
										} // end 31 Dec
									} // end if first31
								} // end if qty_days = 31
							} // end if qty_days = 30
						} // end if qty_days = 29
					} // end if qty_days = 28
				} // end if non-vis
			} // end if vis 
		} // end if qty_days < 28

	tomorrow = prezero(ItoS(iYYy),4) + "-" + prezero(ItoS(iMMy),2) + "-" + prezero(ItoS(iDDy),2);
	} // end if ""
	return tomorrow;		
} // end gettomorrow()
//--------------------------------------------------------------------------------
// return MON TUE WED THU FRI SAT SUN for appropriate day of week for supplied date in format: type=1: dd-mm-yyyy  type=2: yyyy-mm-dd,  blank for wrong
function getDayOfWeek(date, type) { 

	var day = ""; 
	date    = StoS(date);
	type    = StoI(type);
	if ( date.length == 10 ) { // if OK
		var dd   = "";
		var mm   = "";
		var yyyy = "";

		if ( type == 1 ) { // if  dd-mm-yyyy
			dd   = date.substring(0,2);
			mm   = date.substring(3,5);
			yyyy = date.substring(6);
		}

		if ( type == 2 ) { // if yyyy-mm-dd
			dd   = date.substring(8);
			mm   = date.substring(5,7);
			yyyy = date.substring(0,4);
		}

//alert("in getDOW dd=" + dd + " mm=" + mm + " yyyy=" + yyyy);

		if ( isDate(yyyy + "-" + mm + "-" + dd) ) { // if date

			var myDate      = new constructDate(dd, StoI(mm) - 1, yyyy);
			var day_of_week = myDate.dow;                      

//alert("day_of_week=" + day_of_week);

			if ( day_of_week == 1 ) { day = "MON"; }
			if ( day_of_week == 2 ) { day = "TUE"; }
			if ( day_of_week == 3 ) { day = "WED"; }
			if ( day_of_week == 4 ) { day = "THU"; }
			if ( day_of_week == 5 ) { day = "FRI"; }
			if ( day_of_week == 6 ) { day = "SAT"; }
			if ( day_of_week == 0 ) { day = "SUN"; }

		} // end if date
	} // end if OK
	return day;

} // end getDayOfWeek()
//-----------------------------------------------------------------------
// to find date , which is N business days after from supplied date in yyyy-mm-dd format
// careful: for 1 year only
function getDateAfterNdays(date, N) {

	date	  		   = StoS(date);
	N                  = StoI(N);
	var processingDate = date; // returned date

	var holidays	    = new Array(18);
	holidays[0]			= "2002-01-01";  // New Year
	holidays[1]			= "2002-01-26";  // AU
	holidays[2]			= "2002-04-11";  // Easter
	holidays[3]			= "2002-04-12";  // Easter
	holidays[4]			= "2002-04-26";  // Anzac
	holidays[5]			= "2002-06-11";  // Queen
	holidays[6]			= "2002-10-07";  // Labour  
	holidays[7]			= "2002-12-25";  // Boxing
	holidays[8]			= "2002-12-26";  // Christmas

	holidays[9]			= "2003-01-01";  // New Year
	holidays[10]		= "2003-01-27";  // AU
	holidays[11]		= "2003-04-18";  // Easter
	holidays[12]		= "2003-04-21";  // Easter
	holidays[13]		= "2003-04-25";  // Anzac
	holidays[14]		= "2003-06-09";  // Queen
	holidays[15]		= "2003-10-06";  // Labour  
	holidays[16]		= "2003-12-25";  // Boxing
	holidays[17]		= "2003-12-26";  // Christmas

	var dow    = "";    // day of week
	var status = false; // status of processing day: false if holiday of SAT, SUN
	var change = 0;     // reflect is day changed

	if ( isDate(date) && ((N > 0) && (N < 365)) ) { // if OK

		for ( var i = 0; i < N; i++ ) { // for i: while N > 0
	
			processingDate = gettomorrow(processingDate);
			N = N - 1;

			status = false;
			change = 0; 

			WHILE: while ( !status ) { // loop: while day not holiday or weekend
		
				change = 0;

				if ( isItemInArray(processingDate, holidays) >= 0 )	{ // if holidays

					processingDate = gettomorrow(processingDate);
					change++;

				} // end if holidays

				dow = getDayOfWeek(processingDate, 2);

				if ( dow == "SAT" ) { // if SAT

					processingDate = gettomorrow(gettomorrow(processingDate));
					change++;

				} else { // else if SAT

					if ( dow == "SUN" ) { // if SUN

						processingDate = gettomorrow(processingDate);
						change++;

					} // end if SUN

				} // end if SAT

				if ( change == 0 ) { status = true; } // no changes => day OK

			} // end while


		} // end for i

	} // end if OK

	return processingDate;
} // end getDateAfterNdays()
//--------------------------------------------------------------------------------
// to find date , which is N business days after from supplied date-time in yyyy-mm-dd hh:mm:ss format   careful: for 1 year only
function getDateAfterNdays(date, time, N) {

	date	   = StoS(date);
	time	   = StoS(time);
	var hh_cut = "18"; // cut off time 
	var mm_cut = "30";                      
	var ss_cut = "00";         

	var processingDate = date; // returned date

	var holidays	    = new Array(18);
	holidays[0]			= "2002-01-01";  // New Year
	holidays[1]			= "2002-01-26";  // AU
	holidays[2]			= "2002-04-11";  // Easter
	holidays[3]			= "2002-04-12";  // Easter
	holidays[4]			= "2002-04-26";  // Anzac
	holidays[5]			= "2002-06-11";  // Queen
	holidays[6]			= "2002-10-07";  // Labour  
	holidays[7]			= "2002-12-25";  // Boxing
	holidays[8]			= "2002-12-26";  // Christmas

	holidays[9]			= "2003-01-01";  // New Year
	holidays[10]		= "2003-01-27";  // AU
	holidays[11]		= "2003-04-18";  // Easter Friday
	holidays[12]		= "2003-04-21";  // Easter Monday
	holidays[13]		= "2003-04-25";  // Anzac
	holidays[14]		= "2003-06-09";  // Queen
	holidays[15]		= "2003-10-06";  // Labour  
	holidays[16]		= "2003-12-25";  // Boxing
	holidays[17]		= "2003-12-26";  // Christmas

	var dow    = "";    // day of week
	var status = false; // status of processing day: false if holiday of SAT, SUN
	var change = 0;     // reflect is day changed

	if ( isDate(date) && isTime(time) && ((N >= 0) && (N < 365)) ) { // if OK

//		var yyyy = prezero(date.substring(0,4),4); // yyyy-MM-dd
//		var MM   = prezero(date.substring(5,7),2);
//		var dd   = prezero(date.substring(8),2);
		var hh   = prezero(time.substring(0,2),2); // hh:mm:ss
		var mm   = prezero(time.substring(3,5),2);
		var ss   = prezero(time.substring(6),2);

//		var suppliedDate = new Date(yyy, MM, dd, hh, mm, ss);
//	    var cutoffDate   = new Date(yyyy, MM, dd, StoI(hh_cut), StoI(mm_cut), StoI(ss_cut) );

		var isAfter = compare_times(hh + ":" + mm + ":" + ss, hh_cut + ":" + mm_cut + ":" + ss_cut);		

//		var isAfter = suppliedDate.after(cutoffDate);

		if ( isAfter == 1 ) { 
			processingDate = gettomorrow(processingDate); 
		}


//alert("date=" + date + "  time=" + time + "  isAfter=" + isAfter);

		FOR: for ( var i = 0; i <= N; i++ ) { // for i: while N > 0

//alert("000 cycle i=" + i);

			if ( (i == N) && (N != 0) ) { break FOR; }

			if ( N != 0 ) {
				dow = getDayOfWeek(processingDate, 2);
				if ( (dow == "SUN") || (isItemInArray(processingDate, holidays) >= 0) ) { N = N + 1; }
				processingDate = gettomorrow(processingDate);
			}

			status = false;
			change = 0; 

			WHILE: while ( !status ) { // loop: while day not holiday or weekend

//alert("001 in while");

				change = 0;

				if ( isItemInArray(processingDate, holidays) >= 0 )	{ // if holidays
					processingDate = gettomorrow(processingDate);
					change++;
				} // end if holidays

				dow = getDayOfWeek(processingDate, 2);

//alert("003 dow=" + dow);

				if ( dow == "SAT" ) { // if SAT

					processingDate = gettomorrow(gettomorrow(processingDate));
					change++;
				} else { // else if SAT

					if ( dow == "SUN" ) { // if SUN
						processingDate = gettomorrow(processingDate);
						change++;
						if ( N != 0 ) { N = N + 1; }
					} // end if SUN
				} // end if SAT
				if ( change == 0 ) { status = true; } // no changes => day OK
			} // end while
		} // end for i
	} // end if OK
	return processingDate;
} // end getDateAfterNdays()
//--------------------------------------------------------------------------------
function Toggle(objElement) {
// Set the disabled property. If we're in IE, this will automatically disable the elements. If we're on Netscape, this will create a custom property which we use in the event-handlers to determine the status of the elements.

   if ( objElement.disabled == false ) { objElement.disabled = true; }
//   objElement.disabled = (!objElement.disabled);
 
} // end Toggle()  
//------------------------------------------------------------------------
// change of .disabled status
function extracheck(obj) {
	var rt = !obj.disabled;
	return rt;
} // end extracheck()
//------------------------------------------------------------------------
// to disable submit/reset on submit; carefull - not work in NN or earlier 4+
function disable(theform) {

//alert("d01");

var nav = false;
if ( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3) ) { 
nav = true; }

//alert("d02");

if ( document.all || document.getElementById || nav ) { // if form

//alert("d03");

var tempobj = "";

	for ( i = 0; i < theform.length; i++ ) { // for


		tempobj = theform.elements[i];

// alert("d04 i=" + i + " type=" + tempobj.type.toLowerCase());

		if ( (tempobj.type.toLowerCase() == "submit") || (tempobj.type.toLowerCase() == "reset") || (tempobj.type.toLowerCase() == "button") ) { tempobj.disabled = true; }

	} // end for

//	setTimeout('alert("Your payment has been submitted.  Notice how Submit and Reset buttons were disabled upon submission.")', 1000);

//alert("END d05");

	return true;

} else { // else form

//alert("d09");

	alert("Your payment has not been submitted as you're not using IE 4+ or NS 4+. Please, upgrade your browser.");

	return false;

} // end if form

} // end disable()
//------------------------------------------------------------------------
// change text on Submit button
function submitButton(buttonVal) {
	buttonVal.value = " Sending... ";
	return true;
} // end submitButton()
//------------------------------------------------------------------------
// return true for valid VMA card # : A123456                                 
function isVMACard(str) {

	var b = false;
	str = trim(str);

	if ( (str == null) || (str == ("")) || (str.length != 7) ) { return b; } 
	else { // else ""

		if ( str == "A123456") { return true; }

		var first  = str.substr(0,1); // first letter
		var second = str.substr(1);   // 6 numbers

		if ( !isLetter_case(first) ) { return b; }

		if ( !isNum(second) ) { return b; }
	
		b = true;
  	
	} // end if ""
return b;
} // end isVMACard() 
//-------------------------------------------------------------------
// return qty of days since 01 Jan 2001
function Noofdays(year,month,day) {

var qty_days = 31; // qty days in month
var total    = 0;

total = (year - 2001) * 365 ; 

for (i = 1; i <= month - 1; i++) {

	qty_days = 31;

	if ( (i == 4) || (i == 6) || (i == 9) || (i == 11) ) { qty_days = 30; }
	if ( (i == 2) && (year % 4 == 0))                    { qty_days = 29; }
	if ( (i == 2) && (year % 4 != 0))                    { qty_days = 28; }

    total = 1 * total + 1 * qty_days ;

} // end for 

total = 1 * total + 1 * day;

return total ;   
}     
//------------------------------------------------------------ end Noofdays
// to check: if suppliedDate + daysNeeded > today 
function validateDate2(year,month,day) {

var today  = new Date();
var cYear  = today.getYear();  // todays date parameters
var cMonth = today.getMonth();
var cDate  = today.getDate();
var daysNeeded = 0; // depends of day of week

switch ( today.getDay() ) {
	case 0 : 		
		daysNeeded = 4;
	    break ;
	case 1 : 	
		daysNeeded = 5;
	    break ;
	case 2,3,4 :  			
		daysNeeded = 6;
        break ;
	case 5,6 :
		daysNeeded = 5;
	    break ;
	default :  		
		daysNeeded = 7;
        break ;
} // end switch    
           
// qty of days since 01 Jan 2001 till today
var CurrentTotal  = Noofdays(cYear, cMonth+1, cDate); 

// qty of days since 01 Jan 2001 till (year, month, day)= Commence date
var CommenceTotal = Noofdays(year, month, day);

if ( 1 * (CommenceTotal - CurrentTotal) < 1 * daysNeeded  ) { return false; }
return true ; 
} // end validateDate2()
/* -----------------------------------------------------------------------------
** to open new window - behind or up current window 
** first value defines if the window is in the back or not
** behind ='1' // in the back!
** hehind ='0' // in the front, (can be also any other value)!!
*/
function openNewWindow(behind, adress) {
	
	Wind = window.open(adress,'', 'toolbar=yes,status=yes,scrollbars=yes,location=yes,menubar=yes,directories=no,resizable=yes');
	if ( behind == "1" ) { window.focus(); }

} // end of open new window()
//------------------------------------------------------------------------------
// delete all leading & trailing whitespaces from string
function strongStoS(str_in) {

	str_in = StoS(str_in);

	var str_out = replaceChrs(str_in,  "\n", "");
	str_out		= replaceChrs(str_out, "\r", "");
	str_out		= replaceChrs(str_out, "\f", "");
	str_out		= replaceChrs(str_out, "\t", "");
	str_out		= replaceChrs(str_out, "\b", "");

	return str_out;
} // end strongStoS()
//------------------------------------------------------------------------------
// delete all leading & trailing whitespaces from string
function strongStoS_old(str_in) {

	var xyz = StoS(str_in);
	var len = xyz.length;

	if ( len > 1 ) { // if len1

		if ( (xyz.indexOf("\n") == 0) || (xyz.indexOf("\r") == 0) ) {xyz = xyz.substring(1);}

		xyz = StoS(xyz);
		len = xyz.length;

		if ( len > 1 ) { // if len2
			if ( (xyz.indexOf("\n") ==  (len - 1)) || (xyz.indexOf("\r") ==  (len - 1)) ) { xyz = xyz.substring(0, len-1); }
		} // end if len2

		xyz = StoS(xyz);
		len = xyz.length;
		
		if ( len > 1 ) { // if len3

			if ( (xyz.indexOf("\n") == 0) || (xyz.indexOf("\r") == 0) ) { xyz = xyz.substring(1); }

			xyz = StoS(xyz);
			len = xyz.length;

			if ( len > 1 ) { // if len4
				if ( (xyz.indexOf("\r") ==  (len - 1)) || (xyz.indexOf("\n") ==  (len - 1)) ) { xyz = xyz.substring(0, len-1);}	
			} //end if len4

		} // end if len3

	} // end if len1

	return xyz;		
} // end strongStoS()
// ------------------------------------------------------------------------------
function replaceChrs(sGiven, sOld, sNew) {

	var sResult = sGiven;

	if ( (sGiven != null) && (sGiven != "") && (sOld != null) && (sOld != "") && (sNew != null) ) { // if not nul

		var iPos   = sGiven.indexOf(sOld);
	    var iGiven = sGiven.length;
		var iOld   = sOld.length;

	    if ( (1 * iGiven > 0) && (1 * iOld > 0) && (1 * iPos != -1) ) { // if >0

			var sLeft  = "" + sGiven.substring(0, iPos) + sNew;
			var sRight = "";
			if ( iPos < iGiven ) { sRight = "" + sGiven.substring(iPos + iOld); }
			sResult = "" + sLeft + replaceChrs(sRight, sOld, sNew);

		} // end if >0

	} // end if not nul

	return sResult;
} // end replaceChrs()
//-------------------------------------------------------------------------------
// to check if supplied time is in valid hh:mm:ss format 
// (00:00:00  23:58:59  are valid) (1:12:14 a:12:14  24:12:14  00:60:13 00:59:60 - not)
function isTime(time) { 
	var b = false;
	time = StoS(time);
	if ( time.length == 8 ) { // if OK
		if ( (time.substring(2,3) == ":") && (time.substring(5,6) == ":") ) { // if :

			var hh = time.substring(0,2);
			var mm = time.substring(3,5);
			var ss = time.substring(6);
			
			if ( isNum(hh) && isNum(mm) && isNum(ss) && (StoI(hh) >= 0) && (StoI(hh) < 24) && (StoI(mm) >= 0) && (StoI(mm) < 60) && (StoI(ss) >= 0) && (StoI(ss) < 60) ) { b = true; }

		} // end if :

	} // end if OK
	return b;
} // end isTime()
//---------------------------------------------------------------------
// to check if supplied number is odd                            
// isOdd(0) = isOdd(2) = true      isOdd(1) = isOdd(13) = isOdd("a") = false
function isOdd(num) { 
	var b = false;
	num   = StoS(num);
	if ( (num != "") && (num.length > 0) && isNum(num) ) { // if OK
		if ( (num % 2) == 0 ) { b = true; }
	} // end if OK
	return b;
} // end isOdd()
//---------------------------------------------------------------------
// to check if supplied date is not expired for range of 2002 - 2020 years         
function checkExpiry(dd, mm, yy) { 
	var b = false;
	dd    = StoS(dd);
	mm    = StoS(mm);
	yy    = StoS(yy);
	
	if ( isDate("20" + yy + "-" + mm + "-" + dd)  ) { // if OK
		if ( (StoI(mm) >= 1) && (StoI(mm) <= 12) && (StoI(yy) >= 2) && (StoI(yy) <= 20)) { 

			b = true;

		} // end if :

	} // end if OK
	return b;
} // end checkExpiry()
//---------------------------------------------------------------------
// simple check for valid AU state from 8                             
function isState(state) {
	var b = false;
	state = StoS(state);
	if ((state == "ACT") || (state == "NSW") || (state == "VIC") || (state == "QLD") || (state == "SA") || (state == "WA") || (state == "TAS") || (state == "NT")) { b = true;}
	return b;
} // end isState()
//--------------------------------------------------------------------------------
// validate & fix for correct AU postcode; return "ERR" for wrong one     
function fixPostcode(pc) {
	var fixed = "ERR";
	pc        = StoS(pc);
	if ( pc.length == 3 ) { pc = prezero(pc, 4); }
	if ( ( pc.length == 4 ) && isPostcode(pc) ) { fixed = pc; }
	return fixed;
} // end fixPostcode()
//--------------------------------------------------------------------------------
// validate for correct AU postcode                                                
function isPostcode(pc) {
	var b = false;
	pc    = StoS(pc);
	if ( (pc.length == 4) && isNum(pc) ) { // if 4
		var ipc = StoI(pc);
		if ( ((ipc >= 200) && (ipc <= 300)) || ((ipc >= 800) && (ipc <= 900)) || ((ipc >= 1000) && (ipc <= 9800)) ) { b = true; }
	} // end if 4 
	return b;
} // end isPostcode()
//--------------------------------------------------------------------------------
// validate if postcode match AU state + suburb : wrong args (-1) ; doesn't match (0) ; match OK (1)  match, but with double states (2)  match with suburb (3)
function isStateMatchPostcode(state, pc, sub) {
	var res = -1;          
	var ipc = StoI(pc);
	sub     = StoS(sub).toUpperCase();
	state   = StoS(state).toUpperCase();
	if ( isState(state) && isPostcode(pc) ) { // if OK
		res = 0;
		if ( (state == "ACT") && ( (ipc >=  200) && (ipc <=  299) ) ) { res = 1;  }
		if ( (state == "NSW") && ( (ipc >= 1000) && (ipc <= 2599) ) ) { res = 1;  }
		if ( (state == "NSW") && ( (ipc == 2540)                  ) ) { res = 2;  }
		if ( (state == "ACT") && ( (ipc == 2540)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "JERVIS BAY" ) { res = 3; }
		
		}
		if ( (state == "ACT") && ( (ipc >= 2600) && (ipc <= 2618) ) ) { res = 1;  }
		if ( (state == "ACT") && ( (ipc == 2611)                  ) ) { res = 2;  }
		if ( (state == "NSW") && ( (ipc == 2611)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "BRINDABELLA" ) { res = 3; }
		
		}
		if ( (state == "NSW") && ( (ipc == 2619)                  ) ) { res = 1;  }
		if ( (state == "NSW") && ( (ipc == 2620)                  ) ) { res = 2;  }
		if ( (state == "ACT") && ( (ipc == 2620)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( (sub == "HUME") || (sub == "KOWEN FOREST") || (sub == "OAKS ESTATE") || (sub == "THARWA") || (sub == "TOP NAAS") ) { res = 3; }
		
		}
		if ( (state == "NSW") && ( (ipc >= 2621) && (ipc <= 2899) ) ) { res = 1;  }
		if ( (state == "NSW") && ( (ipc == 2734)                  ) ) { res = 2;  }
		if ( (state == "VIC") && ( (ipc == 2734)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "SPEEWA ISLAND" ) { res = 3; }
		
		}
		if ( (state == "ACT") && ( (ipc >= 2900) && (ipc <= 2920) ) ) { res = 1;  }
		if ( (state == "NSW") && ( (ipc >= 2921) && (ipc <= 2999) ) ) { res = 1;  }
		if ( (state == "VIC") && ( (ipc >= 3000) && (ipc <= 3999) ) ) { res = 1;  }
		if ( (state == "NSW") && ( (ipc == 3500)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "PARINGI" ) { res = 3; }
		}
		if ( (state == "NSW") && ( (ipc == 3585)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "MURRAY DOWNS" ) { res = 3; }
		}
		if ( (state == "NSW") && ( (ipc == 3586)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "MALLAN" ) { res = 3; }
		}
		if ( (state == "NSW") && ( (ipc == 3644)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( (sub == "BAROOGA") || (sub == "LALALTY") ) { res = 3; }
		}
		if ( (state == "NSW") && ( (ipc == 3707)                  ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( sub == "BRINGENBRONG" ) { res = 3; }
		}
		if ( (state == "VIC") && ( (ipc >= 8000) && (ipc <= 8999) ) ) { res = 1;  }
		if ( (state == "QLD") && ( (ipc >= 4000) && (ipc <= 4999) ) ) { res = 1;  }
		if ( (state == "QLD") && ( (ipc >= 9000) && (ipc <= 9999) ) ) { res = 1;  }
		if ( (state == "SA")  && ( (ipc >= 5000) && (ipc <= 5999) ) ) { res = 1;  }
		if ( (state == "WA")  && ( (ipc >= 6000) && (ipc <= 6999) ) ) { res = 1;  }
		if ( (state == "NT")  && ( (ipc >=  800) && (ipc <=  999) ) ) { res = 1;  }
		if ( (state == "NT")  && ( (ipc ==  872)                  ) ) { res = 2;  }
		if ( (state == "SA")  && ( (ipc ==  872)                ) ) { 
			if ( sub == "" ) { res = 2; }
			if ( (sub == "FREGON") || (sub == "MIMILI") || (sub == "INDULKANA") || (sub == "ERNABELLA") ) { res = 3; }
		}
		if ( (state == "TAS") && ( (ipc >= 7000) && (ipc <= 7999) ) ) { res = 1;  }
	} // end if OK
	return res;
} // end isStateMatchPostcode()
//--------------------------------------------------------------------------------
// validate if postcode match AU state           
function isStateMatchPostcode(state, pc) {

	var b   = false;
	var ipc = StoI(pc);
	state   = StoS(state);

	if ( isState(state) && isPostcode(pc) ) { // if OK

		if ( (state == "ACT") && ( (ipc >   199) && (ipc <   300) ) ) { b = true; }
		if ( (state == "NSW") && ( (ipc >   999) && (ipc <  2600) ) ) { b = true; }
		if ( (state == "ACT") && ( (ipc >  2599) && (ipc <  2620) ) ) { b = true; }
		if ( (state == "NSW") && ( (ipc >  2619) && (ipc <  2900) ) ) { b = true; }
		if ( (state == "ACT") && ( (ipc >  2899) && (ipc <  2921) ) ) { b = true; }
		if ( (state == "NSW") && ( (ipc >  2920) && (ipc <  3000) ) ) { b = true; }
		if ( (state == "VIC") && ( (ipc >  2999) && (ipc <  4000) ) ) { b = true; }
		if ( (state == "QLD") && ( (ipc >  3999) && (ipc <  5000) ) ) { b = true; }
		if ( (state == "SA")  && ( (ipc >  4999) && (ipc <  6000) ) ) { b = true; }
		if ( (state == "SA")  && ( (ipc >  5999) && (ipc <  7000) ) ) { b = true; }
		if ( (state == "NT")  && ( (ipc >   799) && (ipc <   900) ) ) { b = true; }
		if ( (state == "NT")  && ( (ipc >  5749) && (ipc <  6000) ) ) { b = true; }
		if ( (state == "WA")  && ( (ipc >  5999) && (ipc <  7000) ) ) { b = true; }
		if ( (state == "TAS") && ( (ipc >  6999) && (ipc <  8000) ) ) { b = true; }
		if ( (state == "VIC") && ( (ipc >  7999) && (ipc <  9000) ) ) { b = true; }
		if ( (state == "QLD") && ( (ipc >  8999) && (ipc <  9800) ) ) { b = true; }

	} // end if OK

	return b;
} // end isStateMatchPostcode()
//--------------------------------------------------------------------------------
// return first index of item within b[] ( -1 for non-found) : line search        
function isItemInArray(item, b) {

	var index = -1;
	item      = StoS(item);    

	FORB: for ( var j = 0; j < b.length; j++ ) { // for 
		if ( item == StoS(b[j]) ) { index = j; break FORB; }
	} // end for

	return index;
} // end isItemInArray()
//----------------------------------------------------------
// return true for valid phone # : type = 8: 92929292  type = 9: 9292 9292 
// type = 12: 02 9292 9292  type = 13: 0414 014 014 (mobile)  type = 10: 0292929292
function isPhone(phone, type) {

	phone     = StoS(phone);    
	type      = StoI(type);
	var b     = false;        
	var len   = phone.length;
	var temp  = "";
	var bad   = 0;
	var space = 0;
	var type1 = type;
	if ( type == 13 ) { type1 = 12; }

	if ( type == 10 ) { // if 10

		if ( (len == 10) && isNum(phone) ) { return true; }
		else { return false; }

	} // end if 10

	if ( len == type1 ) { // if OK
	
		FORI: for ( var i = 0; i < len; i++ ) { // for 

			temp = phone.charAt(i);

			if ( !isNum(temp) ) { // if not number 

				if ( temp == " " ) { // if space

					if ( (type == 12) && ((i == 2) || (i == 7)) ) { space++; } // if 12
					else { // else if 12

						if ( (type == 9) && (i == 4) ) { // if 9 
							space++;
						} else { // else if 9
							
							if ( (type == 13) && ((i == 4) || (i == 8)) ) { // if 13
								space++;
							} else { // else 13
								bad++; break FORI; 
							} // end if 13

						} // end if 9
					} // end if 12

				} else { bad++; break FORI; } // end if space

			} // end if not number

		} // end for

		var std = phone.substring(0,2);

//	alert("bad=" + bad + "\ntype=" + type + "\nstd=" + std + "\nisSTD=" + isSTD(std) + "\nspace=" + space);

		if ( (bad == 0) && ( ((type == 10) && (space == 0)) || ((type == 13) && (space == 2)) || ( (type == 12) && (space == 2) && isSTD(std) ) || ((type == 9) && (space == 1))  || ((type == 8) && (space == 0)) )	) { b = true; }

	} // end if OK

	return b;
} // end isPhone()
//----------------------------------------------------------
// return true for valid AU STD
function isSTD(code) {
	var b = false;
	code  = StoS(code);
	if ( (code.length == 2) && ((code == "02") || (code == "03") || (code == "04") || (code == "07") || (code == "08")) ) { b = true; }
	return b;
} // end isSTD()
//----------------------------------------------------------
// return true for valid Acc # : valid symbols are: numbers s S -
function isAccNo(acc) {
	var b = false;
	acc = StoS(acc);
	if ( (acc != "") && (acc.length >= 2) && (acc.length <= 9) && ((isNum(acc.toUpperCase(), "S")) || (isNum(acc, "-")) ) ) { b = true; }
	return b;
} // end isAccNo()
//----------------------------------------------------------------------------------
// return true for valid BSB as long 123-456                                          
function isBSB(bsb) {
	var b = false;
	bsb = StoS(bsb);
	if ( (bsb != "") && (bsb.length == 7) && (bsb.substring(3,4) == "-") && (isNum(bsb.substring(0,3))) && (isNum(bsb.substring(4))) ) { b = true; }
	return b;
} // end isBSB()
//----------------------------------------------------------------------------------
// to check what time from supplied 2 is earlier: hh:mm:ss format   -1 if time1 < time2, 0 if time1 = time2  1 if time1 > time2   10 - for wrong args
function compare_times(time1, time2) {
	var result = 10;
	if ( isTime(time1) && isTime(time2) ) { // if OK

		var hh1 = StoI(time1.substring(0,2));
		var mm1 = StoI(time1.substring(3,5));
		var ss1 = StoI(time1.substring(6));

		var hh2 = StoI(time2.substring(0,2));
		var mm2 = StoI(time2.substring(3,5));
		var ss2 = StoI(time2.substring(6));

		if ( hh1 < hh2 ) { result = -1; } // if hh1 <
		else { // else if hh1 <

			if ( hh1 == hh2 ) { // if hh1 =
				
				if ( mm1 < mm2 ) { result = -1; } // if mm1 <
				else { // else if mm1 <
					
					if ( mm1 == mm2 ) { // if mm1 =

						if ( ss1 < ss2 ) { result = -1; } // if ss1 <
						else { // else if ss1 <
							
							if ( ss1 == ss2 ) { result = 0; } // if ss1 =
							else { result = 1; } // end if ss1 =

						} // end if ss1 <

					} else { result = 1; } // end if mm1 =

				} // end if mm1 <

			} else { result = 1; } // end if hh1 =

		} // end if hh1 <

	} // end if OK
	return result;
} // end compare_times()
//--------------------------------------------------------------------------------
// change title in multi-frame
function changeFrameTitle(desc) {
    var agt    = navigator.userAgent.toLowerCase();
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
	if ( !is_nav ) { parent.document.title = StoS(desc); }
} // end changeFrameTitle()
//--------------------------------------------------------------------------------
function afterzero(str, qty) {

str         = "" + str;
var str_out = str;
var len     = str.length;
var dot     = ".";

var ind = str.indexOf(dot);

if ( len >= 1 ) { // if >

	if ( ind < 0 ) { 

		str_out = str_out + dot;
		for ( var i = 0; i < qty; i++ ) { str_out = "" + str_out + "0"; }
	}
	
	if ( (ind > 0) && (len - ind == 2) ) { str_out = "" + str_out + "0"; }
	
	if ( (ind > 0) && (len - ind <= 1) ) {
		for ( var i = 0; i < qty; i++ ) { str_out = "" + str_out + "0"; }
	}
	
} // end if > 
return str_out;
} // end afterzero()
//-------------------------------------------------------
function isAlphaNum(str) {

	str = StoS(str);
	var b  = false;
	if ( str != "" ) { // if ""
	    for ( i = 0; i < str.length; i++ ) { // for
			if ( !isLetter(str.charAt(i)) ) { // if l
				if (str.charAt(i) < "0" || str.charAt(i) > "9") { return b; }
			} // end if l
		} // end for
		b = true;
	} // end if ""
	return b;

} // end isAlphaNum()
//-------------------------------------------------------
// return following type for form' elements (supplied by name as document.formName.elementName)
// text; radio; select-one; hidden; submit; reset; button; 
// "" - for undefined element
function elementType(elName) {

	var out = "";
	if ( (elName != null) && elName && document.getElementsByName(elName) ) { 
		out = StoS(elName.type);	
	} 
	return out;

} // end elementType()
//----------------------------------------------------------------
function decimal_place(n) {
var n1 = n * 10;
var n2 = Math.floor(n * 10);

if (n1 == n2 ) { }

var n11 = n * 100;
var n22 = Math.floor(n * 100);

if ( (n11 == n22) && (n1 == n2) ) { }

}  // end decimal_pl()
//--------------------------
// rounds number to qty decimals, def = 2 
function round2(number, qty) {
// qty = qty: 2, qty;
return Math.round(number * Math.pow(10, qty)) / Math.pow(10, qty);
}  // end round2()
//------------------------------
