// JavaScript Document
function isPhoneNo(phone){
	// Check for correct phone number
	rePhoneNumber = new  RegExp(/^\[0-9]d{1,7}$/);
	//if (!rePhoneNumber.test(phone)) {
	if( isNaN(phone) || phone.length<10 || phone.length>15){
		return false;
	}
	return true;
}


function checkAccount()
{ 
	var f_name = $("f_name").value;
	var l_name = $("l_name").value;
	var email = $("email").value;
	var c_email = $("c_email").value;
	var password = $("password").value;
	var c_password = $("c_password").value;
	var tnc = $("tnc").checked;
	var phone = $("phone").value;
	var msg = "";
	
	if( f_name == "" || f_name == null || l_name == ""|| l_name == null || email == ""|| email == null || c_email == "" || c_email == null || email != c_email || password == null || password == "" || c_password == null || c_password == "" || c_password != password || phone == "" || phone == null || tnc == false )
	{
		msg = "<b>Following errors occurred : </b><ul>";
		if(f_name.strip() == "")
		{
			msg += "<li>Please enter your first name.</li> ";
		}
		if(l_name.strip() == "")
		{
			msg += "<li>Please enter your last name.</li> ";
		}
		if(email.strip() == "")
		{
			msg += "<li>Please enter your email address.</li> ";
		}
		else if(!isEmailAddr(email))
		{
			msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
		}
		
		if(c_email.strip() == "")
		{
			msg += "<li>Please confirm your email address.</li> ";
		}
		if(c_email.strip() != email.strip())
		{
			msg += "<li>Your email address and email confirmation does not match. Please re-enter.</li> ";
		}
		if(password.strip() == "")
		{
			msg += "<li>Please enter password.</li> ";
		}
		if(c_password.strip() == "")
		{
			msg += "<li>Please confirm your password.</li> ";
		}
		if(password.strip() != c_password.strip())
		{
			msg += "<li>Your password and password confirmation does not match. Please re-enter.</li> ";
		}
		if(phone.strip() == "" )
		{
			msg += "<li>Please enter your phone number.</li> ";
		}
		else if(!isPhoneNo(phone.strip()))
		{
			msg += "<li>" + "Please enter a valid phone number. (Do not include '-' or '+')</li>";
		}
		if(tnc == false )
		{
			msg += "<li>You must accept the terms and conditions.</li>";
		}
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkEditAccount(){ 
	var f_name = $("f_name").value;
	var l_name = $("l_name").value;
	var email = $("email").value;
	var c_email = $("c_email").value;
	var password = $("password").value;
	var c_password = $("c_password").value;
	var phone = $("phone").value;
	var msg = "";
	
	if( f_name == "" || f_name == null || l_name == ""|| l_name == null || email == ""|| email == null || c_email == "" || c_email == null || email != c_email || password == null || password == "" || c_password == null || c_password == "" || c_password != password || phone == "" || phone == null)
	{
		msg = "<b>Following errors occurred : </b><ul>";
		if(f_name.strip() == "")
		{
			msg += "<li>Please enter your first name.</li> ";
		}
		if(l_name.strip() == "")
		{
			msg += "<li>Please enter your last name.</li> ";
		}
		if(email.strip() == "")
		{
			msg += "<li>Please enter your email address.</li> ";
		}
		else if(!isEmailAddr(email))
		{
			msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
		}
		
		if(c_email.strip() == "")
		{
			msg += "<li>Please confirm your email address.</li> ";
		}
		if(c_email.strip() != email.strip())
		{
			msg += "<li>Your email address and email confirmation does not match. Please re-enter.</li> ";
		}
		if(password.strip() == "")
		{
			msg += "<li>Please enter password.</li> ";
		}
		if(c_password.strip() == "")
		{
			msg += "<li>Please confirm your password.</li> ";
		}
		if(password.strip() != c_password.strip())
		{
			msg += "<li>Your password and password confirmation does not match. Please re-enter.</li> ";
		}
		if(phone.strip() == "" )
		{
			msg += "<li>Please enter your phone number.</li> ";
		}
		else if(!isPhoneNo(phone.strip()))
		{
			msg += "<li>" + "Please enter a valid phone number. (Do not include '-' or '+')</li>";
		}
		
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkLogin()
{ 
	var username = $("username").value.strip();
	var password = $("password").value.strip();
	var msg = "<b>Following errors occurred : </b><ul>";
	
	if(username == "" || username == null ) msg += "<li>Please enter your email address.</li>";
	if(password == "" || password == null ) msg += "<li>Please enter your password.</li>";
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}



function checkForgotPwd(){ 
	var email = $("email").value;
	var msg = "<b>Following errors occurred : </b><ul>";
		
	/* email value error checking */
	if(email == "" || email == null ) msg += "<li>Please enter your email address.</li>";
	else if(!isEmailAddr(email)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}

function makeApprovalButton(newEmail, oldEmail){
	if( newEmail.strip() != oldEmail.strip() ) {
		$('get_approval').disabled = false;
		$('approval_status_msg').innerHTML = '';
	}
}

function sendApprovalMail(){
	var divToBeUpdated = 'approval_status_msg';
	$(divToBeUpdated).innHTML = '';
	var gov_email = $("gov_email").value.strip();
	var msg = '';
	if(gov_email.strip() == "") msg = '<span class="red-text">Please enter your email address.</span> ';
	else if(!isEmailAddr(gov_email)) msg = '<span class="red-text">Please enter a valid email address as: <B>yourname@yourdomain.com</B></span>';
	else{
		var url='includes/common_ajax.php?item=gov_email&value='+gov_email;
		new Ajax.Updater(divToBeUpdated,url,{asynchronous:true,onLoading:function(request){Element.show('indicator')},onComplete:function(request){ Element.hide('indicator')}, evalScripts:true});
	}
	if(msg != ''){
		//$(divToBeUpdated).show('slow');
		$(divToBeUpdated).innerHTML = msg;
	}
}

function checkNominationQuestion1(){ 
	var nom_email = $("nom_email").value.strip();
	var nom_daytime = $("nom_daytime").value.strip();
	var nom_fax = $("nom_fax").value.strip();
	var	msg = "<b>Following errors occurred : </b><ul>";
	if(nom_daytime!='' && !isPhoneNo(nom_daytime)) msg += "<li>" + "Please enter a valid phone number. (Do not include '-' or '+')</li>";
	if(nom_fax!='' && !isPhoneNo(nom_fax)) msg += "<li>" + "Please enter a valid fax number.</li>";
	if(nom_email == "" || nom_email == null ) msg += "<li>Please enter email address.</li>";
	else if(!isEmailAddr(nom_email)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkNominationQuestion2(){ 
	var email_1 = $("email_1").value.strip();
	var email_2 = $("email_2").value.strip();
	var email_3 = $("email_3").value.strip();
	var email_4 = $("email_4").value.strip();
	var email_5 = $("email_5").value.strip();
	
	var phone_1 = $("phone_1").value.strip();
	var phone_2 = $("phone_2").value.strip();
	var phone_3 = $("phone_3").value.strip();
	var phone_4 = $("phone_4").value.strip();
	var phone_5 = $("phone_5").value.strip();
	
	var msg = "<b>Following errors occurred : </b><ul>";

	if(phone_1!='' && !isPhoneNo(phone_1)) msg += "<li>" + "Please enter a valid phone number of Mayor or other executive government representative.</li>";
	if(email_1 != '' && !isEmailAddr(email_1)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B> of Mayor or other executive government representative.</li>";
	if(phone_2!='' && !isPhoneNo(phone_2)) msg += "<li>" + "Please enter a valid phone number of Director of your parks and recreation department/agency.</li>";
	if(email_2 != '' && !isEmailAddr(email_2)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B> of Director of your parks and recreation department/agency.</li>";
	if(phone_3!='' && !isPhoneNo(phone_3)) msg += "<li>" + "Please enter a valid phone number of Community business representative.</li>";
	if(email_3 != '' && !isEmailAddr(email_3)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B> of Community business representative.</li>";
	if(phone_4!='' && !isPhoneNo(phone_4)) msg += "<li>" + "Please enter a valid phone number of Community member partner-1.</li>";
	if(email_4 != '' && !isEmailAddr(email_4)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B> of Community member partner-1.</li>";
	if(phone_5!='' && !isPhoneNo(phone_5)) msg += "<li>" + "Please enter a valid phone number of Community member partner-2.</li>";
	if(email_5 != '' && !isEmailAddr(email_5)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B> of Community member partner-2.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkNominationQuestion3()
{ 
	var total_tennis_facilities = $("total_tennis_facilities").value.strip();
	var master_plan = $("master_plan").value.strip();
	var capital_improvements = $("capital_improvements").value.strip();

	var msg = "<b>Following errors occurred : </b><ul>";
	
	if(total_tennis_facilities == "" || total_tennis_facilities == null ) msg += "<li>Please enter total tennis facilities.</li>";
	if(master_plan == "" || master_plan == null ) msg += "<li>Please enter master plan.</li> ";
	if(capital_improvements == "" || capital_improvements == null ) msg += "<li>Please enter capital improvements.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>")
	{
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkNominationQuestion4()
{ 
	var summary_tennis_prog = $("summary_tennis_prog").value.strip();
	var total_tennis_participants = $("total_tennis_participants").value.strip();
	var top_three_priorities = $("top_three_priorities").value.strip();
	var promote_participation = $("promote_participation").value.strip();
	var education_and_training = $("education_and_training").value.strip();

	var msg = "<b>Following errors occurred : </b><ul>";
	
	if(summary_tennis_prog == "" || summary_tennis_prog == null ) msg += "<li>Please enter summary tennis programme.</li>";
	if(total_tennis_participants == "" || total_tennis_participants == null ) msg += "<li>Please enter total tennis participants.</li> ";
	if(top_three_priorities == "" || top_three_priorities == null ) msg += "<li>Please enter top three priorities.</li>";
	if(promote_participation == "" || promote_participation == null ) msg += "<li>Please enter promote participation information.</li>";
	if(education_and_training == "" || education_and_training == null ) msg += "<li>Please enter education and training information.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>")
	{
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkNominationQuestion5()
{ 
	var population_size = $("population_size").value.strip();
	var square_mileage = $("square_mileage").value.strip();
	var national_recognition = $("national_recognition").value.strip();
	var other_national_recongnition = $("other_national_recongnition").value.strip();

	var msg = "<b>Following errors occurred : </b><ul>";
	
	if(population_size == "" || population_size == null ) msg += "<li>Please enter population size.</li>";
	if(square_mileage == "" || square_mileage == null ) msg += "<li>Please enter square mileage.</li> ";
	if(national_recognition == "" || national_recognition == null ) msg += "<li>Please enter national recognition.</li>";
	if(other_national_recongnition == "" || other_national_recongnition == null ) msg += "<li>Please enter other national recongnition.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>")
	{
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkNominationQuestion6(){
	var gov_email = $("gov_email").value.strip();
	var phone_no = $("phone_no").value.strip();	
	var msg = "<b>Following errors occurred : </b><ul>";
	if(phone_no!='' && !isPhoneNo(phone_no)) msg += "<li>" + "Please enter a valid phone number. (Do not include '-' or '+')</li>";
	if(gov_email == "" || gov_email == null ) msg += "<li>Please enter government official's email address.</li>";
	else if(!isEmailAddr(gov_email)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}



function validate_form (){
	var name = $("name").value.strip();
	var email = $("email").value.strip();
	var city = $("city").value.strip();
	var state = $("state").value.strip();
	var notes = $("notes").value.strip();
	
	var msg = "<b>Following errors occurred : </b><ul>";
	if(name == "" || name == null ) msg += "<li>Please enter your email address.</li>";
	if(email == "" || email == null ) msg += "<li>Please enter your email address.</li>";
	else if(!isEmailAddr(email)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
	if(city == "" || city == null ) msg += "<li>Please enter your city / town.</li>";
	if(state == "" || state == null ) msg += "<li>Please enter your state.</li>";
	if(notes == "" || notes == null ) msg += "<li>Please enter message.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}



function checkNominationQuestion7()
{ 
	var mayor_name = $("mayor_name").value.strip();
	var sign_date = $("sign_date").value.strip();
	var expedite_process = $("expedite_process").value.strip();

	var msg = "<b>Following errors occurred : </b><ul>";
	
	if(mayor_name == "" || mayor_name == null ) msg += "<li>Please enter mayor name.</li>";
	if(sign_date == "" || sign_date == null ) msg += "<li>Please enter sign date.</li> ";
	if(expedite_process == "" || expedite_process == null ) msg += "<li>Please enter expedite process.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>")
	{
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


function checkFile()
{
	var file = $("file").value.strip();

	var msg = "<b>Following errors occurred : </b><ul>";
	
	if(file == "" || file == null ) msg += "<li>Please select file to upload.</li>";
	
	if(msg != "<b>Following errors occurred : </b><ul>")
	{
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else
	{
		$('indicator').show();
		return true;
	}
}




function searchZipcode(component_initials, component_id)
{
	var divToBeUpdated = component_initials+'_'+component_id;
	var component_value = $(component_id).value;
	if(component_value.strip()!="" && component_value.strip()!=null)
	{
		var url='includes/common_ajax.php?item='+component_initials+'&id='+component_id+'&value='+component_value;
		new Ajax.Updater(divToBeUpdated,url,{asynchronous:true,onLoading:function(request){Element.show('indicator')},onComplete:function(request){ Element.hide('indicator')}, evalScripts:true});
	}
	else
	{
		alert("Please provide input for Search.");
	}
}


function checkEmail(component_value, divToBeUpdated, except)
{
	if(component_value.strip()!="" && component_value.strip()!=null)
	{
		if(except!="" && except!="")
		{
			var url='includes/common_ajax.php?item=checkEmail&value='+component_value+'&except='+except;
		}
		else var url='includes/common_ajax.php?item=checkEmail&value='+component_value;
		ajaxObject(divToBeUpdated, url);
	}
	else
	{
		alert("Please enter your email address.");
	}
}

function ajaxObject(divToBeUpdated, url)
{
	new Ajax.Updater(divToBeUpdated,url,{asynchronous:true,onLoading:function(request){Element.show('indicator')},onComplete:function(request){ Element.hide('indicator')}, evalScripts:true});
}


/**
* POP-UP Function
*
* Function for Opening a popup window
* with the object of current form.
*
* @param Form Object myForm Object of Form called
*/
function popup(url) 
{
	 var width  = 716;
	 var height = 650;
	 var left   = (screen.width  - width)/2;
	 var top    = (screen.height - height)/2;
	 var params = 'width='+width+', height='+height;
	 params += ', top='+top+', left='+left;
	 params += ', directories=no';
	 params += ', location=no';
	 params += ', menubar=no';
	 params += ', resizable=yes';
	 params += ', scrollbars=yes';
	 params += ', status=no';
	 params += ', toolbar=no';
	 //var url = "./account_edit.php";
	 newwin=window.open(url,'Popup_Window', params);
	 //newwin=window.open('about:blank','Popup_Window', params);
	 //myForm.target = 'Search';
	 return true;
}


function isEmailAddr(email)
{ 
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	if (!filter.test(email)) return false;
	else return true;
}


function pop_up(url)
{
	window.open(url);
}


function addChild(field)
{
	var numberOfRecords = $(field+"Record").value;
	var html = $(field+"Html").value;
	var num = parseInt(numberOfRecords) + 1;
	document.getElementById(field+"Record").value = num;
	var parent = document.getElementById(field+"DynamicChilds");
	var divIdName = field+num+"Div";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	newdiv.setAttribute("width","100%");
	var loop_val = ""+num;
	//var formdata="<input type='file' size='40' name='lead_proposal["+field.toLowerCase()+"_"+num+"]' />";
	//var formdata="<textarea rows='3' name='follow_up_new[]' id='follow_up_new' cols='50'></textarea>";
	var formdata = html.replace(/####/g,num);
	
	newdiv.innerHTML =  formdata+"&nbsp;<a href=\"javascript:removeChild(\'"+field+"\', \'"+divIdName+"\');\"><img alt='Remove' src='./images/main/remove.gif' align='top' border='0' /></a><br /><br />";
							  
	parent.appendChild(newdiv);
}		
function removeChild(field, divNum)
{
	var parent = document.getElementById(field+"DynamicChilds");
	var olddiv = document.getElementById(divNum);
	parent.removeChild(olddiv);
	//var numberOfRecords = document.getElementById(field+"Record").value;
	//var num = parseInt(numberOfRecords) - 1;
	//document.getElementById(field+"Record").value = num;
}


function checkPolls(){ 
	$("error").hide();
	$("server_message").hide();
	var first_name = $("first_name").value;
	var last_name = $("last_name").value;
	var age = $("age").value;
	var email = $("email").value;
	var voteFor = $("voteFor").value;
	var msg = "<b>Following errors occurred : </b><ul>";
	if(first_name.strip() == "") msg += "<li>Please enter your first name.</li> ";
	if(last_name.strip() == "") msg += "<li>Please enter your last name.</li> ";
	if(email.strip() == "") msg += "<li>Please enter your email address.</li> ";
	else if(!isEmailAddr(email)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
	if(age.strip() == "") msg += "<li>Please enter your age.</li> ";
	/*else if(parseInt(age) == '' || parseInt(age) == null || parseInt(age)<=0) msg += "<li>Please enter your age in numbers.</li> ";*/
	else if( age.strip() != "" && isNaN(age))  msg += "<li>Please enter your age in numbers.</li> ";
	//if($("newsletter").checked != true) msg += "<li>Please subscribe to newsletter.</li> ";
	if(voteFor.strip() == "") msg += "<li>Please select any voting contestent.</li> ";
	if(msg != "<b>Following errors occurred : </b><ul>"){
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
	}
	else{
		var indicator = 'polls_indicator';
		var divToBeUpdated = 'server_message';
		var formToBeSubmitted = 'polls';
		var url='./../includes/common_ajax.php';		
		new Ajax.Updater(divToBeUpdated, url,{onLoading:function(request){Element.show(indicator)},onComplete:function(request){Element.hide(indicator)},parameters:Form.serialize(formToBeSubmitted),asynchronous:true, evalScripts:true});		
	}
}

function showElement(elementId){
	$(elementId).show();
}

function changeVoteFor(status){
	if(status==true) $("voteFor").value = 1;
	else $("voteFor").value = 0;
}


function checkResendVoteInfo()
{ 
	var email = $("email").value;
	var msg = "<b>Following errors occurred : </b><ul>";
	if(email.strip() == "") msg += "<li>Please enter your email address.</li> ";
	else if(!isEmailAddr(email)) msg += "<li>" + "Please enter a valid email address as: <B>yourname@yourdomain.com</B></li>";
	if(msg != "<b>Following errors occurred : </b><ul>")
	{
		msg += "</ul>";
		$("error").show('slow');
		$("error").innerHTML = msg;
		return false;
	}
	else return true;
}


/**
* Focus Function
* Function for setting focus to first textfield of page on page load
*
* @param Field ID field ID of Field to be focussed
*/
function setFocus(field)
{
$(field).focus();
}

/**
* Print Function
* Function for Print the current Page
*
*/
function printpage()
{
	window.print();
}

/**
* Disable Button Function
* Function for disabling the clicked button
* and changing its label simultaneously.
*
*/
function disableIt(component_id, text)
{
	var newLabel;
	if(text!="" && text != null)
	{
		newLabel = text;
	}
	else newLabel = $(component_id).value + 'ing';
	$(component_id).disabled = true;
	$(component_id).value = newLabel + '....';
}

/**
* Show Hide Function
* Function for Show or Hide the component
*
*/
function show_hide(component_id)
{
	$(component_id).toggle('slow');
}

function sort_by(controller, item, action)
{
	if(action!="" && action!=null)
	{
		action = action;
	}
	else action = 'index';
	
	var dir = $(item+'_sort').value;
	var url = '/'+controller+'/'+action+'?sort_by='+item+'&dir='+dir;
	document.location = url
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/**
* Confirm Function
* Function for Confirming user before proceeding
* to performing the request.
*
*/
function confirm_request(text)
{
	confirm('');
}


/**
* Delete Function
* Function for confirming before deleting
* and changing its label simultaneously.
*
*/
function deleteIt(component_id, component_initials, text, indicator_id)
{
	//	alert("sdgtfd = " + indicator_id);
	var newLabel;
	if(text!="" && text != null)
	{
		newLabel = "Are you sure, you want to delete "+text+"?";
	}
	else newLabel = "Are you sure, you want to delete ?";
	var indicator_div = indicator_id;
	/*if(indicator_id!="" && indicator_id != null) indicator_div = indicator_id;
	else indicator_div = "indicator";*/
	//alert("sdgtfd = " + indicator_div);
	var check = confirm(newLabel);
	if(check)
	{
		var divToBeUpdated = component_initials+'_'+component_id;
		var url='./includes/common_ajax.php?item='+component_initials+'&id='+component_id;
		new Ajax.Updater(divToBeUpdated,url,{asynchronous:true,onLoading:function(request){Element.show(indicator_div)},onComplete:function(request){ Element.hide(indicator_div)}, evalScripts:true});
	}
}


/*function getElementsByType(type) {
var _input = document.getElementsByTagName("input");
var k=0;
for (var i=0;i<_input.length;i++) {
if (_input[i].type==type)
k++;
}
alert("Total Number of "+type+" = "+k);
}
function getCheckedElements(type) {
var _input = document.getElementsByTagName("input");
var k=0;
for (var i=0;i<_input.length;i++) {
if (_input[i].type==type && _input[i].checked)
k++;
}
alert("Total Number of "+type+" that are checked = "+k);
}
*/

function number_suffix(givenNum)
{
	if(parseInt(givenNum)>=0)
	{
		var number = suffix = "";
		if(parseInt(givenNum)>=10) number = String(givenNum).substr(-1);
		else number = givenNum;
		switch(number){
			case '1':
				suffix = "st";
				break;
			case '2':
				suffix = "nd";
				break;
			case '3':
				suffix = "rd";
				break;
			default:
				suffix = "th";
				break;
		}
		return suffix;
	}
	//return null;
}

function getCheckedElements(type)
{
	var msg="Sorry, we cannot complete your request.\nKindly provide the missing or incorrect information enclosed below.\n\n";
	var _input = document.getElementsByTagName("input");
	var k=0;
	for (var i=0;i<_input.length;i++) 
	{
		if (_input[i].type==type && _input[i].checked)
		{
			k++;
			var name = _input[i].name.split('_');
			var test_date = 'test_date_'+name[1];
			if(parseInt(_input[i].value)==1 && ($(test_date).value=="" || $(test_date).value==null))
			{
				var suffix = number_suffix(k);
				 msg += "- Please check " + k + suffix + " test date.\n";
			}
		}
	}
	return msg;
}




/**
 * Function for checking session on user-end
 */
function check_session(sessionField, divToBeUpdated, formName, indicator, url, valueToBeSetBefore, inField)
{
	 var session_user_id = $(sessionField).value;
	 if(session_user_id!="" && session_user_id != null)
	 {
		 if(valueToBeSetBefore!="" && valueToBeSetBefore != null && inField!="" && inField != null)
		 {
			 $(inField).value = valueToBeSetBefore;
		 }
		 
	 new Ajax.Updater(divToBeUpdated, url,{
onLoading:function(request){Element.show(indicator)},
onComplete:function(request){Element.hide(indicator)},
parameters:Form.serialize(formName),
asynchronous:true, evalScripts:true});
	 
	 /*new Ajax.Updater(document.createElement('div'),url, {
asynchronous:true, evalScripts:true, onComplete:function(request, json) {Element.hide(indicator);}, onLoading:function(request) {Element.show(indicator);}, parameters:Form.serialize(formName), requestHeaders:['X-Update', "'"+divToBeUpdated+"'"]});*/

	}
	else
	{
		alert("Please Login First.");
	}
	return false;
}


