function ParentValidationEdit()
{
	if($('FirstName').value=='')
	{
		alert("Please Enter First Name");
		$('FirstName').focus();
		return false;
	}
	if($('LastName').value=='')
	{
		alert("Please Enter Last Name");
		$('LastName').focus();
		return false;
	}
	if($('Email').value=='')
	{
		alert("Please Enter Email Address:");
		$('Email').focus();
		return false;
	}

	if((/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z.]{2,5}$/).exec($("Email").value)==null)
	{
					alert("The email you entered is invalid. Please re-enter your email address.");
					$("Email").focus();
					return false;
	}
	if($('Password').value=='')
	{
		alert("Please Enter Password:");
		$('Password').focus();
		return false;
	}
	if($("Password").value.length<6)
	{
		alert("Your password must be at least 6 characters long. ");
		$("Password").focus();
		return false;
	}
	if($('CPassword').value=='')
	{
		alert("Please Enter Confirm Password:");
		$('CPassword').focus();
		return false;
	}
	if($('Password').value != $('CPassword').value)
	{
		alert("Confirm Password Does Not Match:");
		$('Password').focus();
		return false;
	}
	document.Parentform.submit();
	return true;
}
function ParentValidation()
 {

 	if($('FirstName').value=='')
	{
		alert("Please Enter First Name");
		$('FirstName').focus();
		return false;
	}
	if($('LastName').value=='')
	{
		alert("Please Enter Last Name");
		$('LastName').focus();
		return false;
	}

	if($('Email').value=='')
	{
		alert("Please Enter Email Address:");
		$('Email').focus();
		return false;
	}

	if($('CEmail').value=='')
	{
		alert("Please Enter Confirm Email Address:");
		$('CEmail').focus();
		return false;
	}

	if((/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z.]{2,5}$/).exec($("Email").value)==null)
	{
					alert("The email you entered is invalid. Please re-enter your email address.");
					$("Email").focus();
					return false;
	}

	if(ISValidParentEmail()==false)
	{
			alert("The email you entered is already exists");
			$("Email").focus();
			return false;
	}

	if($('Password').value=='')
	{
		alert("Please Enter Password:");
		$('Password').focus();
		return false;
	}
	if($("Password").value.length<6)
	{
		alert("Your password must be at least 6 characters long. ");
		$("Password").focus();
		return false;
	}
	if($('CPassword').value=='')
	{
		alert("Please Enter Confirm Password:");
		$('CPassword').focus();
		return false;
	}
	if($('Password').value != $('CPassword').value)
	{
		alert("Confirm Password Does Not Match:");
		$('Password').focus();
		return false;
	}

	if($('parent_month').selectedIndex==0)
	{
		alert('Please select Month');
		$('parent_month').focus();
		return false;
	}
	if($('parent_day').selectedIndex==0)
	{
		alert('Please select Day');
		$('parent_day').focus();
		return false;
	}
	if($('parent_year').selectedIndex==0)
	{
		alert('Please select Day');
		$('parent_year').focus();
		return false;
	}

	document.Parentform.submit();
	return true;
 }
function ISValidParentEmail()
{
	InfoEmailIsvalid.Stats = false;

	new Ajax.Request('inc/parenthandler.php', {
  method: 'post',
  asynchronous: false,
  parameters: {ParentjoinEmailex:true,Email:$('Email').value},
  onSuccess: ISValidParentEmailSuFc,
  onFailure:  GlobalErrFunc
  });

  if(InfoEmailIsvalid.Stats == false)
  {
	return false;
  }else if(InfoEmailIsvalid.Stats == true)
  {
    return true;
  }
	return false;
}
 function GlobalErrFunc()
 {
	alert('Error');
 }
 function ISValidParentEmailSuFc(response)
 {
	if (200 == response.status)
	{
		if(response.responseText=='exist')
		{
			InfoEmailIsvalid.Stats=true;
		}else
		{
			InfoEmailIsvalid.Stats=false;
		}
	}

 }

