function doClear(theText) 
{
     if (theText.value == theText.defaultValue)
 {
         theText.value = ""
     }
 }
function onTextFieldLostFocus(){
document.form2.searchsite.value = "Keyword";
}
function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}

function printWindow() {
	parent.mainFrame.focus();
	window.print(parent.mainFrame);
}
function checkAnnounceForm(flag) {
	name = trimSpaces(document.mainForm.name.value);
	emailid = trimSpaces(document.mainForm.emailid.value);
	desc  = trimSpaces(document.mainForm.desc .value);
	eventdate  = trimSpaces(document.mainForm.event_date .value);
	tilldate  = trimSpaces(document.mainForm.till_date .value);
	subject = trimSpaces(document.mainForm.subject.value);
	if(subject.length <= 0) {
			alert("Please provide the subject before submitting the form");
			document.mainForm.subject.focus();
			return false;
		}
	if(name.length <= 0) {
		alert("Please provide your name before submitting the form");
		document.mainForm.name.focus();
		return false;
	}
	if(emailid.length <= 0) {
		alert("Please provide your email address before submitting the form");
		document.mainForm.emailid.focus();
		return false;
	}
	if(!checkEmail(emailid)) {
		document.mainForm.emailid.focus();
		return false;
	}
	if(eventdate.length <= 0) {
		alert("Please fill the event date before submitting the form");
		document.mainForm.event_date.focus();
		return false;
	}
	if(tilldate.length <= 0) {
		alert("Please mention the date till before submitting the form");
		document.mainForm.till_date.focus();
		return false;
	}
	if(desc.length <= 0) {
		alert("Please mention your announcement before submitting the form");
		document.mainForm.desc.focus();
		return false;
	}
	document.mainForm.frmAction.value = "update";
}


function checkForm(flag) {
	name = trimSpaces(document.mainForm.name.value);
	emailid = trimSpaces(document.mainForm.emailid.value);
	comments  = trimSpaces(document.mainForm.comments .value);
	subject = trimSpaces(document.mainForm.subject.value);
	if(subject.length <= 0) {
			alert("Please provide the subject before submitting the form");
			document.mainForm.subject.focus();
			return false;
		}
	if(name.length <= 0) {
		alert("Please provide your name before submitting the form");
		document.mainForm.name.focus();
		return false;
	}
	if(emailid.length <= 0) {
		alert("Please provide your email address before submitting the form");
		document.mainForm.emailid.focus();
		return false;
	}
	if(!checkEmail(emailid)) {
		document.mainForm.emailid.focus();
		return false;
	}

	if(comments.length <= 0) {
		alert("Please mention your queries before submitting the form");
		document.mainForm.comments.focus();
		return false;
	}
	document.mainForm.frmAction.value = "update";
}
/*function checkFeedBack() {  
	document.forms[0].lastName.value = trimSpaces(document.forms[0].lastName.value);
	if(document.forms[0].lastName.value.length <= 0) {
		alert("Please enter your Last name");
		document.forms[0].lastName.focus();
		return false;
	}
	document.forms[0].firstName.value = trimSpaces(document.forms[0].firstName.value);
	if(document.forms[0].firstName.value.length <= 0) {
		alert("Please enter your First Name");
		document.forms[0].firstName.focus();
		return false;
	}

	document.forms[0].email.value = trimSpaces(document.forms[0].email.value);
	if(document.forms[0].email.value.length <= 0) {
		alert("Please enter your email address");
		document.forms[0].email.focus();
		return false;
	}
	if(!checkEmail(document.forms[0].email.value)) {
		document.forms[0].email.focus();
		document.forms[0].email.select();
		return false;
	}
	document.forms[0].frmAction.value = "update";
}*/

