function showPicture(galleryid, photoType,categoryid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showPictureFrame.php?galleryid=" + galleryid + "&photoType=" + photoType + "&category="+categoryid, "picture", "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);
	window.print(self);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); 
  return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
	v=args[i+2];
    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
	}
    obj.visibility=v; 
  }
}

function printRegistration() {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 650;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("regFormFrame.php", "regForm", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function checkRegistration() {
	if(trimSpaces(document.forms[0].username.value).length <= 0) {
		alert("Please provide a username");
		document.forms[0].username.focus();
		return false;
	}
	if(trimSpaces(document.forms[0].password.value).length <= 0) {
		alert("Please provide a password");
		document.forms[0].password.focus();
		return false;
	}
	document.forms[0].frmAction.value = "update";
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showNews(newsid, pageType) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	if(pageType == "home") {
		pageUrl = "php/";
	}
	else {
		pageUrl = "";
	}

	window.open(pageUrl + "showNewsFrame.php?newsid=" + newsid, "news", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function checkMemberCategory(optVal) {
	if(optVal.length <= 0) {
//		document.forms[0].otherCategory.readonly = false;
		document.forms[0].otherCategory.focus();
	}
	else {
//		document.forms[0].otherCategory.blur();
//		document.forms[0].otherCategory.readonly = true;
	}
}

//function checkSubscription(fromPage) {
	
	/*firstName = trimSpaces(document.forms[0].firstName.value);
	if(firstName.length <= 0) {
		alert("Please enter your first 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;
		}
	}
	if(fromPage == 'home')
	{
	document.forms[0].submit();
	}
	else
	{
	document.forms[0].frmAction.value = "update";
	}
}*/

function checkSubscription(action)
{

 if(action=="sub")
  {
	document.forms[1].lastName.value=trimSpaces(document.forms[1].lastName.value);
	if(document.forms[1].lastName.value.length<=0)
	 {
	 	alert("Enter your Last Name");
		document.forms[1].lastName.focus();
		return false;
	 }

	document.forms[1].firstName.value=trimSpaces(document.forms[1].firstName.value);
	if(document.forms[1].firstName.value.length<=0)
	 {
	 	alert("Enter your First Name");
		document.forms[1].firstName.focus();
		return false;
	 }

	   	
	document.forms[1].email.value=trimSpaces(document.forms[1].email.value);
	if(document.forms[1].email.value.length<=0)
	 {
	 	alert("Enter Email Id");
		document.forms[1].email.focus();
		return false;
	 }
	else
	 {
	   if(!checkEmail(document.forms[1].email.value))
	   {
		document.forms[1].email.focus();
	    return false;
	   }
	 }  	 
	 
	document.forms[1].frmAction.value="update";
	document.forms[1].submit();
 }
 else
  {	
  	document.forms[1].email.value=trimSpaces(document.forms[1].email.value);
	if(document.forms[1].email.value.length<=0)
	 {
	 	alert("Enter Email Id");
		document.forms[1].email.focus();
		return false;
	 }
	else
	 {
	   if(!checkEmail(document.forms[1].email.value))
	   {
	    return false;
	   }
	 }  	 
	 
	document.forms[1].frmAction.value="delete";
	alert();
	document.forms[1].submit();
}
}

function showMemberList(catId, pageType) {
	if(catId.length > 0) {
		if(pageType == "home") {
			document.forms[0].action = "php/0100fram.php";
			document.forms[0].linkid.value = "3";
		}
		document.forms[0].submit();
	}
}

function goDiscoverPage(linkId, pageType) {
	if(linkId.length > 0) {
		document.forms[0].submit();
	}
}

function takeToEvent(eventRef) {
	window.location.href = window.location.href + "#" + eventRef;
	return;
}

function checkContact() {
	visitorName = trimSpaces(document.forms[1].visitorName.value);
	visitorEmail = trimSpaces(document.forms[1].visitorEmail.value);
	visitorPhone = trimSpaces(document.forms[1].visitorPhone.value);
	visitorComments = trimSpaces(document.forms[1].visitorComments.value);
	
	if(visitorName.length <= 0) {
		alert("Please provide your name before submitting the form");
		document.forms[1].visitorName.focus();
		return false;
	}
	
	if(visitorEmail.length <= 0) {
		alert("Please provide your email address before submitting the form");
		document.forms[1].visitorEmail.focus();
		return false;
	}
	
	if(!checkEmail(visitorEmail)) {
		document.forms[1].visitorEmail.focus();
		return false;
	}
	
	if(visitorComments.length <= 0) {
		alert("Please mention your queries or suggestions before submitting the form");
		document.forms[1].visitorComments.focus();
		return false;
	}
	document.forms[1].frmAction.value = "send";
}

function checkSelectDD() {
	category = document.topform.categoryidtop.options[document.topform.categoryidtop.selectedIndex].value;
	if(category.length > 0) {
		document.topform.submit();
	}
	return;
}

function goDropDown(pageType) {
	if(document.forms[0].categoryid.selectedIndex == 0) {
		document.forms[0].linkid.value = 1;
		document.forms[0].submit();
	}
	else if(document.forms[0].categoryid.selectedIndex > 1) {
		document.forms[0].linkid.value = 1;
		document.forms[0].submit();
	}
}

function showEvents(eventid, eventtype) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 600;
	winHeight = 500;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	
	window.open("showEventFrame.php?eventid=" + eventid + "&eventtype=" + eventtype, "events", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}
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 checkemailSend()
{
	
  	document.forms[1].remail.value=trimSpaces(document.forms[1].remail.value);
	if(document.forms[1].remail.value.length<=0)
	 {
	 	alert("Enter Recepients Email Id");
		document.forms[1].remail.focus();
		return false;
	 }
	else
	 {
	   if(!checkEmail(document.forms[1].remail.value))
	   {
	    return false;
	   }
	 }  	 
	 
	if(document.forms[1].yemail.value.length<=0)
	 {
	 	alert("Enter your Email Id");
		document.forms[1].yemail.focus();
		return false;
	 }
	else
	 {
	   if(!checkEmail(document.forms[1].yemail.value))
	   {
	    return false;
	   }
	 }  	 
	document.forms[1].frmAction.value="update";
    return;
}
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 checkForm(flag) {
	name = trimSpaces(document.mainForm.name.value);
	emailid = trimSpaces(document.mainForm.emailid.value);
	comments  = trimSpaces(document.mainForm.comments .value);
	if(flag!="F" && flag!="I")
	{
		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(flag=="L")
    {
		politician = trimSpaces(document.mainForm.politician.value);
		leadership  = trimSpaces(document.mainForm.leadership.value);
		if(politician.length <= 0) 
		{
			alert("Please provide the name of politician before submitting the form");
			document.mainForm.politician.focus();
			return false;
		}
			if(leadership.length <= 0) 
		{
			alert("Please provide the leadership of politician before submitting the form");
			document.mainForm.leadership.focus();
			return false;
		}
	}
	if(flag=="L" || flag=="P")
    {
		politicalparty  = trimSpaces(document.mainForm.politicalparty.value);
		if(politicalparty.length <= 0) 
		{
			alert("Please provide the name of Political Party before submitting the form");
			document.mainForm.politicalparty.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 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 ='displayPoll.php';
	document.form1.frmAction.value = 'Vote';
	document.form1.submit();
}

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.form1.searchKey.value);
		if(searchKey == '') {
			alert("Enter search string");
			document.form1.searchKey.focus();
			return false;
		}else {
			document.form1.action = val+"displaySearch.php";
			document.form1.submit();
		}		
	}
}
function checkMailing(){

	firstName = trimSpaces(document.forms[1].firstName.value);
	if(firstName.length <= 0) {
		alert("Please enter your first name.");
		document.forms[1].firstName.focus();
		return false;
	}
	
	lastName = trimSpaces(document.forms[1].lastName.value);
	if(lastName.length <= 0) {
		alert("Please enter your last name.");
		document.forms[1].lastName.focus();
		return false;
	}
	
	subscriberEmail = trimSpaces(document.forms[1].subscriberEmail.value);
	if(subscriberEmail.length <= 0) {
		alert("Please enter your email.");
		document.forms[1].subscriberEmail.focus();
		return false;
	}
	if(subscriberEmail.length > 0){
		if(!checkEmail(subscriberEmail)){
			document.forms[1].subscriberEmail.focus();
			return false;
		}
	}
	
	document.forms[1].frmAction.value = "yes";

}
function valApprove()
{
	document.forms[1].frmAction.value ="approve";
	document.forms[1].submit();

}
function valPetdelete(toDo) {
	rowSelected = false;
	if(document.forms[1].elements["petDel[]"].length > 0) {
		for(itemCount = 0; itemCount < document.forms[1].elements["petDel[]"].length; itemCount++) {
			if(document.forms[1].elements["petDel[]"][itemCount].checked) {
				rowSelected = true;
			}
		}
	}
	else {
		if(document.forms[1].elements["petDel[]"].checked) {
			rowSelected = true;
		}
	}
	
	if(toDo == "reject") {
		actType = "deletion";
	}
	else {
		actType = "approval";
	}
	
	if(!rowSelected) {
		alert("No entries selected for " + actType);
		return false;
	}
	else {
		if(toDo == "reject") {
			if(!confirm("Do you really want to delete these photos?")) {
				return false;
			}
		}
	}
	document.forms[1].frmAction.value ="deletePhotos";
	document.forms[1].submit();
}

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 searchFromHome(page)
{
	if(page == 'home') {
		val = 'php/';
	}else {val = '';}
	searchKey = trimSpaces(document.form1.searchKey.value);
	if(searchKey == '') {
		alert("Enter search string");
		document.form1.searchKey.focus();
		if(page=='home')
			return false;
		else
    		return false;
	}
	document.form1.action = val+"displaySearch.php";
	document.form1.submit();
}
 function doClear(theText) 
{
     if (theText.value == theText.defaultValue)
 {
         theText.value = ""
     }
 }

function openDynWindow(url,width,height) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = width;
	winHeight = height;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	window.open(url, "win", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