// This prtin contain other fucntionalities
function defaltinfo()
{
	currentstep = ({info:'1'});
	Pcont1 = ({Content:'<div class="parentheader">Does your child already have a Scallyroo account?</div><table cellspacing="15" cellpadding="0" width="85%" align="center" style="text-align:left;" class="BlueFontSize"><tr><td><img src="images/parentyes.gif" style="cursor:pointer;" onclick="javascript:ParentYes();"></td><td style="text-align:left;">My child has an account<td/></tr><tr><td><img src="images/parentno.gif" style="cursor:pointer;" onclick="javascript:ParentNo()";></td><td style="text-align:left;">I am creating a new account for my child</td></tr></table><script>SetViewForParent();</script>'});
	Pcont2 = ({Content:'<div class="parentheader">To add your child, please enter the following information </div> <table cellspacing="10" cellpadding="0" width="100%" align="center" style="text-align:left;" class="BlueFontSize"><tr><td NOWRAP>Child\'s Scallyroo Screen Name:</td><td style="text-align:left;"><table cellspacing="0" cellpadding="0" align="left" width="100%"><tr><td class="inputctl_lblue"/><td class="inputct_lblue"/><td class="inputctr_lblue"/></tr><tr><td class="inputcl_lblue"/><td class="inputcspacer_lblue"><input class="cal_inputtext" type="text" name="screenname" id="CScreenName" ></td><td class="inputcr_lblue"/></tr><tr><td class="inputcbl_lblue"/><td class="inputcb_lblue"/><td class="inputcbr_lblue"/></tr></table><td/></tr><tr><td>Child\'s Scallyroo Password:</td><td style="text-align:left;"><table cellspacing="0" cellpadding="0" align="left" width="100%"><tr><td class="inputctl_lblue"/><td class="inputct_lblue"/><td class="inputctr_lblue"/></tr><tr><td class="inputcl_lblue"/><td class="inputcspacer_lblue"><input class="cal_inputtext" type="password" name="password" id="CPassword" ></td><td class="inputcr_lblue"/></tr><tr><td class="inputcbl_lblue"/><td class="inputcb_lblue"/><td class="inputcbr_lblue"/></tr></table></td></tr><tr><td colspan="2"><button  onclick="submitchildinfo();" class="submitbtn" type="button" style="width: 147px;"><img src="images/wishlist/wis_submit.jpg" alt="Submit"/></button></td></tr></table><script>SetViewForParent();</script>'});
	//Pcont3 = ({Content:'<div class="parentheader">Create an Account For Your Child</div> <div>Your child\'s account will automatically be added to your Parent Dashboard once you complete this form.</div><table cellspacing="10" cellpadding="0" width="100%" align="center" class="BlueFontSize"><tr><td style="text-align:right" width="48%"> Screen Name:</td><td style="text-align:left;"><input class="PTboxpopup" type="text" name="screenname" id="CScreenName" onblur="javascript:Availabalescreenname();"><td/></tr><tr style="display:none;" id="ScreenNameAvailable"><td></td><td style="text-align:left;"><div style="color:red;font-size:14px;" id="screenMsg" > Screen Name Not Available <div></td></tr><tr><td style="text-align:right"> Password:</td><td style="text-align:left;"><input class="PTboxpopup" type="password" name="password" id="CPassword"></td></tr><tr><td style="text-align:right"> Confirm Password:</td><td style="text-align:left;"><input class="PTboxpopup" type="password" name="password" id="ConfirmPassword"></td></tr><tr><td style="text-align:right"> Date Of Birth:</td><td style="text-align:left;"><div id="dateofBirthcontrl"></div></td></tr><tr><td style="text-align:right"> Your child\'s First Name</td><td style="text-align:left;"><input class="PTboxpopup" type="text" name="text" id="ChildFirstName"></td></tr><tr><td colspan="2"><button onclick="CreateChidSNew();" class="submitbtn" type="button" style="width: 147px;"><img src="images/wishlist/wis_submit.jpg" alt="Submit"/></button></td></tr></table>'});
	Pcont3 = ({Content:'<div class="parentheader">Create an Account For Your Child</div> <div>Your child\'s account will automatically be added to your Parent Dashboard once you complete this form.</div><table cellspacing="10" cellpadding="0" width="100%" align="center" class="BlueFontSize"><tr><td style="text-align:right" width="48%"> Screen Name:</td><td style="text-align:left;"><table cellspacing="0" cellpadding="0" align="left" ><tr><td class="inputctl_lblue"/><td class="inputct_lblue"/><td class="inputctr_lblue"/></tr><tr><td class="inputcl_lblue"/><td class="inputcspacer_lblue"><input class="cal_inputtext" type="text" name="screenname" id="CScreenName" onblur="javascript:Availabalescreenname();"></td><td class="inputcr_lblue"/></tr><tr><td class="inputcbl_lblue"/><td class="inputcb_lblue"/><td class="inputcbr_lblue"/></tr></table></td></tr><tr style="display:none;" id="ScreenNameAvailable"><td></td><td style="text-align:left;"><div style="color:red;font-size:14px;" id="screenMsg" > Screen Name Not Available <div></td></tr><tr><td style="text-align:right"> Password:</td><td style="text-align:left;"><table cellspacing="0" cellpadding="0" align="left"><tr><td class="inputctl_lblue"/><td class="inputct_lblue"/><td class="inputctr_lblue"/></tr><tr><td class="inputcl_lblue"/><td class="inputcspacer_lblue"><input class="cal_inputtext" type="password" name="password" id="CPassword"></td><td class="inputcr_lblue"/></tr><tr><td class="inputcbl_lblue"/><td class="inputcb_lblue"/><td class="inputcbr_lblue"/></tr></table></td></tr><tr><td style="text-align:right"> Confirm Password:</td><td style="text-align:left;"><table cellspacing="0" cellpadding="0" align="left" ><tr><td class="inputctl_lblue"/><td class="inputct_lblue"/><td class="inputctr_lblue"/></tr><tr><td class="inputcl_lblue"/><td class="inputcspacer_lblue"><input class="cal_inputtext" type="password" name="password" id="ConfirmPassword"></td><td class="inputcr_lblue"/></tr><tr><td class="inputcbl_lblue"/><td class="inputcb_lblue"/><td class="inputcbr_lblue"/></tr></table></td></tr><tr><td style="text-align:right"> Date Of Birth:</td><td style="text-align:left;"><div id="dateofBirthcontrl"></div></td></tr><tr><td style="text-align:right"> Your child\'s First Name</td><td style="text-align:left;"><table cellspacing="0" cellpadding="0" align="left" ><tr><td class="inputctl_lblue"/><td class="inputct_lblue"/><td class="inputctr_lblue"/></tr><tr><td class="inputcl_lblue"/><td class="inputcspacer_lblue"><input class="cal_inputtext" type="text" name="text" id="ChildFirstName"></td><td class="inputcr_lblue"/></tr><tr><td class="inputcbl_lblue"/><td class="inputcb_lblue"/><td class="inputcbr_lblue"/></tr></table></td></tr><tr><td colspan="2"><button onclick="CreateChidSNew();" class="submitbtn" type="button" style="width: 147px;"><img src="images/wishlist/wis_submit.jpg" alt="Submit"/></button></td></tr></table><script>SetViewForParent();</script>'});
}
function Availabalescreenname()
{
	if($('CScreenName').value=='')
	{
		return false;
	}

	if((/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z.]{2,5}$/).exec($('CScreenName').value)!=null)
	{
				alert("you can not use email address as your Screen name");
				$("screenMsg").update('Please enter valid screen name');
				$('ScreenNameAvailable').show();
				$('CScreenName').focus();
				SetViewForParent();
				return false;
	}

	new Ajax.Request('inc/parenthandler.php', {
	  method: 'post',
	  asynchronous: false,
	  parameters: {isScreenAvailable:true,ScreenName:$('CScreenName').value},
	  onSuccess: IsValidScreenSucc,
	  onFailure:  GlobalErrFunc
	  });

}

