/******************************************************
	Date Created: 10-Oct-2008
	Created By: Pravin kucha
	Purpose of this (page/form/module): This page is used for the javascript funtion.
	Last Modified: 
	Modified By: Pravin kucha
******************************************************/
/* Read Only Function*/
function make_readonly()
{
	alert("Please Use Browse Button");
	return false;
}//End of Function

/* Checks for blank text boxes*/
function checkBlank(ctl,msgName)
{
	if(Trim(ctl.value)=="")	
    {
		alert(''+msgName+'' + "cannot be blank");
		ctl.focus();
		return (false);
    }
}//End of Function

/* Checks for unselected select boxes*/
function checkSelect(ctl,msgName)
{
	if(ctl.selectedIndex<=0)	
    {
		alert('Please select '+msgName);
		ctl.focus();
		return (false);
    }
	else
    {
    	return (true);
    }
}//End of Function

/* Checks for the entered email id is in a proper format*/
function ValidateEmail(ctl)
{
	var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) ) 
	{
		error = 1;
		alert("Email address is not formatted properly.");
		ctl.focus();
		return (false);
	}
}
function checkEmail(ctl)
{
	var id=ctl;
	var str=id.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else
	{
		alert("Email address is not formatted properly.");
		ctl.focus();
		testresults=false
	}
	return testresults;
}//End of Function

/* Checks for password entered is same or not*/
function confirmPassword(ctl1,ctl2)
{
	if(ctl1.value != ctl2.value)
	{
   		alert("Password and Confirm Password must be same");
   		ctl1.focus();
   		return(false);
   }
}//End of Function

/* Function to validate the radio button*/
function radio_validate(formObj) 
{
    var isOK = false;
    for (i=0;i<formObj.elements.length;i++) 
	{
		currElem = formObj.elements[i]
        if (currElem.type == "radio"  &&  currElem.checked) 
		{
            isOK=true;
			break;
        }
    }
    
	if (!isOK) 
		alert("You need to select a option !");
    return isOK;
}//End of Function
function checkURL(ctl,msgName) 
{
	var value = ctl.value;
	var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
	if(!urlregex.test(value))
	{
		alert(''+msgName+'' + "is not valid ");
		ctl.focus();
		return (false);
	}
	return(true);
}

/* Function to remove the leading and trailing spaces*/
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}//End of Function

