function fun_divload(dv)
{
	document.getElementById(dv).innerHTML="<img src='common/images/loader.gif'>";
	document.getElementById(dv).style.visibility="visible";
	document.getElementById(dv).style.position="absolute";	
}

//ajax common function
function GetXmlHttpObject()
{
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
// baby name check
function babyname_check(val,dv)
{
	if (Trim(val)!='')
	{
			fun_divload(dv);
			var xmlHttp=null;
			var url;
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
			  alert ("Your browser does not support AJAX!");
			  return;
			} 
			url="bnamecheck.asp";
			url=url+"?bname="+val;
			xmlHttp.onreadystatechange=stateChangedbname;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
	}
	else
	{hidemsgdiv(dv);}
}
function stateChangedbname() 
{ 
	
	if (xmlHttp.readyState==4)
	{ 
		var userexist;
		userexist=Trim(xmlHttp.responseText);
		if (userexist=='yes')
			{	
				document.getElementById('userdiv').style.color="#ff0000";
				document.getElementById('userdiv').innerHTML='<b>Baby name already exist</b>';
			}
		else if (userexist=='no')
			{	
				document.getElementById('userdiv').innerHTML='';
			}
		document.getElementById("userdiv").style.visibility="visible";
		document.getElementById("userdiv").style.position="absolute";	
	}
}

