//--------------------------------------------------------------------------
//Function to validate main search form
//-------------------------------------------------------------------------
function chksearchform()
{
	var msg = "";
	if (document.searchform.keywords.value == "Search" || document.searchform.keywords.value == "") {msg = msg + "Enter keywords to be Searched.\n";}
	if (document.searchform.cat.value == "") {msg = msg + "Select Category.\n";}
	if (msg != "")
	{
		alert(msg);
	}
	else
	{
		document.searchform.submit();
	}
	
}

//--------------------------------------------------------------------------
//Function to show/hide divs of events page
//-------------------------------------------------------------------------
function st2new(n)
{
	for(i=1;i<=5;i++)
	{

		if (n==i)
		{
			showDiv('helptalk_dd'+n);
		}
		else
		{
			hideDiv('helptalk_dd'+i);
		}
	}
}
function showDiv(divnm)
{
		document.getElementById(divnm).style["display"]="block" ;
		document.getElementById(divnm).style["visibility"]="visible" ;
}

function hideDiv(divnm)
{
		document.getElementById(divnm).style["display"]="none" ;
		document.getElementById(divnm).style["visibility"]="hidden" ;
}

//-----------------------------------------------------------------------------
//Pagination dropdown redirection for news.php
//-----------------------------------------------------------------------------
function redirect_pg_news(url)
{
	document.location=url+'&pageno='+document.getElementById('redirectid').value;
}

//-----------------------------------------------------------------------------
//Pagination dropdown redirection
//-----------------------------------------------------------------------------
function redirect_pg(url)
{
	document.location=url+'?pageno='+document.getElementById('redirectid').value;
}

//-------------------------------------------------------------
//Function to preload images
//--------------------------------------------------------------
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_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_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_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];}
}

//-------------------------------------------------------------
//Validate Ask the Librarian Form
//--------------------------------------------------------------
function ask_the_librarian_validate()
{
	var msg = "";
	
	
	if (document.ask_the_librarian.patient_name.value == "") { msg = msg + 'Name \n';}
	if (document.ask_the_librarian.email.value == "") { msg = msg + 'Email \n';}
	else
	{
		var emailReegxp = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/;
		if (emailReegxp.test(document.ask_the_librarian.email.value) != true) { msg = msg + 'Invalid Email \n'; }
	}
	

	if (document.ask_the_librarian.required_info.value == "") { msg = msg + 'Required Information \n';}
	if (document.ask_the_librarian.queries.value == "") { msg = msg + 'Complaints or Symptoms \n';}
	if (document.ask_the_librarian.sec_code.value == "") { msg = msg + 'Security Code \n';}
	
	
	
		
	if (msg != "")
	{
		alert("Please fill in following details \n\n"+msg);
	}
	else if (!document.ask_the_librarian.terms.checked)
	{
		alert("Please accept terms and conditions by clicking checkbox");
	}
	else
	{
		document.ask_the_librarian.submit();
	}

}

//----------------------------------------------------------------------
//Function to check "Search Events by keywords" form
//----------------------------------------------------------------------
function chkeve_form()
{
	
	if (document.eve_form.eve_keywords.value == "" || document.eve_form.eve_keywords.value == "Search by Keywords")
	{
		alert("Please enter keywords.");
		return false;
	}
	
}

//----------------------------------------------------------------------
//Function to disable tobacco form fields if 'no' radio buton is checked
//-----------------------------------------------------------------------
function disablefields1(ans)
{
	
	if (ans == "no")
	{
		for(var i=0;i<=document.ask_the_librarian.tobacco_type.length-1;i++)
		{
			document.ask_the_librarian.tobacco_type[i].disabled = true;
		}	
		
		document.ask_the_librarian.tobaccoyrs.style.background = "#DDDDDD";
		document.ask_the_librarian.tobaccoyrs.disabled = true;
	
		document.ask_the_librarian.tobaccoquantity.style.background = "#DDDDDD";
		document.ask_the_librarian.tobaccoquantity.disabled = true;
	}
	else
	{
		for(var i=0;i<=document.ask_the_librarian.tobacco_type.length-1;i++)
		{
			document.ask_the_librarian.tobacco_type[i].disabled = false;
		}	
		
		document.ask_the_librarian.tobaccoyrs.style.background = "#FFFFFF";
		document.ask_the_librarian.tobaccoyrs.disabled = false;
	
		document.ask_the_librarian.tobaccoquantity.style.background = "#FFFFFF";
		document.ask_the_librarian.tobaccoquantity.disabled = false;
	}	
	
	
}


//-------------------------------------------------------------
//Function to check login form
//--------------------------------------------------------------
function chkloginform()
{

	var msg = "";
	if (document.loginform.email.value == "") { msg = msg + "Email\n";}
	if (document.loginform.password.value == "") { msg = msg + "Password\n";}

	if (msg != "")
	{
		alert("Please fill in following fields\n\n"+msg);
		return false;
	}
	
}

//-------------------------------------------------------------
//Function to submit redirect form in patients login  
//-------------------------------------------------------------
function redirect(id)
{
	document.redirectform.ticket_no.value = id;
	document.redirectform.submit();
}

