/*
<!-- -->
<!-- The copyright in the work that is PublicAccess is the exclusive -->
<!-- property of CAPS Solutions Ltd, and its respective copyright owners, and is -->
<!-- protected under United Kingdom copyright law and other international copyright -->
<!-- treaties and conventions. 
<!-- © 2004. CAPS Solutions Ltd and its licensor(s). All rights reserved. -->
*/

//***********************************************************************************
// Converts a string representing an integer to an integer
//***********************************************************************************
function ValidateLogin(){
	
	if(document.frmLogin.txtUsername.value > "" && document.frmLogin.txtPassword.value > "")
	{
		//this is fine
		return true;
	}
	else
	{
		//this is not allowed
		alert("You must enter a username and password to login");
		return false;
	}
}

//***********************************************************************************
// Converts a string representing an integer to an integer
//***********************************************************************************
function atoi(s){
	
	var t = 0;
	var ch='';
	
	for(var i=0;i < s.length;i++){
		
		ch = s.charAt(i);
		
		if(!isDigit(ch))
			return t;
		else 
			t = t * 10+(ch-'0');
	}
	
	return t;
}

//***********************************************************************************
// checks to see if char is numeric
//***********************************************************************************

// checks that a value is a number
function isNumber(pVal) {
 var i;

 for(i = 0; i < pVal.length; i++) {
  if(isNaN(parseInt(pVal.substring(i, i + 1)))) {
            return false;
    }
 } return true;
}

//**********************************************************************************
// function to determine if a value is a valid decimal number. will return false for 
// decimal numbers with more decimal places than specified by -iDecimalPlaces- 
// (rather than rounding the value)
//***********************************************************
function isValidDecimalNumber(pVal, iDecimalPlaces) {
 
 var bIsDecimal;
 var iCommaIndex;
 var szDecimal;
 var iDecimalLength;
 
 bIsDecimal = false;

 iCommaIndex = pVal.indexOf('.');

 if (iCommaIndex != -1){
	if (isNumber(pVal.substring(0,iCommaIndex))){
	
		szDecimal = pVal.substring(iCommaIndex + 1, pVal.length);
		iDecimalLength = szDecimal.length;
		
		if (iDecimalLength > iDecimalPlaces || iDecimalPlaces < 0)
			return false;
			
		if (isNumber(pVal.substring(iCommaIndex + 1,iCommaIndex + 1 + iDecimalPlaces)))
			bIsDecimal = true;
	}
 }
 else{
 	if (isNumber(pVal)) bIsDecimal = true;
 }
 

 
 return  bIsDecimal;
}//end function


function isDigit(ch){
	return(ch >= '0' && ch <= '9');
}


//**********************************************************************************
//	======================  DATE AND TIME FUNCTIONS  ==============================
//**********************************************************************************

//***********************************************************************************
// get number of days in a particular month
//***********************************************************************************
function getMonthDayCount(m, y){
	
	var rM=new Array(12);
	rM[0]=rM[2]=rM[4]=rM[6]=rM[7]=rM[9]=rM[11]=31;
	rM[3]=rM[5]=rM[8]=rM[10]=30;
	rM[1]=28;
	
	var iDays = rM[m-1];
	
	// check for leap year 
	if((2 == m) && isLeapYear(y))
		iDays++;
	
	return iDays;
}

//***********************************************************************************
// is year a leap year
//***********************************************************************************
function isLeapYear(y){

	if(0==y%4 && ((y%100!=0) || (y%400==0))) 
		return true;
	else 
		return false;
}


//***********************************************************************************
// Returns true if string s is empty or 
// whitespace characters only.
//***********************************************************************************
function isWhitespace (s){   
	// whitespace regexp for validation
	var szcREGEXP_WHITESPACE = " \t\n\r";
	var i;
    // 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 (szcREGEXP_WHITESPACE.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
//***********************************************************************************
// Check whether string s is empty
//***********************************************************************************
function isEmpty(s){
	return ((s == null) || (s.length == 0));
}

//********************************************************
//  removes elements contained in one array from the other
//********************************************************
function removeDuplicates(ar_Array, ar_ElementsToBeRemoved){
	
	if (ar_ElementsToBeRemoved != null){
		
		var arPurgedArray = new Array();
		var bIsDuplicate = false;
		
		for(var i=0; i< ar_Array.length; i++){
			
			bIsDuplicate = false;
			
			for (var j=0; j< ar_ElementsToBeRemoved.length; j++){
				if (ar_Array[i] == ar_ElementsToBeRemoved[j])
					bIsDuplicate = true;
			}
			
			if (bIsDuplicate!=true){
				arPurgedArray[arPurgedArray.length] = ar_Array[i];
			}
		}
		return arPurgedArray;
	}
	
	else return ar_Array;
}


//********************************************************
//  clears a set of checkboxes
//********************************************************
function clearCheckBoxes(elChecks)
{
	
	if (elChecks != null) 
	{
		var iUpper = elChecks.length;
		// length is undefined if only one
		if (!iUpper)
		{
			elChecks.checked = false;
		}
		else
		{
			for (var i=0;i< iUpper;i++)
			{
				elChecks[i].checked = false;
			}
		}
		
	}
}

//*********************************************************
// clears a search form, including preselected SELECTs
//*********************************************************
function clearForm(f)
{
	var i;
	f.reset();
	for (i=0; i<f.elements.length; i++)
	{
		if (f.elements[i].type=='text')
		{
			f.elements[i].value='';
		}
		
		if (f.elements[i].selectedIndex)
		{
			f.elements[i].selectedIndex=0;
		}
	}
}

/*************************************************
 pguz, 25/02/2004, for cross-browser compatibility.
 gets the named attribute from the given element,
 avoiding use of IE's element.attribute syntax.
**************************************************/
function getAttributeFromElement(el,attributeName)
{
	var bFoundAttribute=false;
	var elementAttribute=null;
	var i=0;
	
	//IE5.5 doesn't support el.attributes[] ...
	
	if (navigator.appName=="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera")==-1 && el.tagName.toLowerCase()!="button") //cannot do element.attribute with buttons
	{
	
		var attributeValue = (eval("el."+attributeName));
		var attribute = new objAttribute();
		attribute.name="attributeName";
		attribute.value=attributeValue;
		return attribute;
	}
	else //... while only IE supports the element.attribute syntax
	{		
		elementAttribute =el.getAttribute(attributeName);
		//the code above replaced the bottom code as it did not work on ie5.5
		//while (!bFoundAttribute && i<el.attributes.length - 1)
		//{
		//	if (el.attributes[i].name.toLowerCase()==attributeName.toLowerCase())
		//	{
		//		elementAttribute = el.attributes[i];
		//		bFoundFieldTypeAttribute=true;
		//	}
		//	i++;
		//}

		return elementAttribute;
	}
}

function objAttribute()
{
	name="";
	value="";
}