function IsValidScreenSucc(response)
{

	if (response.status == 200)
	{
		if(response.responseText=='allow')
		{
			$('ScreenNameAvailable').hide();
			SetViewForParent();
		}else
		{
			$("screenMsg").update('screen name not available');
			$('ScreenNameAvailable').show();
			SetViewForParent();
		}
	}
}
function CreateChidSNew()
{
	var Isvalid = true;
	
	if($('CScreenName').value=='')
	{
		Isvalid = false;
		alert('please Enter Screen Name');
		$('CScreenName').focus();
		return false;
	}
	
	Availabalescreenname();
	
	if($('CPassword').value=='')
	{
		Isvalid = false;
		alert('please Enter Password');
		$('CPassword').focus();
		return false;
	}
	
	if($('CPassword').value.length < 6)
	{
		Isvalid = false;
		alert("Your child's password must be at least 6 characters long. ");
		$('CPassword').focus();
		return false;
	}
	
	if($('ConfirmPassword').value=='')
	{
		Isvalid = false;
		alert('please Enter Confirm Password');
		$('ConfirmPassword').focus();
		return false;
	}
	
	if($('ConfirmPassword').value != $('CPassword').value)
	{
		Isvalid = false;
		alert('Confirm Password does not match');
		$('CPassword').focus();
		return false;
	}
	
	if($('child_month').selectedIndex==0)
	{
		Isvalid = false;
		alert('please select month');
		$('child_month').focus();
		return false;
	}
	
	if($('child_day').selectedIndex==0)
	{
		Isvalid = false;
		alert('please select day');
		$('child_day').focus();
		return false;
	}
	
	if($('child_year').selectedIndex==0)
	{
		Isvalid = false;
		alert('please select year');
		$('child_year').focus();
		return false;
	}
	
	if($('ChildFirstName').value == '')
	{
		Isvalid = false;
		alert('please Enter Child\'s First Name');
		$('ChildFirstName').focus();
		return false;
	}
	
	if(Isvalid)
	{
		sendDateChilToRegister();
	}
	
}

