// JavaScript Document
function setMenuItem() {
	category = document.forms[0].category.options[document.forms[0].category.selectedIndex].value;
	hashIndex = category.indexOf("#");
	if(hashIndex < 0){
		anchorName = "";
		document.forms[0].submit();
	}
	else{
		anchorName = category.substr(hashIndex, category.length);
		window.location.href = anchorName;
	}
}

function checkGiftCertificate() {
	senderName = trimSpaces(document.forms[0].senderName.value);
	if(senderName.length <= 0) {
		alert("Plese enter your name");
		document.forms[0].senderName.focus();
		return false;
	}
	
	senderAddress = trimSpaces(document.forms[0].senderAddress.value);
	if(senderAddress.length <= 0) {
		alert("Plese enter your address");
		document.forms[0].senderAddress.focus();
		return false;
	}

	senderCity = trimSpaces(document.forms[0].senderCity.value);
	if(senderCity.length <= 0) {
		alert("Plese enter your city");
		document.forms[0].senderCity.focus();
		return false;
	}
	
	senderState = trimSpaces(document.forms[0].senderState.value);
	if(senderState.length <= 0) {
		alert("Plese enter your state");
		document.forms[0].senderState.focus();
		return false;
	}

	senderZip = trimSpaces(document.forms[0].senderZip.value);
	if(senderZip.length <= 0) {
		alert("Plese enter your ZIP");
		document.forms[0].senderZip.focus();
		return false;
	}
	
	senderPhone = trimSpaces(document.forms[0].senderPhone.value);
	if(senderPhone.length <= 0) {
		alert("Plese enter your telephone number");
		document.forms[0].senderPhone.focus();
		return false;
	}

	senderEmail = trimSpaces(document.forms[0].senderEmail.value);
	if(senderEmail.length <= 0) {
		alert("Plese enter your email address");
		document.forms[0].senderEmail.focus();
		return false;
	}
	if(!checkEmail(senderEmail)) {
		document.forms[0].senderEmail.focus();
		return false;
	}
	
	certificateQuantity = trimSpaces(document.forms[0].certificateQuantity.value);
	certificateAmount = trimSpaces(document.forms[0].certificateAmount.value);
	if(certificateQuantity.length <= 0 && certificateAmount.length <= 0) {
		if(certificateQuantity.length <= 0) {
			alert("Plese enter the certificate quantity");
			document.forms[0].certificateQuantity.focus();
			return false;
		}
		if(certificateAmount.length <= 0) {
			alert("Plese enter the certificate amount");
			document.forms[0].certificateAmount.focus();
			return false;
		}
	}
	
	document.forms[0].frmAction.value = "send";
}