function chknewpostform()
{
	var msg = "";
	

	if (document.newpostform.sub.value == "") { msg = msg + "Subject\n";}
	if (document.newpostform.newmessage.value == "") { msg = msg + "Message\n";}
	
	if (msg != "") 
	{ 
		alert('Please fill in following fields\n\n'+msg);
		return false;
	}
}

//------------------------------------------------------------------
// Function to validate patient's forgot password form
//------------------------------------------------------------------
function chkfgpwdform()
{
	var msg = "";
	if (document.fgpwdform.email.value == "") { msg = msg + "Email\n";}
	if (document.fgpwdform.security_code.value == "") { msg = msg + "Verification Code\n";}
	if (msg != "")
	{
		alert("Please fill in following fields\n\n"+msg);
		return false;
	}

}

//------------------------------------------------------------------
// Function to validate patient's change password form
//------------------------------------------------------------------
function chk_chpasswordform()
{
	//alert('hi');
	//return false;
	var msg = "";
	if (document.chpasswordform.currpwd.value == "") { msg = msg + "Current Password\n";}
	if (document.chpasswordform.newpwd.value == "") { msg = msg + "New Password\n";}
	if (document.chpasswordform.renewpwd.value == "") { msg = msg + "Confirm New Password\n";}
	if (msg != "")
	{
		alert("Please fill in following fields\n\n"+msg);
		return false;
	}
	else if (document.chpasswordform.newpwd.value != document.chpasswordform.renewpwd.value)
	{
		alert(document.chpasswordform.newpwd.value);
		alert(document.chpasswordform.renewpwd.value);
		
		alert("New Passwords do not match.");
		
		return false;
	}
	
}

//------------------------------------------------------------------
// Function to validate patient's change password form
//------------------------------------------------------------------
function mb_formvalidate()
{
	var msg = "";

	if (document.mb_form.subject.value == "") { msg = msg + "Subject \n"; }
	if (document.mb_form.message.value == "") { msg = msg + "Message \n"; }
	if (document.mb_form.name.value == "") { msg = msg + "Name \n"; }
	if (document.mb_form.name.value == "") { msg = msg + "Email \n"; }
	else
	{
		var emailReegxp = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/;
		if (emailReegxp.test(document.mb_form.email.value) != true) { msg = msg + 'Invalid Email \n'; }
	}
	if (document.mb_form.security_code.value == "") { msg = msg + "Code \n"; }
	if (!document.mb_form.tos.checked) { msg = msg + "Agree to Terms Of Service \n"; }

	if (msg  == "")
	{
		document.mb_form.submit();
	}
	else
	{
		alert("Please fill the following fields correctly \n\n" + msg);
	}

}

//------------------------------------------------------------------
// Function to show humour
//------------------------------------------------------------------
function show_humour()
{
	document.location = "humour.php?id="+document.getElementById('humour_id').value;
}

//------------------------------------------------------------------
// Function to validate 'add an entry to directory' form
//------------------------------------------------------------------
function chkdirpostform()
{
	var msg = "";
	if (document.dirpostform.name.value == "") { msg = msg + "Name \n";}
	if (document.dirpostform.dircat_id.value == "") { msg = msg + "Category \n";}
	if (document.dirpostform.profile.value == "") { msg = msg + "Profile \n";}
	if (document.dirpostform.address.value == "") { msg = msg + "Address \n";}
	if (document.dirpostform.dirstate_id.value == "") { msg = msg + "State \n";}
	if (document.dirpostform.city.value == "") { msg = msg + "City \n";}
	if (document.dirpostform.pincode.value == "") { msg = msg + "Pincode \n";}
	if (document.dirpostform.contact_person.value == "") { msg = msg + "Contact Person \n";}
	if (document.dirpostform.phone.value == "") { msg = msg + "Phone \n";}
	if (document.dirpostform.mobile.value == "") { msg = msg + "Mobile \n";}
	if (document.dirpostform.email.value == "") { msg = msg + "Email \n";}
	else
	{
		var emailReegxp = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/;
		if (emailReegxp.test(document.dirpostform.email.value) != true) { msg = msg + 'Invalid Email \n'; }
	}
	if (document.dirpostform.poster_name.value == "") { msg = msg + "Your Name \n";}
	if (document.dirpostform.poster_email.value == "") { msg = msg + "Your Email \n";}
	if (document.dirpostform.poster_phone.value == "") { msg = msg + "Your Phone \n";}
	if (document.dirpostform.poster_address.value == "") { msg = msg + "Your Address \n";}
	if (document.dirpostform.poster_pincode.value == "") { msg = msg + "Your Pincode \n";}
	if (document.dirpostform.poster_city.value == "") { msg = msg + "Your City \n";}
	
	if (msg != "")
	{
		alert("Please fill in following fields\n\n"+msg);
		return false;
	}
	
}

function showhide(ind)
{
	if (ind == 1)
	{
		document.getElementById('spdiv').style["display"]="block" ;
		document.getElementById('spdiv').style["visibility"]="visible" ;
		
		document.getElementById('spdiv2').style["display"]="block" ;
		document.getElementById('spdiv2').style["visibility"]="visible" ;
	}
	else
	{
		document.getElementById('spdiv').style["display"]="none" ;
		document.getElementById('spdiv').style["visibility"]="hidden" ;
		
		document.getElementById('spdiv2').style["display"]="none" ;
		document.getElementById('spdiv2').style["visibility"]="hidden" ;
	}
}

