function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function checkTextBox(txtElement,fieldName)
{
/*	var GoodChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var i = 0*/

	if(txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	
/*	for (i =0; i <= txtElement.value.length -1; i++)
	{
		if (GoodChars.indexOf( txtElement.charAt(i)) == -1)
		 {
		alert( txtElement.charAt(i) + " is no good.");
		alert("Please enter a valid " + fieldName + ".\nIt can only include alphabets");
		txtElement.focus();
		return false;
		} // End if statement
	} // End for loop*/

	return true;
}
	
function checkTextArea(txtElement,maxAllowedLength,fieldName,allowEmpty)
{
	if(allowEmpty == false && txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	if(txtElement.value.length > maxAllowedLength)
	{			
		alert("You have entered " + txtElement.value.length + " characters in the " + fieldName + ". \nThe Maximum number of characters allowed for this field is " + maxAllowedLength);
		//Truncate Statement
		txtElement.value = txtElement.value.substring(-1,maxAllowedLength);
		return false;
		//alert(txtElement.value.charAt(498))
	}
	return true;
}

function checkPassword(txtElement,fieldName,maxNum)
{
	var checkstring = /[^-_()&+*\"\'@!%\/?:=~#a-zA-Z0-9]/
	if(txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	if(txtElement.value.search(checkstring)!=-1)
	{
		alert("Please enter a valid password.\nIt can only include numbers, upper and lower case letters\nor the following special characters . - _ ( ) & + * \" ' @ ! % / ? : = ~ # ");
		txtElement.focus();
		return false;
	}
	return true;
}

function openWin(strURL,strWinName,winWidth,winHeight)
{
	var chngpass;
	winTop=0
	winLeft=0
	winLeft=Math.floor((Math.abs(screen.availWidth-winWidth))/2);
	winTop=Math.floor((Math.abs(screen.availHeight-winHeight))/2);

	strWin=window.open(strURL,strWinName,'top='+ winTop + ',left=' + winLeft + ',width=' + winWidth + ',height=' + winHeight + ',toolbar=no menubar=no,location=no,directories=no,status=no,resizable=no,scrollbars=yes');
	//return strWin;
}

function chkPin(txtElement,fieldName,allowEmpty)
{
	
	if(allowEmpty==false && txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}

	if(txtElement.value.search("[^0-9 ,/+-]")!=-1)
	{
		alert("Please enter a valid " + fieldName + ".\nIt can only include numbers and the following special characters:\n space , / + -");
		txtElement.focus();
		return false;
	}
	return true;
}


function checkList(element,strfield)
{ 
 	if  (element.selectedIndex ==0)
   {   
        var mess;
        mess = strfield;
        alert ("Please select a '" + mess +"'");
        element.focus();
				return false;
    }
    else
    {
        return true;   
    }
}


function checkCheckBox(chkElement,fieldName,isAlert) 
{ //alert(chkElement.name)
	//alert(chkElement.length)
	//checking if a checkbox is selected
	if(isNaN(chkElement.length)) //ie if its not a group
	{ 
		if(!chkElement.checked) 
		{
			if (isAlert)
			{
				alert("Please select  '" + fieldName + "'")
			}
			return false;
		}
		else
		{
			return true;
		}
	}
	else      //ie if it is a group
	{	var isChecked=false
		for(i=0;i<chkElement.length;i++)  //
		{
			isChecked = isChecked || chkElement[i].checked
			//alert(isChecked)
		}
		if (!isChecked)
		{
			if (isAlert)
			{
				alert("Please choose  '" + fieldName + "'")
			}
				return false;
		}
		else
		{
			return true;
		}
	}
}

function checkNumeric(txtElement,fieldName)
{
	if(txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	if(isNaN(txtElement.value))
	{
		alert("Please enter a valid '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	
	return true;
}


function checkDate(txtElement,fieldName)
{
	var checkstring = /[/0-9]/
	
	if(txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	
	if(txtElement.value.search(checkstring)==-1)
	{
		alert("Please enter a valid Date : Format: DD/MM/YYYY Eg: 03/11/2002 ");
		txtElement.focus();
		return false;
	}
	
	if(txtElement.value.length < 9)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	return true;
}

function checkNumeric(txtElement,fieldName,maxNum)
{
	if(txtElement.value.length == 0)
	{
		alert("Please enter '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	if(isNaN(txtElement.value))
	{
		alert("Please enter a valid '" + fieldName + "'");
		txtElement.focus();
		return false;
	}
	if(maxNum != 0 && parseInt(txtElement.value) > maxNum)
	{
		alert("'" + fieldName + "' should be less than " + maxNum);
		txtElement.focus();
		return false;
	}
	return true;
}