function printCoupon(couponid){
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 700;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showCouponFrame.php?couponid=" + couponid, "printCoupon", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}

function printWindow() {
	parent.mainFrame.focus();
	window.print(parent.mainFrame);
}

function checkCouponMail() {
	senderName = trimSpaces(document.forms[0].senderName.value);
	senderEmail = trimSpaces(document.forms[0].senderEmail.value);
	receiverEmail = trimSpaces(document.forms[0].receiverEmail.value);
	if(senderName.length <= 0) {
		alert("You have to enter your name.");
		document.forms[0].senderName.focus();
		return false;
	}
	if(senderEmail.length <= 0) {
		alert("You have to enter your email address.");
		document.forms[0].senderEmail.focus();
		return false;
	}
	if(!checkEmail(senderEmail)) {
		document.forms[0].senderEmail.focus();
		return false;
	}
	if(receiverEmail.length <= 0) {
		alert("You have to enter your friend's email address.");
		document.forms[0].receiverEmail.focus();
		return false;
	}
	if(!checkEmail(receiverEmail)) {
		document.forms[0].receiverEmail.focus();
		return false;
	}
	document.forms[0].frmAction.value = "yes";
}

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 checkFeedBack() {
	document.forms[0].visitorName.value = trimSpaces(document.forms[0].visitorName.value);
	if(document.forms[0].visitorName.value.length <= 0) {
		alert("Please enter your name");
		document.forms[0].visitorName.focus();
		return false;
	}

	document.forms[0].emailAddress.value = trimSpaces(document.forms[0].emailAddress.value);
	if(document.forms[0].emailAddress.value.length <= 0) {
		alert("Please enter your email address");
		document.forms[0].emailAddress.focus();
		return false;
	}
	if(!checkEmail(document.forms[0].emailAddress.value)) {
		document.forms[0].emailAddress.focus();
		document.forms[0].emailAddress.select();
		return false;
	}

	document.forms[0].visitorComments.value = trimSpaces(document.forms[0].visitorComments.value);
	if(document.forms[0].visitorComments.value.length <= 0) {
		alert("Please enter your comments");
		document.forms[0].visitorComments.focus();
		return false;
	}
	document.forms[0].frmAction.value = "update";
}


function showPicture(gid,cid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showPicture.php?galleryid=" + gid + "&category=" +cid, "picture", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function checkEmailList() {
	
	firstName = trimSpaces(document.forms[0].firstName.value);
	if(firstName.length <= 0) {
		alert("Please enter your name.");
		document.forms[0].firstName.focus();
		return false;
	}
/*	
	lastName = trimSpaces(document.forms[0].lastName.value);
	if(lastName.length <= 0) {
		alert("Please enter your last name.");
		document.forms[0].lastName.focus();
		return false;
	}
*/	
	subscriberEmail = trimSpaces(document.forms[0].subscriberemail.value);
	if(subscriberEmail.length <= 0) {
		alert("Please enter your email.");
		document.forms[0].subscriberemail.focus();
		return false;
	}
	if(subscriberEmail.length > 0){
		if(!checkEmail(subscriberEmail)){
			document.forms[0].subscriberemail.focus();
			return false;
		}
	}
	
	document.forms[0].frmAction.value = "update";

}
function checkField2(page)
  {
	if(document.investor.userName.value.length<=0) 
	{ 
	alert("Enter the user name"); 
	document.investor.userName.focus();
	if(page=="home")
		return; 
	else
	     return false;
	}
	if(document.investor.password.value.length<=0) 
	{ 
	alert("Enter the password"); 
	document.investor.password.focus();
	if(page=="home")
		return; 
	else
	     return false;
	}
	document.investor.frmAction.value="login";
	document.investor.submit();
 }
function checkListing()
{

	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].street.value=trimSpaces(document.forms[0].street.value);
	if(document.forms[0].street.value.length<=0)
	 {
	 	alert("Enter your street");
		document.forms[0].street.focus();
		return false;
	 }

	   	
	document.forms[0].apartment.value=trimSpaces(document.forms[0].apartment.value);
	if(document.forms[0].apartment.value.length<=0)
	 {
	 	alert("Enter your Apartment");
		document.forms[0].apartment.focus();
		return false;
	 }

	   	
	   	
	document.forms[0].city.value=trimSpaces(document.forms[0].city.value);
	if(document.forms[0].city.value.length<=0)
	 {
	 	alert("Enter your City");
		document.forms[0].city.focus();
		return false;
	 }

	   	
	   	
	document.forms[0].state.value=trimSpaces(document.forms[0].state.value);
	if(document.forms[0].state.value.length<=0)
	 {
		if(document.forms[0].state1.value.length<=0)
		 {
			alert("Enter your State");
			document.forms[0].state1.focus();
			return false;
		 }
		 else if(document.forms[0].country.value=="US")
		 {
			alert("Select your country");
			document.forms[0].country.focus();
			return false;
		 }
	 }

	document.forms[0].phone.value=trimSpaces(document.forms[0].phone.value);
	if(document.forms[0].phone.value.length<=0)
	 {
	 	alert("Enter your Phone");
		document.forms[0].phone.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();
}
 function activate(pic)
 {
	 document.img1.src=pic;
	/* img2.style.visibility='hidden';
	 img3.style.visibility='hidden';
	 img4.style.visibility='hidden';
	 img5.style.visibility='hidden';
 	 img6.style.visibility='hidden';
	 eval(pic+".style.visibility='visible'");*/
 }
function submitSearch(page)
{
	if(page == 'home') {
		val = 'php/';
	}else {val = '';}
	searchKey = trimSpaces(document.search.searchKey.value);
	if(searchKey == '') {
		alert("Enter search string");
		document.search.searchKey.focus();
		return;
	}
	//document.search.action = "displaySearch.php?searchKey=" + searchKey;
	document.search.action = val+"displaySearch.php";
	document.search.submit();
}
function checkKey(page){
	if(window.event.keyCode == 13) {
		if(page == 'home') {
			val = 'php/';
		}else {val = '';}

		searchKey = trimSpaces(document.search.searchKey.value);
		if(searchKey == '') {
			alert("Enter search string");
			document.search.searchKey.focus();
			return false;
		}else {
			document.search.action = val+"displaySearch.php";
			document.search.submit();
		}		
	}
}
function validateFields(from)
{
user_name=trimSpaces(document.loginform.user_name.value);
password=trimSpaces(document.loginform.password.value);
if(user_name.length<=0)
	{
	  alert("Enter the user name");
	  document.loginform.user_name.focus();
	 if(from=="home")
	   return;
	 else
	   return false;
	}
if(password.length<=0)
	{
	  alert("Enter the password");
	  document.loginform.password.focus();
	 if(from=="home")
	   return;
	 else
	   return false;
	}
	document.loginform.frmAction.value="login";
	document.loginform.submit();
}
function checkUserForm()
{
firstName=trimSpaces(document.regform.first_name.value);
lastName=trimSpaces(document.regform.last_name.value);
user_name=trimSpaces(document.regform.user_name.value);
password=trimSpaces(document.regform.password.value);
email=trimSpaces(document.regform.email.value);
if(firstName.length<=0)
{
  alert("Enter your first name");
  document.regform.first_name.focus();
   return false;
}
if(lastName.length<=0)
{
  alert("Enter your last name");
  document.regform.last_name.focus();
   return false;
}
if(email.length<=0)
 {
  alert("Please enter the email");
  document.forms[0].email.focus();
  return false;
 }
 else
 {
	 if(email.length>0)
	 {
		 if(!checkEmail(email))
		 {
		  document.forms[0].email.focus();
		  return false;
		 }
	 }
  }
if(user_name.length<=0)
{
  alert("Enter the user name");
  document.regform.user_name.focus();
   return false;
}
if(password.length<=0)
{
  alert("Enter the password");
  document.regform.password.focus();
   return false;
}

document.regform.frmAction.value="update";
document.regform.submit();
}
function showEventPicture(imgURL, imgType) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	if(imgType == "photo") {
		winWidth = 400;
		winHeight = 400;
	}
	else {
		winWidth = 125;
		winHeight = 100;
	}
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showeventPicture.php?imgURL=" + imgURL, "photograph", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}
function showCalendar1(frmElement, dispElement) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 375;
	winHeight = 300;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showCalendar1.php?frmElement=" + frmElement + "&dispElement=" + dispElement, "Calendar", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=0,resizable=0");
	return;
}
function checkComplaintForm()
{
district_id=trimSpaces(document.forms[0].district_id.value);
panchayat_id=trimSpaces(document.forms[0].panchayat_id.value);
category_id=trimSpaces(document.forms[0].category_id.value);
org_id=trimSpaces(document.forms[0].org_id.value);
officer=trimSpaces(document.forms[0].officer.value);
hdate=trimSpaces(document.forms[0].hdate.value);
nature=trimSpaces(document.forms[0].nature.value);
complaint=trimSpaces(document.forms[0].complaint.value);
suggestion=trimSpaces(document.forms[0].suggestion.value);
if(district_id.length<=0)
 {
  alert("Sorry, there is no district available under this state");
  document.forms[0].district_id.focus();
  return false;
 }
if(panchayat_id.length<=0)
 {
  alert("Sorry, there is no panchayat available under this district");
  document.forms[0].panchayat_id.focus();
  return false;
 }

if(category_id.length<=0)
 {
  alert("Sorry, there is no organization available under this panchayat");
  document.forms[0].category_id.focus();
  return false;
 }
if(org_id.length<=0)
 {
  alert("Sorry, there is no office available under this organization");
  document.forms[0].org_id.focus();
  return false;
 }
if(officer.length<=0)
 {
  alert("Please enter the officer name");
  document.forms[0].officer.focus();
  return false;
 }
 if(hdate.length<=0)
 {
  alert("Please enter the date of incident");
  document.forms[0].date.focus();
  return false;
 }
	if(nature.length<=0)
	 {
	  alert("Please enter the nature of the complaint");
	  document.forms[0].nature.focus();
	  return false;
	 }
	if(complaint.length<=0)
	 {
	  alert("Please enter your complaint");
	  document.forms[0].complaint.focus();
	  return false;
	 }
	if(suggestion.length<=0)
	 {
		alert("Please enter your suggestion");
		document.forms[0].suggestion.focus();
		return false;
	 }
 document.forms[0].frmAction.value="update";
 document.forms[0].submit();
} 
function checkOrgRegForm()
{
org_name=trimSpaces(document.forms[0].org_name.value);
position =trimSpaces(document.forms[0].position.value);
first_name=trimSpaces(document.forms[0].first_name.value);
last_name=trimSpaces(document.forms[0].last_name.value);
category_id=trimSpaces(document.forms[0].category_id.value);
category_new=trimSpaces(document.forms[0].category_new.value);
district_id=trimSpaces(document.forms[0].district_id.value);
district_new=trimSpaces(document.forms[0].district_new.value);
panchayat_id=trimSpaces(document.forms[0].panchayat_id.value);
panchayat_new=trimSpaces(document.forms[0].panchayat_new.value);
telephone=trimSpaces(document.forms[0].telephone.value);
email=trimSpaces(document.forms[0].email.value);
user_name=trimSpaces(document.forms[0].user_name.value);
password=trimSpaces(document.forms[0].password.value);
if(org_name.length<=0)
 {
  alert("Please enter the organization name");
  document.forms[0].org_name.focus();
  return false;
 }
if(position.length<=0)
 {
  alert("Please enter the position");
  document.forms[0].position.focus();
  return false;
 }
 if(first_name.length<=0)
 {
  alert("Please enter the first name");
  document.forms[0].first_name.focus();
  return false;
 }
if(last_name.length<=0)
 {
  alert("Please enter the last name");
  document.forms[0].last_name.focus();
  return false;
 }
if(category_id.length<=0 && category_new.length<=0)
 {
	alert("Please enter the industry");
	document.forms[0].category_new.focus();
	return false;
 }
if(district_id.length<=0 && district_new.length<=0)
 {
  alert("Please enter the district");
  document.forms[0].district_new.focus();
  return false;
 }
if(panchayat_id.length<=0 && panchayat_new.length<=0)
 {
  alert("Please enter the panchayat");
  document.forms[0].panchayat_new.focus();
  return false;
 }
if(telephone.length<=0)
 {
  alert("Please enter the telephone");
  document.forms[0].telephone.focus();
  return false;
 }
if(email.length<=0)
 {
  alert("Please enter the email");
  document.forms[0].email.focus();
  return false;
 }
 else
 {
	 if(email.length>0)
	 {
		 if(!checkEmail(email))
		 {
		  document.forms[0].email.focus();
		  return false;
		 }
	 }
  }
 if(user_name.length<=0)
{
  alert("Enter the user name");
  document.forms[0].user_name.focus();
   return false;
}
if(password.length<=0)
{
  alert("Enter the password");
  document.forms[0].password.focus();
   return false;
}
document.forms[0].frmAction.value="update";
 return;
} 
function openDynWindow(url) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 700;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	window.open(url, "News", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function showCoupon(galleryid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showCouponFrame.php?couponid=" + galleryid , "picture", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}