function checkFeedBack() { 
	document.forms[1].visitorName.value = trimSpaces(document.forms[1].visitorName.value);
	if(document.forms[1].visitorName.value.length <= 0) {
		alert("Please enter your name");
		document.forms[1].visitorName.focus();
		return false;
	}

	document.forms[1].emailAddress.value = trimSpaces(document.forms[1].emailAddress.value);
	if(document.forms[1].emailAddress.value.length <= 0) {
		alert("Please enter your email address");
		document.forms[1].emailAddress.focus();
		return false;
	}
	if(!checkEmail(document.forms[1].emailAddress.value)) {
		document.forms[1].emailAddress.focus();
		document.forms[1].emailAddress.select();
		return false;
	}

	document.forms[1].visitorComments.value = trimSpaces(document.forms[1].visitorComments.value);
	if(document.forms[1].visitorComments.value.length <= 0) {
		alert("Please enter your comments");
		document.forms[1].visitorComments.focus();
		return false;
	}
	document.forms[1].frmAction.value = "update";
}

function checkAlbumPhotos(frmType) {
	caption = trimSpaces(document.forms[1].caption.value);
	icon = trimSpaces(document.forms[1].icon.value);
	photograph = trimSpaces(document.forms[1].photograph.value);
	
	
	if(caption.length <= 0) {
		alert("Plese add a caption");
		document.forms[1].caption.focus();
		return false;
	}
	if(frmType != "modify") {
		if(icon.length <= 0) {
			alert("Plese select an icon image");
			document.forms[1].icon.focus();
			return false;
		}
		if(photograph.length <= 0) {
			alert("Plese select a photograph");
			document.forms[1].photograph.focus();
			return false;
		}
	}
	document.forms[1].frmAction.value = "update";
}
function checkPhotos() {
	
	first_name = trimSpaces(document.forms[1].first_name.value);
	if(first_name.length <= 0) {
		alert("Please enter your first name.");
		document.forms[1].first_name.focus();
		return false;
	}
	last_name = trimSpaces(document.forms[1].last_name.value);
	if(last_name.length <= 0) {
		alert("Please enter your last name.");
		document.forms[1].last_name.focus();
		return false;
	}
	email = trimSpaces(document.forms[1].email.value);
	if(email.length <= 0) {
		alert("Please enter your email.");
		document.forms[1].email.focus();
		return false;
	}
	if(email.length > 0){
		if(!checkEmail(email)){
			document.forms[1].email.focus();
			return false;
		}
	}
document.forms[1].frmAction.value = "update";
	document.forms[1].submit();
}
//function to check user submitted photo from the list
function delSubmittedPhotos(toDo) {
	rowSelected = false;
	if(document.forms[1].elements["user_id[]"].length > 0) {
		for(itemCount = 0; itemCount < document.forms[1].elements["user_id[]"].length; itemCount++) {
			if(document.forms[1].elements["user_id[]"][itemCount].checked) {
				rowSelected = true;
			}
		}
	}
	else {
		if(document.forms[1].elements["user_id[]"].checked) {
			rowSelected = true;
		}
	}
	
	if(toDo == "reject") {
		actType = "deletion";
	}
	else {
		actType = "approval";
	}
	
	if(!rowSelected) {
		alert("No items selected for " + actType);
		return false;
	}
	else {
		if(toDo == "reject") {
			if(!confirm("Do you really want to reject and delete these items?")) {
				return false;
			}
		}
	}
	document.forms[1].frmAction.value = toDo;
	document.forms[1].submit();
}
function checkSubscription(action)
{

 if(action=="sub")
  {
	document.forms[0].lastName.value=trimSpaces(document.forms[0].lastName.value);
	if(document.forms[0].lastName.value.length<=0)
	 {
	 	alert("Enter your Last Name");
		document.forms[0].lastName.focus();
		return false;
	 }

	document.forms[0].firstName.value=trimSpaces(document.forms[0].firstName.value);
	if(document.forms[0].firstName.value.length<=0)
	 {
	 	alert("Enter your First Name");
		document.forms[0].firstName.focus();
		return false;
	 }

	   	
	document.forms[0].email.value=trimSpaces(document.forms[0].email.value);
	if(document.forms[0].email.value.length<=0)
	 {
	 	alert("Enter Email Id");
		document.forms[0].email.focus();
		return false;
	 }
	else
	 {
	   if(!checkEmail(document.forms[0].email.value))
	   {
		document.forms[0].email.focus();
	    return false;
	   }
	 }  	 
	 
	document.forms[0].frmAction.value="update";
	document.forms[0].submit();
 }
 else
  {	
  	document.forms[0].email.value=trimSpaces(document.forms[0].email.value);
	if(document.forms[0].email.value.length<=0)
	 {
	 	alert("Enter Email Id");
		document.forms[0].email.focus();
		return false;
	 }
	else
	 {
	   if(!checkEmail(document.forms[0].email.value))
	   {
	    return false;
	   }
	 }  	 
	 
	document.forms[0].frmAction.value="delete";
	alert();
	document.forms[0].submit();
}
}

