<!--
//01-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@description: pass radio button 
function checkGender(gender){
	if ((! gender[0].checked) && (! gender[1].checked)){
		alert("Please specify your gender");
		return false;
	}
	else { return true; }
}
//02-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@description: chek username with minimum length
function isUsername(uNameField, minLength){
	var label= "username";
	if (isEmpty(uNameField, label)){
		return false;
	}
	else if (! checkMinLength(uNameField.value, minLength, label)){
		uNameField.focus();
		return false;
	}
	else { return true; }
}
//03-----------------------------------------------------------------
//@author: Unknown
//@description: function to check empty field
function isEmpty(aTextField, label) {
	strRE = new RegExp( );
	strRE.compile( '^[s ]*$', 'gi' );
	if (strRE.test(aTextField.value)) {
		alert("Please enter " + label + ".");
	  	aTextField.focus();
      	return true;
   	}
   	else { return false; }
}
//04-----------------------------------------------------------------
//@author: Unknown
//@description: function to check valid email address
function checkMail(emailField){
	var x = emailField.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,6})+$/;
	if (filter.test(x)){
		return true; 
	}
	else{
		emailField.focus();	
		alert('A valid e-mail address is required.\nPlease amend and retry'); 
		return false;
	}
}
//05-----------------------------------------------------------------
//@author: Unknown
//fucntion to check password
function validatePwd(pwdField1, pwdField2) {
	var invalid = " "; // invalid character is a space
	var minLength = 3; // minimum length
	var pw1 = pwdField1.value;
	var pw2 = pwdField2.value;
	// check for a value in both fields.
	if (pw1 == '' || pw2 == '') {
		alert('Please enter your password twice.');
		pwdField1.focus();
		return false;
	}
	// check for minimum length
	else if(! checkMinLength( pw1, minLength, "password" )){
		pwdField1.focus();
		return false;
	}
	// check for spaces
	else if (pw1.indexOf(invalid) > -1) {
		alert("Sorry, spaces are not allowed.");
		pwdField1.focus();
		return false;
	}
	else if (pw1 != pw2) {
		alert ("You did not enter the same new password twice. Please re-enter your password.");
		pwdField1.focus();
		return false;
	}
	else {	return true;	}
	
}
//06-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@description: check minimum length of a given value
function checkMinLength( fieldText, minLength, label ){
	 if (fieldText.length < minLength) {
		alert('Your ' + label + ' must be at least ' + minLength + ' characters long.');
		return false;
	}
	else { return true; }
}
//07-----------------------------------------------------------------
//@author: Unknown
function checkDate(monthField, dateField, yearField){
	if(! isDate(dateField, monthField)){
		dateField.focus();
		return false;
	}
	else if (! isMonth(monthField)){
		monthField.focus();
		return false;
	}
	else if(! isYear(yearField)){
		yearField.focus();
		return false;
	}
	else {	return true;	}
}
//08-----------------------------------------------------------------
//@author: Unknown
function isMonth(monthField){
	if (! isNumber(monthField, "Month")){
		return false;
	}
	else if((monthField.value < 1) || (monthField.value > 12)){
		alert(monthField.value + " is not a valied month");
		return false;
	}
	else {	return true;	}
}
//09-----------------------------------------------------------------
//@author: Unknown
function isDate(dateField, monthField){
	var daysInMonths= new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var date= dateField.value;
	var month= monthField.value;
	if(! isNumber(dateField, "Date")){
		return false;
	}
	else if((date < 1) || (date > daysInMonths[month -1])){
		alert("Please enter a valied date.");
		return false;
	}
	else {
		return true;
	}
}
//10-----------------------------------------------------------------
//@author: Unknown
function isYear(yearField){
	if(! isNumber(yearField, "Year")){
		return false;
	}
	else if( yearField.value < 1930 || yearField.value > 2006 ){
		alert("Please enter a valied year [between 1930 && 2006].");
		return false;
	}
	else {
		return true;
	}
	
}
//11-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
function isNumber(numberField, label){
	if (isEmpty(numberField, label)){
		return false;
	}
	else if (isNaN(numberField.value)){
		alert(label + " only accept numeric values.");
		return false;
	}
	else { return true; }
}
//12-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
function submitChoice(choice, uniqueId, url){
	var submitStatus;
	if(choice== "deleteRc" ){
		submitStatus= confirm("Do you want to delete this record?.")
	}
	else { submitStatus= true; }
	
	if (submitStatus== true ){
		location.href= url + "?choice="+ choice +"&uniqueId= "+uniqueId;
	}
	else {	return; }
}
//13-----------------------------------------------------------------
//@author: Unknown
function replaceString(fullS, oldS, newS) {
	// Replaces oldS with newS in the string fullS   
	for (var i=0; i<fullS.length; i++) {
		if (fullS.substring(i,i+oldS.length) == oldS) {
			if (newS== "") {
				
				fullS = fullS.substring(0,i)+fullS.substring(i+oldS.length,fullS.length);
			}
			else {
				
				fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
			}
		}   
	}   
	return fullS
}
function replaceStr(str, rstr, nstr){
		return str.replace(rstr, nstr);
}
//14-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
function removeNBSP(str){
	var NBSP= "%A0";
	str= escape(str).replace(NBSP,"");
	return unescape(str);
}
//15-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
function getNodeValue(id){
	return removeNBSP(document.getElementById(id).firstChild.nodeValue);
}
//16-----------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
function selectOptionText(selectField, text){
	for (var i=0; i < selectField.options.length; i ++){
		//	alert(selectField.options[i].text)
		if (selectField.options[i].text== text){
			selectField.options[i].selected= true;
			break;
		}
	}
}
//17---------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
function isSelectSelectfieldItemSelected(objSelect, label){
	if (objSelect.options[objSelect.selectedIndex].value== "null"){
		alert("Please select "+ label +".");
		objSelect.focus()
		return false;
	}
	else return true;
}
//18--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
//@description: Radiobutton(s) or checkbox(s)  is selected or not
function isCollectionSelected(formname,cname, label){
	var objCollection= eval("document."+formname+"."+cname);
	var objSelected= false;
	var message= "Please select atleast one "+ label +".";
	if (objCollection.length != undefined) {
		for (var i=0; i< objCollection.length; i++){
			if (objCollection[i].checked){
				objSelected= true;
				break;
			}
		}
	}
	else {
		objSelected= objCollection.checked;
		message= "Please select " + label +".";
	}
	if (! objSelected){ alert(message );}
return objSelected;}
//19--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
function getRowValueByIndex(rowIndex, colIndex){
	return removeNBSP(eval("document.getElementById(rowIndex).childNodes["+colIndex+"].firstChild.nodeValue"));
}
//20--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: none
//@description: pass a HTML element collection eg: td
function getValueFromCollection(collection, itemId){
	return replaceString(replaceString(collection.item(itemId).innerHTML,"&nbsp;",''), "<BR>", unescape('%0D%0A'));
}
//21--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
function isListBoxSelected(selectField, label){
	var isSelected= false;
	for (var i=0; i < selectField.options.length; i ++){
		if (selectField.options[i].selected){
			isSelected= true;
			break;
		}
	}
	if (! isSelected ) {
		alert( "Please select atleast one "+ label+ ".");
		selectField.focus();
	}
	return isSelected;
}
//22--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: none
function deselectListbox(listBox){
	for(var i= 0; i< listBox.options.length; i++){
		listBox.options[i].selected= false;
	}
}
//23--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: none
function selecListbox(listBox, strValues, label){
	var arrObj= strValues.split(",");
	deselectListbox(listBox);
	for (j= 0; j< arrObj.length; j++ ) {
		selectOptionText(listBox, arrObj[j]);
	}
}
//24--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: none
//@description: will attach a delete query string with the url
function deleteRecord(indexname, index, url){
	if(confirm("Do you want to delete this record?.")){
		location.href= url + "?formaction=deleterec&"+indexname+"="+index;
	}
	else {	return; }
}
//25--------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
//@description: check the width and height of an image
function checkImageSize(imageField, width, height){
	var tempImg= new Image()
	if (imageField.value != "") {
		tempImg.src= imageField.value
		if ((tempImg.width > width) || (tempImg.height > height)){
			alert("Please select an image, that size of "+width+"x"+height+"."); 
			return false;
		}
		else{return true}
	}
return true;}
//26-------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
//@description: will check text is pure alpha numeric
function isLegalText(txt) {
	var invalids = "!@#$%^&*()-~,'<.>/?;:\|"
	for(i=0; i<invalids.length; i++) {
		if(txt.indexOf(invalids.charAt(i)) >= 0 ) {
			return false;
		}
	}
	return true;
}
//27-------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
//@description: function will check minimum length
function checkMaxLength( aTextField, maxLength, label ){
	if(isEmpty(aTextField, label)){
		return false;
	}
	else if(aTextField.value.length > maxLength) {
		alert('Maximum '+maxLength+' characters are allowed to write your '+label+'.');
		return false;
	}
	else { 
		return true; 
	}
}
//28-------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
var checkboxStatus= true;
function selectAllCheckbox(objForm){
	var elm= objForm.getElementsByTagName("INPUT");
	for (var i= 0 ; i < elm.length; i++){
		if(elm.item(i).type== "checkbox"){
			elm.item(i).checked= checkboxStatus;
		}
	}
	checkboxStatus= (checkboxStatus)? false : true;
}
//29-------------------------------------------------------------------
//@author: Anis A.H <anis_karakkad@yahoo.com> 
//@return: boolean
function isAnyCheckboxSelected(objForm, label){
	var elm= objForm.getElementsByTagName("INPUT");
	var isSelected= false;
	for (var i= 0 ; i < elm.length; i++){
		if(elm.item(i).type== "checkbox"){
			if(elm.item(i).checked){
				isSelected= true;
				break;
			}
		}
	}
	if(!isSelected) alert ("Please select atleast one "+ label + ".");
	return isSelected;
}	
/*
	try
	{
		//Run some code here
	}
	catch(err)
	{
		alert(err.description )
		//Handle errors here
	}
*/
//-->