function sendDateChilToRegister()
{
	new Ajax.Request('inc/parenthandler.php', {
	  method: 'post',
	  asynchronous: false,
	  parameters: {ParentSendRequestRegister:true,FirstName:$('ChildFirstName').value,ScreenName:$('CScreenName').value,Password:$('CPassword').value,Month:$('child_month').value,Day:$('child_month').value,Year:$('child_month').value},
	  onSuccess: ParentSendChildReq,
	  onFailure:  GlobalErrFunc
	  });

}
function ParentSendChildReq(response)
{

	if(response.status == 200)
	{
		RespnseObj = eval(response.responseText);
		if(RespnseObj.Status == 'exist')
		{
			$('MainContentDisp').update('<div> Screen Name Not Available Please <a href="javascript:void(0);" onclick="javascript:ParentNo();">try again</a></div>');
		}
		else if(RespnseObj.Status == 'create')
		{
			$('MainContentDisp').update('<div class="parentheader">Create an Account For Your Child</div> <br><br><br><div style="font-size: 18px;"><center> Account Successfully created </center><br/><br/> <center><a class="darkbluecolorP"  href="'+RespnseObj.DbUrl+'">Take Me To My Dashboard</a></center></div>');
			$('ChildDescription').update(RespnseObj.Content);
		}else
		{
			$('MainContentDisp').update('<div class="parentheader">Create an Account For Your Child</div> <br><br><br><div style="font-size: 18px;">Error while creating account please <a class="darkbluecolorP" href="javascript:void(0);" onclick="ParentNo();">click here</a> to try again</div>');
		}
		SetViewForParent();
	}

}



function submitchildinfo()
{
	if($('CScreenName').value=='')
	{
		alert('Please Enter Screen Name');
		$('CScreenName').focus();
		return false;
	}
	if($('CPassword').value=='')
	{
		alert('Please Enter Password');
		$('CPassword').focus();
		return false;
	}

	ChildLinkToParent();
}

function ChildLinkToParent()
{
	new Ajax.Request('inc/parenthandler.php', {
  	method: 'post',
  	asynchronous: false,
  	parameters: {ChildAdd:true,Screenname:$('CScreenName').value,Password:$('CPassword').value},
  	onSuccess: isvalidChidID,
  	onFailure:  GlobalErrFunc
  	});

}
function isvalidChidID(response)
{
	if(200 == response.status)
	{
		ResOBJPC = eval(response.responseText);

		if(ResOBJPC.Status=='allow')
		{
			$("MainContentDisp").update('<div style="font-size: 18px;"> <center>Child Has Been Added to Your Account</center> <br> <center><a class="darkbluecolorP" href="'+ResOBJPC.DbUrl+'"> Take Me To My Dashboard</a> </center><br></div>');
			$('ChildDescription').update(ResOBJPC.Content);
		}else
		{
			$("MainContentDisp").update('<div style="font-size: 18px;"><center>The Screen Name Or Password You Entered Does Not Exist.</center><br><br><br>  <center><a class="darkbluecolorP" onclick="javascript:ParentYes();" href="javascript:void(0);">Please Try Again</a></center></div>');
		}
		SetViewForParent();
	}
}
function ParentYes()
{
	if(currentstep.info==1)
	{
		$("MainContentDisp").update(Pcont2.Content);
		SetViewForParent();
	}
}
function ParentNo()
{
	if(currentstep.info==1)
	{
		$("MainContentDisp").update(Pcont3.Content);
		$("dateofBirthcontrl").update(DateControlForChild);
		SetViewForParent();
	}
}

function closewindow()
{
	currentstep.info=1;
	$("DefaultGoalDiv").setStyle({display: 'none' });
	$("bluediv").setStyle({display: 'none' });
}
function AddaChild()
{
	defaltinfo();

	if(currentstep.info==1)
	{
		$("MainContentDisp").update(Pcont1.Content);
	}

	SetPopupBackground();
	$("DefaultGoalDiv").setStyle({display: 'block',opacity : '1.0' });

	SetGoalpopupPos();
//	SetViewForParent();
	Fix_PNGBEHAVIOR();
	return;
}

function AppRejResponse(ID,Opt)
{
	new Ajax.Request('inc/parenthandler.php', {
  	method: 'post',
  	asynchronous: false,
  	parameters: {ChildFriendAccRej:true,FrndID:ID,Opration:Opt},
  	onSuccess: UpdateChildFrnd,
  	onFailure:  GlobalErrFunc
  	});
	return true;
}

function UpdateChildFrnd(response)
{
	if(200 == response.status)
	{
		ResOBJAccRej = eval(response.responseText);

		if(ResOBJAccRej.Status=='update')
		{
			$('FriendRequestdiv').update(ResOBJAccRej.Content);
		}
	}

}

function SetViewForParent()
{
	botheight = $('heightMser').getHeight() + 'px';
	Sideheight = $('heightMser').getHeight() - 150  + 'px';

	$('TopDiv').setStyle({height: Sideheight});
	$("LftDiv").setStyle({height: Sideheight});
	$("RgtDiv").setStyle({height: Sideheight});
	$("BotDiv").setStyle({height: botheight});
	return true;
}