function checkVote() { 
	count = document.form1.poll_option_id.length;
	pollSelect = false;
	for(i = 0; i < count; ++i) {
		if(document.form1.poll_option_id[i].checked) {
			pollSelect = true;
			break;
		}
	}
	if(!pollSelect) {
		alert("Select an answer to vote");
		return false;
	}
	document.form1.action ='index.php';
	document.form1.frmAction.value = 'Vote';
	document.form1.submit();
}
 function doClear(theText) 
{
     if (theText.value == theText.defaultValue)
 {
         theText.value = ""
     }
 }
function checkKey(page){
	if(window.event.keyCode == 13) {
		if(page == 'home') {
			val = 'php/';
		}else {val = '';}

		searchKey = document.commonform.searchKey.value;
		if(searchKey == '') {
			alert("Enter search string");
			document.commonform.searchKey.focus();
			return false;
		}else {
			document.commonform.action = val+"displaySearch.php";
			document.commonform.submit();
		}		
	}
}
function searchFromHome(page)
{
	if(page == 'home') {
		val = 'php/';
	}else {val = '';}
	searchKey = document.commonform.searchKey.value;
	if(searchKey == '') {
		alert("Enter search string");
		document.commonform.searchKey.focus();
		if(page=='home')
			return false;
		else
    		return false;
	}
	document.commonform.action = val+"displaySearch.php";
	document.commonform.submit();
}
function chklang()
{
if(document.commonform.selectlang.options[document.commonform.selectlang.selectedIndex].value=="MAL")
window.location.href="http://www.keralapathram.com";
}
function chkstate()
{
link1="http://"+document.commonform.state.options[document.commonform.state.selectedIndex].value;
window.open(link1);
}
function chkcity()
{
link1="http://"+document.commonform.city.options[document.commonform.city.selectedIndex].value;
window.open(link1);
}
function chkcategory()
{
if(document.commonform.category.options[document.commonform.category.selectedIndex].value=="X")
   {
    alert("Please select one under that category");
    document.commonform.category.focus();
   }
else
   {
    link1="http://"+document.commonform.category.options[document.commonform.category.selectedIndex].value;
    window.open(link1);
   }
  }
  
  
 //////petions section//////
 
 function chkPetitions()
{

	petitionTitle = (document.form1.petition_title.value);
	category = (document.form1.category.value);
	//description = (document.form1.description.value); 
	organisation = (document.form1.organisation.value); 
	contactPerson = (document.form1.contact_person.value); 
	phone = (document.form1.phone.value); 
	email = (document.form1.email.value);
	//startDate = trimSpaces(document.form1.start_date.value);
	//endDate = trimSpaces(document.form1.end_date.value);
	address = (document.form1.address.value);
	city = (document.form1.city.value);
	country = (document.form1.country.value);
	zip = (document.form1.zip.value);

	if(petitionTitle.length <= 0)
	{
		alert("Please enter Petition Title");
		document.form1.petition_title.focus();
		return false;
	}
	if(category.length <= 0)
	{
		alert("Please select any category");
		document.form1.category.focus();
		return false;
	}
	if(description.length <= 0)
	{
		alert("Please enter your petition statement");
		document.form1.description.focus();
		return false;
	}
	/*if(startDate.length <= 0)
	{
		alert("Please enter Start Date");
		return false;
	}
	if(endDate.length <= 0)
	{
		alert("Please enter End Date");
		return false;
	}*/
	if(organisation.length <= 0)
	{
		alert("Please enter Petition Author");
		document.form1.organisation.focus();
		return false;
	}		
	if(contactPerson.length <= 0)
	{
		alert("Please enter Contact Person's Name");
		document.form1.contact_person.focus();
		return false;
	}
	if(email.length <= 0)
	{
		alert("Please enter Email ID");
		document.form1.email.focus();
		return false;
	}
	if(!checkEmail(document.form1.email.value))
	{
		document.form1.email.select();
		return false;
	}
	if(address.length <= 0)
	{
		alert("Please enter Address");
		document.form1.address.focus();
		return false;
	}
	if(city.length <= 0)
	{
		alert("Please enter City");
		document.form1.city.focus();
		return false;
	}
	if(country.length <= 0)
	{
		alert("Please select a Country");
		document.form1.country.focus();
		return false;
	}	
	if(zip.length <= 0)
	{
		alert("Please enter the Zip Code");
		document.form1.zip.focus();
		return false;
	}

	document.form1.frmAction.value="Add";
	
}
function validateSign()
{
    firstName = document.forms[1].first_name.value;
    lastName =document.forms[1].last_name.value;	  
	email = document.forms[1].email.value;
	city = document.forms[1].city.value;
	country = document.forms[1].country.value;

	if(firstName.length <= 0)
	{
		alert("Please enter First Name");
		document.forms[1].first_name.focus();
		return false;
	}
	if(lastName.length <= 0)
	{
		alert("Please select Last Name");
		document.forms[1].last_name.focus();
		return false;
	}
	if(email.length <= 0)
	{
		alert("Please enter Email ID");
		document.forms[1].email.focus();
		return false;
	}
	if(!checkEmail(document.forms[1].email.value))
	{
		document.forms[1].email.select();
		return false;
	}
	if(city.length <= 0)
	{
		alert("Please enter City");
		document.forms[1].city.focus();
		return false;
	}
	if(country.length <= 0)
	{
		alert("Please select a Country");
		document.forms[1].country.focus();
		return false;
	}	
	document.forms[1].frmAction.value="Add";
	
}
 
 /////////////////////////////
 
 function checkPhotoModify(frmAction) {
	if(frmAction == "remove") {
		anySelected = false;
		itemLength = document.forms[1].elements["pid[]"].length;
		if(itemLength > 0) {
			for(photos = 0; photos < itemLength; photos ++) {
				if(document.forms[1].elements["pid[]"][photos].checked) {
					anySelected = true;
				}
			}
		}
		else {
			if(document.forms[1].elements["pid[]"].checked) {
				anySelected = true;
			}
		}
		if(anySelected) {
			if(!confirm("Do you really want to delete the selected photos?")) {
				return false;
			}
		}
		else {
			alert("Nothing selected for deletion");
			return false;
		}
	}
}
function removePhoto(photoUrl, photoField) {
	if(photoUrl.length > 0) {
		if(confirm("Do you really want to delete this photo?")) {
			document.forms[1].frmAction.value = "removePhoto";
			document.forms[1].photoURL.value = photoUrl;
			document.forms[1].photoField.value = photoField;
			document.forms[1].submit();
		}
		else {
			return;
		}
	}
}

function showIcon(iconUrl,menu) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 300;
	winHeight = 300;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showIcon.php?iconUrl=" + iconUrl + "&menu=" + menu,"iconURL","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=0,resizable=0");
}
function showPhoto(photoUrl,menu) {

	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showIcon.php?iconUrl=" + photoUrl + "&menu=" + menu,"photoURL","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