// user id check
function userid_check(val,dv)
{
	if (Trim(val)!='')
	{
		if (checkmail(val)==false)
		{
			document.getElementById(dv).style.color="#FF0000";	
			document.getElementById(dv).innerHTML="<b>Please enter a valid Email ID</b>";
		}
		else
		{
			fun_divload(dv);
			var xmlHttp=null;
			var url;
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
			  alert ("Your browser does not support AJAX!");
			  return;
			} 
			url="usercheck.asp";
			url=url+"?user="+val;
			xmlHttp.onreadystatechange=stateChangeduser;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
	else
	{hidemsgdiv(dv);}
}
function stateChangeduser() 
{ 
	
	if (xmlHttp.readyState==4)
	{ 
		var userexist;
		userexist=Trim(xmlHttp.responseText);
		if (userexist=='yes')
			{	
				document.getElementById('userdiv').style.color="#ff0000";
				document.getElementById('userdiv').innerHTML='';
				document.getElementById('userdiv').innerHTML='<b>Email ID already exists</b>';
			}
		else if (userexist=='no')
			{	document.getElementById('userdiv').style.color="#008866";
				document.getElementById('userdiv').innerHTML='';
			}
		document.getElementById("userdiv").style.visibility="visible";
		document.getElementById("userdiv").style.position="absolute";	
	}
}


// Exit without save
function fun_exit(url)
{
	window.location.href=url;
}
// automatically exit
function autoexit()
{
	setTimeout ( "fun_exit('bc_login.asp')", 6000 );
}
// Login check
function login_chk2(dv)
{
	document.getElementById(dv).style.color="#FF0000";
	if (Trim(document.getElementById('usertxt').value)=='' && Trim(document.getElementById('passtxt').value)=='')
	{
		document.getElementById(dv).innerHTML="\t<p>Please enter valid Email ID and password</p>";
	}
	else if (Trim(document.getElementById('usertxt').value)!='' && Trim(document.getElementById('passtxt').value)=='')
	{
		document.getElementById(dv).innerHTML="\t<p>Please enter a valid password</p>";
	}
	else if (Trim(document.getElementById('usertxt').value)=='' && Trim(document.getElementById('passtxt').value)!='')
	{
		document.getElementById(dv).innerHTML="\t<p>Please enter a valid Email ID</p>";
		document.getElementById('passtxt').value="";
	}
	else if (Trim(document.getElementById('usertxt').value)!='' && Trim(document.getElementById('passtxt').value)!='')
	{
		if (checkmail(document.getElementById('usertxt').value)==false)
		{
			document.getElementById(dv).innerHTML="\t<p>Please enter a valid Email ID</p>";
		}
		else
		{
			var xmlHttp=null;
			var url,user,pass;
			user=Trim(document.getElementById('usertxt').value);
			pass=Trim(document.getElementById('passtxt').value);
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
			  alert ("Your browser does not support AJAX!");
			  return;
			} 
			url="logincheck.asp";
			url=url+"?user="+user+"&pass="+pass;
			xmlHttp.onreadystatechange=stateChangedlogin2;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
}
function stateChangedlogin2() 
{ 
	
	if (xmlHttp.readyState==4)
	{ 
		var validchk;
		var dv;
		dv="logindiv";
		validchk=Trim(xmlHttp.responseText);
		document.getElementById(dv).style.color="#FF0000";
			if (validchk=='no')
			{	
				document.getElementById(dv).innerHTML="\tUsername and password do not match.";
				document.getElementById('usertxt').value="";
				document.getElementById('passtxt').value="";
				document.getElementById('usertxt').focus();
			}
			else if (validchk!='no')
			{	
				document.getElementById(dv).innerHTML="\tPlease wait...";
				window.location.href="bc_home.asp";
			}
	}
}
// Login check
function login_chk(dv)
{
	document.getElementById(dv).style.color="#ff0000";
	if (Trim(document.getElementById('usertxt').value)=='' && Trim(document.getElementById('passtxt').value)=='')
	{
		document.getElementById(dv).innerHTML="\t<p>Please enter valid Email ID and password</p>";
	}
	else if (Trim(document.getElementById('usertxt').value)!='' && Trim(document.getElementById('passtxt').value)=='')
	{
		document.getElementById(dv).innerHTML="\t<p>Please enter a valid password</p>";
	}
	else if (Trim(document.getElementById('usertxt').value)=='' && Trim(document.getElementById('passtxt').value)!='')
	{
		document.getElementById(dv).innerHTML="\t<p>Please enter a valid Email ID</p>";
		document.getElementById('passtxt').value="";
	}
	else if (Trim(document.getElementById('usertxt').value)!='' && Trim(document.getElementById('passtxt').value)!='')
	{
		if (checkmail(document.getElementById('usertxt').value)==false)
		{
			document.getElementById(dv).innerHTML="\t<p>Please enter a valid Email ID</p>";
		}
		else
		{
			var xmlHttp=null;
			var url,user,pass;
			user=Trim(document.getElementById('usertxt').value);
			pass=Trim(document.getElementById('passtxt').value);
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			{
			  alert ("Your browser does not support AJAX!");
			  return;
			} 
			url="logincheck.asp";
			url=url+"?user="+user+"&pass="+pass;
			xmlHttp.onreadystatechange=stateChangedlogin;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}
}
function stateChangedlogin() 
{ 
	
	if (xmlHttp.readyState==4)
	{ 
		var validchk;
		var dv;
		dv="logindiv";
		validchk=Trim(xmlHttp.responseText);
		document.getElementById(dv).style.color="#ff0000";
			if (validchk=='no')
			{	
				document.getElementById(dv).innerHTML="\tUsername and password do not match.";
				document.getElementById('usertxt').value="";
				document.getElementById('passtxt').value="";
				document.getElementById('usertxt').focus();
			}
			else if (validchk!='no')
			{	
				document.getElementById(dv).innerHTML="\tPlease wait...";
				window.location.href="bc_home.asp";
			}
	}
}

// Forgot password - members info checking
function chk_memberinfo(dv)
{
	var allval,tab;
	allval="<br>";
	if (document.getElementById('usertxt').value=='' || document.getElementById('statetxt').value=='0')
	{allval=allval+"Please fill in the missing fields";}
	else
	{
		if (checkmail(document.getElementById('usertxt').value)==false)
		{allval=allval+"Please enter a valid Email id";}
	}
	allval=allval+"<br><br>";
	tab="<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr bgcolor='#673866'>";
	tab=tab+"<td>&nbsp;</td><td height='25'><div align='left' style='color:#ffffff;'><b>Error</b></div></td></tr>";
	tab=tab+"<tr bgcolor='#D0C5D4'><td>&nbsp;</td><td><div align='left' style='color:#000000;'><b>"+allval+"</b></div></td></tr>"
	tab=tab+"<tr><td colspan='2'>&nbsp;</td></tr>"
	tab=tab+"</table>";
	if (allval!="<br><br><br>")
	{
		document.getElementById(dv).innerHTML=tab;
		document.getElementById(dv).style.display='block';
	}
	else
	{
		var xmlHttp=null;
		var url,user,cnty,dob;
		user=Trim(document.getElementById('usertxt').value);
		state1=Trim(document.getElementById('statetxt').value);
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		url="retrievepass.asp";
		url=url+"?user="+user+"&state1="+state1;
		xmlHttp.onreadystatechange=stateChangedforgotpass;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}
function stateChangedforgotpass() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var adminvalidchk;
		var dv;
		var tab;
		dv="forgotpass";
			adminvalidchk=Trim(xmlHttp.responseText);

			if (adminvalidchk=='no')
			{	
				allval="<br>";
				allval=allval+"Given information does not match.";
				allval=allval+"<br><br>";
				tab="<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr bgcolor='#673866'>";
				tab=tab+"<td>&nbsp;</td><td height='25'><div align='left' style='color:#ffffff;'><b>Error</b></div></td></tr>";
				tab=tab+"<tr bgcolor='#D0C5D4'><td>&nbsp;</td><td><div align='left' style='color:#000000;'><b>"+allval+"</b></div></td></tr>"
				tab=tab+"<tr><td colspan='2'>&nbsp;</td></tr>"
				tab=tab+"</table>";
				document.getElementById(dv).innerHTML=tab;
				document.getElementById(dv).style.display='block';
				document.getElementById('usertxt').value="";
				document.getElementById('statetxt').value="0";
				document.getElementById('usertxt').focus();
			}
			else if (adminvalidchk!='no')
			{	
				//document.getElementById("mid1").innerHTML="<br><h4>The password has been successfully sent to your Email id</h4>";
				autoexit();
			}
	}
}

// information save user details to database
function fun_save(dv)
{
	var allval,tab,er;
	er=0;
	allval="<br>";
	if ((document.getElementById('userdiv').innerHTML!='') || (document.getElementById('zipdiv').innerHTML!=''))
	{allval=allval+"Please correct the highlighted errors in red";}
	else
	{
		if (Trim(document.getElementById('passtxt').value)=='' || Trim(document.getElementById('nametxt').value)==''|| Trim(document.getElementById('address').value)=='' || Trim(document.getElementById('citytxt').value)=='')
		{er=er+1;}
		if (Trim(document.getElementById('mobiletxt').value)=='' || Trim(document.getElementById('ziptxt').value)=='' || Trim(document.getElementById('statetxt').value)=='0')
		{er=er+1;}
		if (er>0)
		{allval=allval+"All fields are mandatory. Please fill in the missing fields.";}
	}
	allval=allval+"<br><br>";
	tab="<table border='0' cellpadding='0' cellspacing='0' width='80%'><tr>";
	tab=tab+"<td height='25'><div align='left' style='color:#990000;'><b>Error: </b></td>";
	tab=tab+"<td height='25'><div align='left' style='color:#000000;'><b>"+allval+"</b></div></div></td></tr>";
	tab=tab+"</table>";
	if (allval!="<br><br><br>")
	{
		document.getElementById(dv).innerHTML=tab;
		document.getElementById(dv).style.display='block';
	}
	else
	{
		document.getElementById("hidsave").value="save";
		document.form1.action="bc_register.asp";
		document.form1.submit();
	}
}
// information update user details to database
function fun_update(dv)
{
	var allval,tab,er;
	er=0;
	allval="<br>";
	if (document.getElementById('zipdiv').innerHTML!='')
	{allval=allval+"Please correct the highlighted errors in red";}
	else
	{
		if (Trim(document.getElementById('passtxt').value)=='' || Trim(document.getElementById('nametxt').value)==''|| Trim(document.getElementById('address').value)=='' || Trim(document.getElementById('citytxt').value)=='')
		{er=er+1;}
		if (Trim(document.getElementById('mobiletxt').value)=='' || Trim(document.getElementById('ziptxt').value)=='' || Trim(document.getElementById('statetxt').value)=='0')
		{er=er+1;}
		if (er>0)
		{allval=allval+"All fields are mandatory. Please fill in the missing fields.";}
	}
	allval=allval+"<br><br>";
	tab="<table border='0' cellpadding='0' cellspacing='0' width='80%'><tr>";
	tab=tab+"<td height='25'><div align='left' style='color:#990000;'><b>Error: </b></td>";
	tab=tab+"<td height='25'><div align='left' style='color:#000000;'><b>"+allval+"</b></div></div></td></tr>";
	tab=tab+"</table>";
	if (allval!="<br><br><br>")
	{
		document.getElementById(dv).innerHTML=tab;
		document.getElementById(dv).style.display='block';
	}
	else
	{
		document.getElementById("hidsave").value="save";
		document.form1.action="bc_modifyuserdetails.asp";
		document.form1.submit();
	}
}

// information save baby details to database
function fun_savephoto(dv)
{
	var allval,tab,er;
	er=0;
	allval="<br>";
	if (window.frames["fileupframe"].document.getElementById("hidfile").value=='0')
	{allval=allval+"Please browse the image and Click on the upload button to save";}
	else
	{
		if (Trim(document.getElementById('bnametxt').value)=='' || Trim(document.getElementById('gender').value)=='select')
		{er=er+1;}
		if (Trim(document.getElementById('dobd').value)=='day' || Trim(document.getElementById('dobm').value)=='month' || Trim(document.getElementById('doby').value)=='year')
		{er=er+1;}
		if (er>0)
		{allval=allval+"All fields are mandatory. Please fill in the missing fields.";}
	}
	allval=allval+"<br><br>";
	tab="<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr bgcolor='#673866'>";
	tab=tab+"<td>&nbsp;</td><td height='25'><div align='left' style='color:#ffffff;'><b>Error</b></div></td></tr>";
	tab=tab+"<tr bgcolor='#D0C5D4'><td>&nbsp;</td><td><div align='left' style='color:#000000;'><b>"+allval+"</b></div></td></tr>"
	tab=tab+"<tr><td colspan='2'>&nbsp;</td></tr>"
	tab=tab+"</table>";
	if (allval!="<br><br><br>")
	{
		document.getElementById(dv).innerHTML=tab;
		document.getElementById(dv).style.display='block';
	}
	else
	{
		
		document.getElementById("hidsave").value="save";
		document.form1.enctype="multipart/form-data";
		document.form1.action="bc_addbabydetails.asp";
		document.form1.submit();
	}
}

// update baby details to database
function fun_updatephoto(dv,file1,file2,id)
{
	var allval,tab,er;
	er=0;
	allval="<br>";
	if (file1=='0' && file2=='0')
	{er=er+1;}
	if (Trim(document.getElementById('bnametxt').value)=='' || Trim(document.getElementById('captiontxt').value)=='' || Trim(document.getElementById('gender').value)=='select')
	{er=er+1;}
	if (Trim(document.getElementById('dobd').value)=='day' || Trim(document.getElementById('dobm').value)=='month' || Trim(document.getElementById('doby').value)=='year')
	{er=er+1;}
	if (er>0)
	{allval=allval+"All fields are mandatory. Please fill in the missing fields.";}
	allval=allval+"<br><br>";
	tab="<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr bgcolor='#673866'>";
	tab=tab+"<td>&nbsp;</td><td height='25'><div align='left' style='color:#ffffff;'><b>Error</b></div></td></tr>";
	tab=tab+"<tr bgcolor='#D0C5D4'><td>&nbsp;</td><td><div align='left' style='color:#000000;'><b>"+allval+"</b></div></td></tr>"
	tab=tab+"<tr><td colspan='2'>&nbsp;</td></tr>"
	tab=tab+"</table>";
	if (allval!="<br><br><br>")
	{
		document.getElementById(dv).innerHTML=tab;
		document.getElementById(dv).style.display='block';
	}
	else
	{
		document.getElementById("hidsave").value="update";
		document.form1.enctype="multipart/form-data";
		document.form1.action="bc_modifybabydetails.asp?id="+id;
		document.form1.submit();
	}
}
// delete baby  details

function fun_deletepic(id,pth)
{
		document.getElementById("hiddel").value="delete";
		document.getElementById("hidpicpath").value=pth;
		document.getElementById("hidpic").value=id;
		document.form1.action="bc_viewbabyphotos.asp";
		document.form1.submit();
}
function fun_delbabydetails(babyid)
{
		document.getElementById("hiddelbaby").value="delete";
		document.getElementById("hidbabyid").value=babyid;
		document.form1.action="bc_viewbabyphotos.asp";
		document.form1.submit();
}

function update_caption(val,id)
{
		var hidcap="hidcap"+id;
		var cap="cap"+id;
		window.parent.document.getElementById(hidcap).value=document.getElementById(cap).value;
}
function update_caption2(val,id,bid)
{
		var hidcap="hidcap"+id;
		var cap="cap"+id;
		window.parent.document.getElementById(hidcap).value=document.getElementById(cap).value;
		window.parent.document.getElementById("hidbid").value=bid;
}
function fun_modifypic(id)
{
		document.form1.action="bc_modifybabydetails.asp?id="+id;
		document.form1.submit();
}

//show large image with slide
function fun_showbabylarge(bid)
{
		window.parent.document.getElementById('light').style.display='block';
		window.parent.document.getElementById('fade').style.display='block';
		var picbit;
		picbit=0;
		if (readcook(bid)==true)
		{picbit=1;}
		window.parent.document.getElementById("babylarge").innerHTML="<iframe frameborder='0' src='showbabylarge.asp?babyid="+bid+"&picbit="+picbit+"' allowtransparency='1' scrolling='no' width='100%' height='100%'></iframe>";
}
function fun_voteforbaby(imgid,vote)
{
		var xmlHttp=null;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		url="voteforbaby.asp";
		url=url+"?babyid="+imgid+"&vote="+vote;
		xmlHttp.onreadystatechange=stateChangedvoteforbaby;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function stateChangedvoteforbaby() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var submitvote;
		submitvote=Trim(xmlHttp.responseText);
		if (submitvote!='')
		{fun_showbabylarge(submitvote);}
	}
}

function fun_viewlarge(hidval)
{
	var hidimgname="hidimgname"+hidval;
	var hidcaption="hidcaption"+hidval;
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
	document.getElementById('imgsrc').innerHTML="<div align='center'><h1>"+document.getElementById(hidcaption).value+"</h1><br><img src='"+document.getElementById(hidimgname).value+"'></div>";
}
function fun_closelargeview()
{
	document.getElementById('light').style.display='none';
	document.getElementById('fade').style.display='none';						
}
function fun_closelargeview2()
{
	window.parent.document.getElementById('light').style.display='none';
	window.parent.document.getElementById('fade').style.display='none';						
}
function fun_addmorephoto(bid)
{
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
	document.getElementById('imgsrc').style.width='400px';
	document.getElementById('imgsrc').style.height='600px';
	document.getElementById('hidbid').value=bid;
	document.getElementById('imgsrc').innerHTML="<iframe frameborder='0' src='uploadfile3.asp?action=0&bid="+bid+"' allowtransparency='1' scrolling='no' width='100%' height='500px'></iframe>";
}
//upload photo in iframe
function fun_submitpic()
{
		document.form1.action="uploadfile.asp";
		document.form1.submit();
}

function createCookie(bid) 
{
	var date = new Date();
	date.setTime(date.getTime()+(1*5*740*740*1000));
	var expires = "; expires="+date.toGMTString();	
	document.cookie = "BC"+bid+"="+bid+"BOM;expires="+expires+";path=/";
}
function readcook(babyid)
{
	var bc_cook,bc_cook2,bc1,bc2;
	var ca = document.cookie.split(';');
	var cnt;
	cnt=0;
	if(ca.length>0)
	{
		for(i=0;i<ca.length;i++) 
		{
			bc_cook=ca[i];
			bc_cook2=bc_cook.split('=');
			bc2=bc_cook2[1];
			if (bc_cook2[0].indexOf("BC")>=0)
			{
					
				var bid=babyid+"BOM";
				if (bid==bc2)
				{cnt=cnt+1;}
			}
		}
	}
	if (cnt>=1)
	{return true;}
	else
	{return false;}
}
function fun_selans(val)
{
	for (i=1;i<=3;i++)	
	{
		var a,q;
		a="a"+i;
		q="q"+i;
		if (parseInt(val)==i)
		{document.getElementById(a).style.display='block';
		document.getElementById(q).className='selected';
		}
		else
		{document.getElementById(a).style.display='none';
		document.getElementById(q).className='';
		}
	}
}