/* Funtion for Numbers Only and Disables all other key*/
function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
		//unicode!=8;
	if (unicode!=9)
	{ //if the key isn't the backspace key (which we should allow)
		if ((unicode<48||unicode>57) && unicode != 46 && unicode != 8) //if not a number
		return false //disable key press
	}
}//End of Function
/* Funtion for Numbers Only and Disables all other key*/
function numbersonlyyear(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
		//unicode!=8;
	if (unicode!=9)
	{ //if the key isn't the backspace key (which we should allow)
		if ((unicode<48||unicode>57) && unicode != 8) //if not a number
		return false //disable key press
	}
	
}//End of Function
/* Function moves the cursor from one text box to another after 3 characters*/
function valuedata(data,movedata)
{ 
	if(data.length == 3)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function
 
/* Function moves the cursor from one text box to another after 2 characters*/
function valuedata1(data,movedata)
{
	if(data.length == 2)
	{
		document.getElementById(movedata).focus();
	}
} //End of Function

/* Funtion for Characters Only and Disables all other key*/
function alphaCharacters(event)
{
	/********
	FOR IE
	*********/
	if(document.all)
	{
		if(event.keyCode>=65 && event.keyCode<=90)
		{
			return true;
		}
		else if(event.keyCode>=97 && event.keyCode<=122)
		{
			return true;
		}
		else if(event.keyCode==32)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/************************************
	OTHER BROWSER LIKE FIREFOX,NETSCAPE
	*************************************/
	if ((!document.all )&& (document.getElementById)) 
	{
		if(event.which>=65 && event.which<=90)
		{
			return true;
		}
		else if(event.which>=97 && event.which<=122)
		{
			return true;
		}
		else if(event.which==32)
		{
			return true;
		}
		else if(event.which==0 || event.which==8)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}//End of Function
/*----Validation For Phone Number---*/
function isDigit(elem)
{
	var digitExp= /^[0-9]+$/;
	if(elem.value.match(digitExp)) { return true;}
	else
	{
		alert("Please Enter Valid Phone Number");
		elem.focus();
		return false;
	}
}
function editValidation(){	
	frm	=document.frmchangepass;	
	if(checkBlank(frm.txtPassword,"Old Password ") == false)
		return false;
	if(checkBlank(frm.txtnewpass," New Password ") == false)
		return false;
	if(checkBlank(frm.txtcpass," Confirm Password ") == false)
		return false;
	if(confirmPassword(frm.txtnewpass,frm.txtcpass) == false)
		return false;		
	if(document.getElementById("messages1").value=="not Allow"){
		alert("please enter Correct Password");		
		return false;
	}
	return true;	
}
function validationContUs()
{
	var frm = document.frmContactus;
	if(checkBlank(frm.txtName," Name ") == false)
		return false;	
	/*if(checkBlank(frm.txtPhone," Phone Number ") == false){}
	else{	if(isDigit(frm.txtPhone) == false)
			return false;	
		}
	if(numbersonly(frm.txtPhone," Phone Number ") == false)
		return false;*/	
	if(checkBlank(frm.txtEmail," Email ") == false)
		return false;	
	if(checkEmail(frm.txtEmail," E-mail Address ") == false)
		return false;		

	if(checkBlank(frm.txtComments," Comment ") == false)
		return false;		
	
	return true;
	
}
function EmailcheckFPwd()
{
	var frm	=document.frmLogin;
	if(checkBlank(frm.txtemailid," E-mail Address ") == false)
	{
		return false;
	}
	if(checkEmail(frm.txtemailid," E-mail Address ") == false)
	{
		return false;
	}
	return true;
}
function ValidationGossMor(e,UserSession)
{
	
	var frm	=document.formComment;
	if(checkBlank(frm.txtComment," Comment ") == false)
	{
		return false;
	}
	document.getElementById("txtcommentl").value=document.getElementById("txtComment").value;
	document.getElementById("hndLookIdl").value=document.getElementById("hndArticalId").value;
	if(UserSession == '')
	{
		popup('popUpDiv',e);
		return false;
	}
	return true;
}
function ValidationLookMor(e,UserSession)
{
	
	var frm	=document.frmlookalike;
	if(checkBlank(frm.txtcomment," Comment ") == false)
	{
		return false;
	}
	document.getElementById("txtcommentl").value=document.getElementById("txtcomment").value;
	document.getElementById("hndLookIdl").value=document.getElementById("hndLookId").value;
	if(UserSession == '')
	{
		popup('popUpDiv',e);
		return false;
	}
	return true;
}
function popupemailValid()
{ 
	var frm = document.frmmail;
	if(checkBlank(frm.txttname," Recepient Name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txttemail," Recepient E-mail Address ") == false)
	{
		return false;
	}
	if(checkEmail(frm.txttemail," E-mail Address ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtsname," Your Name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtsemail," Your E-mail Address ") == false)
	{
		return false;
	}
	if(checkEmail(frm.txtsemail," E-mail Address ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtmessage," Message ") == false)
	{
		return false;
	}
	return true;
}
function newRegValid()
{ 	var frm = document.frmregprofile;
	if(checkEmail(frm.txtEmailID," Email Address ") == false)
		return false;	
	if(checkBlank(frm.txtFName," First Name ") == false)
		return false;	
	if(checkBlank(frm.txtLName," Last Name ") == false)
		return false;	
	if(checkBlank(frm.txtEmailID," Email Address ") == false)
		return false;	
	if(checkBlank(frm.txtPassword," Password ") == false)
		return false;	
	if(frm.txtPassword.value != frm.txtConfirmPass.value)
	{
		alert("Password and Confirm Password do not match");
		frm.txtPassword.focus();
		return false;
   } 
	if(frm.cmbcountry.value =='')
	{
		alert("Select Country");
		frm.cmbcountry.focus();
		return false;
	}
	if(checkBlank(frm.formYear," Date of Birth ") == false)
	return false;	
	
	var d = new Date();
	var curr_year = d.getFullYear();
	var myDayStr = frm.formDate.value;
	var myMonthStr = frm.formMonth.value;
	var myYearStr = frm.formYear.value;

	if(curr_year <= myYearStr )
	{
		alert("Year should be less than "+ curr_year);
		return false;
	}
	var datechk = myMonthStr + '/' + myDayStr + '/' + myYearStr;
	if(isDate(datechk)==false){
		frm.formYear.focus();
		return false;
	}
	if(document.getElementById("messages1").value == 'not Allow')
	{
		return false;
	}
	return true;
	
}//end of newRegValid

function profileUpdateValid()
{
	var frm = document.frmregprofile;
	if(checkEmail(frm.txtEmailID," Email Address ") == false)
		return false;	
	if(checkBlank(frm.txtFName," First Name ") == false)
		return false;	
	if(checkBlank(frm.txtLName," Last Name ") == false)
		return false;	
	if(checkBlank(frm.txtEmailID," Email Address ") == false)
		return false;	
	if(frm.cmbcountry.value =='')
	{
		alert("Select Country");
		frm.cmbcountry.focus();
		return false;
	}
	if(checkBlank(frm.formYear," Date of Birth ") == false)
	return false;	
	
	var d = new Date();
	var curr_year = d.getFullYear();
	var myDayStr = frm.formDate.value;
	var myMonthStr = frm.formMonth.value;
	var myYearStr = frm.formYear.value;
	if(curr_year <= myYearStr )
	{
		alert("Year should be less than "+ curr_year);
		return false;
	}
	var datechk = myMonthStr + '/' + myDayStr + '/' + myYearStr;
	if(isDate(datechk)==false){
		formYear.focus();
		return false;
	}	
	return true;

}//end of profileUpdateValid

//fucntion for albhabet validate
function onlyalfa(e)
 {
 var key;
 var keychar;

 if (window.event)
     key = window.event.keyCode;
 else if (e)
     key = e.which;
 else
     return true;
 keychar = String.fromCharCode(key);
 keychar = keychar.toLowerCase();
 // control keys
 if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
     return true;
	else if(key>=65 && key<=90)
		{
			return true;
		}
		else if(key>=97 && key<=122)
		{
			return true;
		}
		else if(key==32)
		{
			return true;
		}
		else if(key==0 || key==8)
		{
			return true;
		}
 		else
     		return false;
 }//end of albhabet validate

function CelebValid()
{	
	var frm = document.frmcelebdating;
	var sinMonth = document.getElementById("cmbmonth").value;
	var sinYear =  document.getElementById("cmbyear").value;
	var stopMonth = document.getElementById("cmbstMonth").value;
	var stopYear = document.getElementById("cmbstYear").value;
	//stopMonth++; 
	
	if(stopMonth != "" && stopYear != "")
	{ 
		if(stopYear <= sinYear)
		{
			if(stopYear < sinYear)
			{
				alert("Stop date cannot be less then start date");
				frm.cmbstYear.focus();
				return false;
			}else
			{
				if(stopMonth < sinMonth)
				{
					alert("Stop date cannot be less then start date");
					frm.cmbstMonth.focus();
					return false;
				}
			
			}
		}
	}
	
	if(checkBlank(frm.txtcelebname," Celebrity Name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtcelebnamewith," Dating With ") == false)
	{
		return false;
	}
	if(frm.cmbmonth.value == '')
	{
		alert("Dating Since date should not be blank");
		return false;
	}
	if(frm.cmbyear.value == '')
	{
		alert("Dating Since date should not be blank");
		return false;
	}
	if(checkBlank(frm.txtcomment," Comment ") == false)
	{
		return false;
	}
	if(document.getElementById("txtcomment").value.length>200)
	{
		alert("Comment exceeded the max 200 character limit");		
		return false;
	}
	return true;
}
function eventValid()
{
	var frm = document.frmcelebevent;
	if(checkBlank(frm.txtEname," Event Name ") == false)
	{
		return false;
	}
	
	if(checkBlank(frm.txtDate," Event date ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtcomment," comment ") == false)
	{
		return false;
	}
	if(document.getElementById("txtcomment").value.length>200)
	{
		alert("Comment exceeded the max 200 character limit");		
		return false;
	}
	if(document.getElementById("messages1").value=="not Allow"){
		alert("Please enter Correct Event Name");		
		return false;
	}
	
	return true;
}
function AdminValidSugGossip()
{
	celebbox = document.getElementById('cmbceleb2');	
	for(to=0;to<celebbox.options.length;to++) {	
		celebbox.options[to].selected = true;
	}
	
	var frm = document.frmgossip;
	if(checkBlank(frm.txttitle," Title ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtDate," Date ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtauthor," Author ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtcomment," Short Description ") == false)
	{
		return false;
	}
	else
	{ 
		 if(frm.txtcomment.value.length  > 300)
		 {
			 alert("Short Description exceeded the max 300 character limit");
			 return false;
		 }
	 }
	 return true;
}

function likeValid()
{
	var frm = document.frmcelebdating;
	if(checkBlank(frm.txtcelebname," Celebrity Name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtLookalike," Look a Like Person name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.celebrityImg," Celebrity Image ") == false)
		{
			return false;
		}

		if(checkBlank(frm.likeImg," Look a Like Image ") == false)
		{
			return false;
		}
		
	return true;
	
}
function AdminValidSugSpot()
{
	var frm = document.frmcelebspot;
	if(checkBlank(frm.txtcelebname," Celebrity Name ") == false)
		{
			return false;
		}
	
	if(checkBlank(frm.txtSpotDate," Spot date ") == false)
		{
			return false;
		}
	
	if(checkBlank(frm.txtcomment," Comment ") == false)
		{
			return false;
		}
	if(frm.txtcomment.value.length > 200)
		{
		alert("Comment exceeded the max 200 character limit");
			return false;
		}
	
	return true;
}

function CelebValidSug()
{	
	
	var frm = document.frmcelebprofile;
	if(checkBlank(frm.txtFname," First Name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.txtLname," Last Name ") == false)
	{
		return false;
	}
	if(checkBlank(frm.formYear," DOB ") == false)
	{
		return false;
	}
	var d = new Date();
	var curr_day = d.getDate();
	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	//alert(curr_day+" "+curr_month+" "+curr_year +" ");
	var myDayStr = frm.formDate.value;
	var myMonthStr = frm.formMonth.value;
	var myYearStr = frm.formYear.value;
	//alert(curr_day+" "+myDayStr+" "+curr_month +" "+myMonthStr +" "+curr_year+" "+myYearStr);
	if(myYearStr > curr_year)
	{
		alert("Birth Year should be less than "+ curr_year);
		return false;
	}
	else if(myYearStr==curr_year)
	{	//alert("myMonthStr"+myMonthStr+" curr_month"+curr_month);

		if(myMonthStr > curr_month+1)
		{	
			var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 
			alert("Birth Month should be less than "+ arrMonths[curr_month+1]);
			return false;
		}
		else if(myMonthStr==curr_month+1)
			{
				if(myDayStr>curr_day)
				{
					alert("Birth day should be less than "+ curr_day);
					return false;
				}
			}
	}
	
	/*
	if(curr_year < myYearStr )
	{
		alert("Birth Year should be less than "+ curr_year);
		return false;
	}*/
	var dobchk = myMonthStr + '/' + myDayStr + '/' + myYearStr;

	if (isDate(dobchk)==false){
		frm.formYear.focus();
		return false;
	}
	//Validation only if Date of Death is Entered#pritam
	if(frm.formdYear.value!='')
	{
		var mydDayStr = frm.formdDate.value;
		var mydMonthStr = frm.formdMonth.value;
		var mydYearStr = frm.formdYear.value;
		
		if(mydYearStr > curr_year)
		{
			alert("Death Year should be less than "+ curr_year);
			return false;
		}
		else if(mydYearStr==curr_year)
		{
			if(mydMonthStr > curr_month+1)
			{
				var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 
				alert("Death Month should be less than "+ arrMonths[curr_month+1]);
				return false;
			}
			else if(mydMonthStr==curr_month+1)
				{
					if(mydDayStr>curr_day)
					{
						alert("Death day should be less than "+ curr_day);
						return false;
					}
				}
		}
		/*if(curr_year < mydYearStr )
		{
			alert("Death Year should be less than "+ curr_year);
			return false;
		}*/
		var dodchk = mydMonthStr + '/' + mydDayStr + '/' + mydYearStr;
		if (isDate(dodchk)==false){
			frm.formdYear.focus();
			return false;
		}
	}
	return true;
	
}
/*
*Function:	datingValidate()
*Purpose:	Validation for dating
*Author:	pritam m
*/
function datingValidate(mSinceElem,ySinceElem,mStopElem,yStopElem)
{
	var monthSince = document.getElementById(mSinceElem);
	var yrSince= document.getElementById(ySinceElem);
	var monthStop = document.getElementById(mStopElem);
	var yrStop= document.getElementById(yStopElem);
	//alert(monthSince.value+" "+yrSince.value+" "+monthStop.value+" "+yrStop.value);
	//validation for stop date larger than since date
	if(yrSince !=null && yrSince.value !='' && (monthSince ==null || monthSince.value =='') )
	{	alert("Only dating since year selected!"); return false;}
	else if(yrStop !=null && yrStop.value !='' && (monthStop ==null || monthStop.value =='') )
	{	alert("Only dating stop year selected!"); return false;}
	else if(yrSince !=null && yrSince.value !='' && yrStop !=null && yrStop.value !='')
	{
		if(yrSince.value > yrStop.value)
		{
			alert("Dating since date should be less than dating stopped date");
			return false;
		}
		else if(yrSince.value==yrStop.value)
		{	
			if(monthSince.value > monthStop.value)
			{
				var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 
				alert("Dating since date should be less than dating stopped date");
				return false;
			}
		}
	}
	return true;
}
