// JavaScript Document

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function display_contactbynew(val) //function to hide and display contact details for current new bf/gf
{
	if(val==1)
	{
		contactbynewblock.style.display='block';
	}
	else
	{
		contactbynewblock.style.display='none';
	}
	
}

function display_block(val) //function to hide and display contact details for current new bf/gf
{
	if(val==1)
	{
		block.style.display='block';
	}
	else
	{
		block.style.display='none';
	}
	
}


function display_contactbyfuture(val) //function to hide and display contact details for future bf/gf
{
	if(val==1)
	{
		contactbyfutureblock.style.display='block';
	}
	else
	{
		contactbyfutureblock.style.display='none';
	}
	
}

function check_member_register() //Function to check the empty fields in the registration
{
	
	missinginfo = "";
if (document.form1.username.value == "")
 	{
		missinginfo += "\n     -  Username";
	}
if ((document.form1.govt_id.value == "") && (document.form1.pass_id.value == ""))
 	{
		missinginfo += "\n     -  Government Id or Passport Id";
	}
if( document.form1.country.value == "" )
	{
		missinginfo += "\n     -  Select Country";
	}
if (document.form1.firstname.value == "")
 	{
		missinginfo += "\n     -  First Name";
	}
	
if (document.form1.lastname.value == "")
 	{
		missinginfo += "\n     -  Last Name";
	}

if (document.form1.email.value == "")
 	{
		missinginfo += "\n     -  Email";
	}
if (document.form1.reg_no.value == "")
 	{
		missinginfo += "\n     -  Registration Number";
	}
	
	if(document.form1.dob.value != '')
	{
		if(!validateDate(document.form1.dob.value,document.form1.dformat.value,document.form1.range.value))
		{
			alert('Date of birth is invalid'); 
			document.form1.dob.focus();
			return false;
		}	
	}
	

	
	
// Verify e-mail
	
	var email1=document.form1.email.value;
	var email2=document.form1.email_confirm.value;
	
	if (email1=="") {
	
		alert("Please enter your e-mail address.");
		document.form1.email.focus();
		return false;
	}
	
	if (!verifyEmail(email1)){

		alert("Please enter a valid e-mail address.");
		document.form1.email.focus();
		return false;	
	}
	
	if (email1 != email2){

		alert("E-mail addresses do not match");
		document.form1.email_confirm.focus();
		return false;	
	}	



	if (document.form1.reg_no.value != "")
 	{
		if (document.form1.reg_no_rq.value != document.form1.reg_no.value)
		{
			alert("Incorrect Registration Number")
			document.form1.reg_no.focus()
			return false
		}
	}
	


	var val = 0;

	for( i = 0; i < document.form1.contactbynew.length; i++ )
	{
	if( document.form1.contactbynew[i].checked == true )
		val = document.form1.contactbynew[i].value;
	}
	
	if (val == "1")
		{
			if(document.form1.new_yahoo.value=='' && document.form1.new_msn.value=='' && document.form1.new_qq.value=='' && document.form1.new_skype.value=='' && document.form1.new_cellphone.value=='' && document.form1.new_homephone.value=='' && document.form1.new_email.value=='')
			missinginfo += "\n     - Atleast one way your partner's new b/f or g/f can contact you at";
		}
		
	for( i = 0; i < document.form1.contactby_future.length; i++ )
	{
	if( document.form1.contactby_future[i].checked == true )
		val = document.form1.contactby_future[i].value;
	}
	
	if (val == "1")
		{
			if(document.form1.future_yahoo.value=='' && document.form1.future_msn.value=='' && document.form1.future_qq.value=='' && document.form1.future_skype.value==''&& document.form1.future_cellphone.value=='' && document.form1.future_homephone.value=='' && document.form1.future_email.value=='')
			missinginfo += "\n     - At least one way your partner's future b/f or g/f can contact you at";
		}
	
if (missinginfo != "") {
		missinginfo ="You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and save again!";
		alert(missinginfo);
		return false;
	}

	
	return true;
	
}

function validate_chgemail()
{
	if (document.chgemail.email.value == "")
	{
		alert("Enter email address")
		document.chgemail.email.focus()
		return false
	}
	if(!isEMailAddr(document.chgemail.email.value))
	{
		document.chgemail.email.focus()
		return false
	}	
}

function validate_chgpass() //Function to check the empty fields in the registration
{
	
	missinginfo = "";
	
	if (document.chgpass.cpass.value == "")
		{
			missinginfo += "\n     -  Current Password";
		}
	
	if (document.chgpass.npass.value == "")
		{
			missinginfo += "\n     -  New Password";
		}
	
	if (document.chgpass.rpass.value == "")
		{
			missinginfo += "\n     -  Re-type Password";
		}
	
	if (document.chgpass.npass.value != document.chgpass.rpass.value)
		{
			alert("The new password and retyped password are not same!");
			document.chgpass.npass.focus();
			return false;
		}
		
	if (missinginfo != "") {
			missinginfo ="You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease re-enter and save again!";
			alert(missinginfo);
			return false;
		}
		else return true;	
		
}

function verifyEmail(sEmail){
var bOk = true;     
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (sEmail.search(emailRegEx) == -1) {
          bOk=false;
     }
 
     return bOk;
}

function check_add_partner() //Function to check the empty fields in the registration
{
	missinginfo = "";
	
	if ((document.form2.govt_id.value == "") && (document.form2.passport_id.value == ""))
		{
			missinginfo += "\n     -  Government Id or Passport Id";
		}
	
	
	
	
	/*if (document.form2.passport_id.value == "")
		{
			missinginfo += "\n     -  Passport Id";
		}
	*/	
	if (document.form2.firstname.value == "")
		{
			missinginfo += "\n     -  First Name";
		}
		
	if (document.form2.lastname.value == "")
		{
			missinginfo += "\n     -  Last Name";
		}	
	
	if (document.form2.dating_start.value == "")
		{
			missinginfo += "\n     -  Dating Start";
		}
	
	  if( document.form2.partner_dob.value != "" )
		{
		   			if(!validateDate(document.form2.partner_dob.value,document.form2.dformat.value,document.form2.range1.value))
					{
						alert('Date of birth is invalid! Please check the format'); 
						document.form2.partner_dob.focus();
						return false;
					}
					
		} 	
	
	if( document.form2.dating_start.value != "" )
		{
		   			if(!validateDate(document.form2.dating_start.value,document.form2.dformat.value,document.form2.range.value))
				{
					alert('Dating start date is Invalid! Please check the format'); 
					document.form2.dating_start.focus();
					return false;
				}
				
				
		   var str1  = document.form2.dating_start.value;
		   var str2  = document.form2.today_date.value;
		   var date_format=document.form2.date_format.value;
          
		  if(date_format=="d/m/Y")
		  {
		  	var dt1   = parseInt(str1.substring(0,2),10);
		  	var mon1  = parseInt(str1.substring(3,5),10);
   		  	var yr1   = parseInt(str1.substring(6,10),10);
          	var dt2   = parseInt(str2.substring(0,2),10);
		  	var mon2  = parseInt(str2.substring(3,5),10);
		  	var yr2   = parseInt(str2.substring(6,10),10);
		  }
		  else if(date_format=="m/d/Y")
		  {
			var dt1   = parseInt(str1.substring(3,5),10);
		  	var mon1  = parseInt(str1.substring(0,2),10);
   		  	var yr1   = parseInt(str1.substring(6,10),10);
          	var dt2   = parseInt(str2.substring(3,5),10);
		  	var mon2  = parseInt(str2.substring(0,2),10);
		  	var yr2   = parseInt(str2.substring(6,10),10);
		  }
		  else{}
		  
		  var date1 = new Date(yr1, mon1, dt1);
          var date2 = new Date(yr2, mon2, dt2);
		  if(date2 < date1)
		  {
	      		alert("You started dating on");
				document.form2.dating_start.select();
      			return false;
		   }
		 else{}	

		

				
				
		} 
	
	if (missinginfo != "") {
			missinginfo ="You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease re-enter and save again!";
			alert(missinginfo);
			return false;
		}
		
		/* Start --- Validation for DOB and Start date */
		
if(document.form2.partner_dob.value > document.form2.dating_start.value)
 {
		
   var str1  = document.form2.partner_dob.value;

   var str2  = document.form2.dating_start.value;

   var mon1   = parseInt(str1.substring(0,2),10);

   var dt1  = parseInt(str1.substring(3,5),10);

   var yr1   = parseInt(str1.substring(6,10),10);

   var mon2   = parseInt(str2.substring(0,2),10);

   var dt2  = parseInt(str2.substring(3,5),10);

   var yr2   = parseInt(str2.substring(6,10),10);

   var date1 = new Date(yr1, mon1, dt1);

   var date2 = new Date(yr2, mon2, dt2);

   if(date2 < date1)

   {
      alert("The Date of Birth is greater than the Start Date for dating !");
      return false;
   }		
		
}
		
		if(document.form2.partner_dob.value == document.form2.dating_start.value)
	{
		alert("The date of Birth is same as the Start Date for dating !");
		return false;
	}
	
	/* End ---- Validation for DOB and Start date */
		
		else return true;
		
		

}

/*
function validate_breakupdate()
{
	if(document.breakup.breakupdate.value == '')
	{
		alert("Enter Breakup Date");	
		document.breakup.breakupdate.focus();
		return false;
	}
	
	if(!checkDate(document.breakup.breakupdate))
	{
		return false;
	}
}
*/

function checkDate(fld) {    
	var mo, day, yr;
    var entry = fld.value;
    var re = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
    if (re.test(entry)) {
        var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
        var delim1 = entry.indexOf(delimChar);
        var delim2 = entry.lastIndexOf(delimChar);
        mo = parseInt(entry.substring(0, delim1), 10);
        day = parseInt(entry.substring(delim1+1, delim2), 10);
        yr = parseInt(entry.substring(delim2+1), 10);
        var testDate = new Date(yr, mo-1, day);
        //alert(testDate)
        if (testDate.getDate( ) == day) {
            if (testDate.getMonth( ) + 1 == mo) {
                if (testDate.getFullYear( ) == yr) {
                    return true;
                } else {
                    alert("There is a problem with the year entry.");
                }
            } else {
                alert("There is a problem with the month entry.");
            }
        } else {
            alert("There is a problem with the date entry.");
        }
    } else {
        alert("Incorrect date format. Enter as mm/dd/yyyy.");
    }
    return false;
}

function isEMailAddr(str) {
    
    str = str.toLowerCase( );

    if (str.indexOf("@") > 1) {

        var addr = str.substring(0, str.indexOf("@"));
        var domain = str.substring(str.indexOf("@") + 1, str.length);
        // at least one top level domain required
        if (domain.indexOf(".") == -1) {
            alert("Verify the domain portion of the email address.");
            return false;
        }
        // parse address portion first, character by character
        for (var i = 0; i < addr.length; i++) {
            oneChar = addr.charAt(i).charCodeAt(0);
            // dot or hyphen not allowed in first position; dot in last
            if ((i == 0 && (oneChar == 45 || oneChar == 46))  ||
                (i == addr.length - 1 && oneChar == 46)) {
                alert("Verify the user name portion of the email address.");
                return false;
            }
            // acceptable characters (- . _ 0-9 a-z)
            if (oneChar == 45 || oneChar == 46 || oneChar == 95 ||
                (oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123)) {
                continue;
            } else {
                alert("Verify the user name portion of the email address.");
                return false;
            }
        }
        for (i = 0; i < domain.length; i++) {
            oneChar = domain.charAt(i).charCodeAt(0);
            if ((i == 0 && (oneChar == 45 || oneChar == 46)) ||
                ((i == domain.length - 1  || i == domain.length - 2) && oneChar == 46)) {
                alert("Verify the domain portion of the email address.");
                return false;
            }
            if (oneChar == 45 || oneChar == 46 || oneChar == 95 ||
                (oneChar > 47 && oneChar < 58) || (oneChar > 96 && oneChar < 123)) {
                continue;
            } else {
                alert("Verify the domain portion of the email address.");
                return false;
            }
        }
        return true;
    }
    else
    {
      alert("Enter valid Email Address");
      return false;
    }

    return true;
    //alert("The email address may not be formatted correctly. Please verify.");
   // return false;
}

function validate_dating_signup()
{
	if(document.dating.demail.value == '')
	{
		alert("Enter Email Address")
		document.dating.demail.focus()
		return false
	}
	
	if(!isEMailAddr(document.dating.demail.value))
	{
		document.dating.demail.focus()
		return false
	}
	
}
/*
function valDateFmt(datefmt) {
return datefmt.value;
/*myOption = -1;
for (i=0; i<datefmt.length; i++) {if (datefmt[i].checked) {myOption = i;}}
if (myOption == -1) {alert("You must select a date format");return ' ';}
return datefmt[myOption].value;

}

function valDateRng(daterng) {myOption = -1;
for (i=0; i<daterng.length; i++) {if (daterng[i].checked) {myOption = i;}}
if (myOption == -1) {alert("You must select a date range");return ' ';}
return daterng[myOption].value;

return daterng.value;
}
*/
function stripBlanks(fld) {
	
var result = "";for (i=0; i<fld.length; i++) {
	
if (fld.charAt(i) != " " || c > 0) {result += fld.charAt(i);
if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);

}

var numb = '0123456789';

function isValid(parm,val) 
{
if (parm == "") return true;
for (i=0; i<parm.length; i++) {
	if (val.indexOf(parm.charAt(i),0) == -1)
		return false;
}
return true;
}

function isNum(parm) 
{
	return isValid(parm,numb);
}

var mth = new Array(' ','january','february','march','april','may','june','july','august','september','october','november','december');
var day = new Array(31,28,31,30,31,30,31,31,30,31,30,31);



function validateDate(fld,fmt,rng) {
	
var dd, mm, yy;var today = new Date;var t = new Date;fld = stripBlanks(fld);
if (fld == '') return false;var d1 = fld.split('\/');
if (d1.length != 3) d1 = fld.split(' ');
if (d1.length != 3) return false;
if (fmt == 'u' || fmt == 'U') {
  dd = d1[1]; mm = d1[0]; yy = d1[2];}
else if (fmt == 'j' || fmt == 'J') {
  dd = d1[2]; mm = d1[1]; yy = d1[0];}
else if (fmt == 'w' || fmt == 'W'){
  dd = d1[0]; mm = d1[1]; yy = d1[2];}
else return false;
var n = dd.lastIndexOf('st');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('nd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('rd');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf('th');
if (n > -1) dd = dd.substr(0,n);
n = dd.lastIndexOf(',');
if (n > -1) dd = dd.substr(0,n);
n = mm.lastIndexOf(',');
if (n > -1) mm = mm.substr(0,n);
if (!isNum(dd)) return false;
if (!isNum(yy)) return false;
if (!isNum(mm)) {
  var nn = mm.toLowerCase();
  for (var i=1; i < 13; i++) {
    if (nn == mth[i] ||
        nn == mth[i].substr(0,3)) {mm = i; i = 13;}
  }
}
if (!isNum(mm)) return false;

var numAsStringObject = new String(yy);
//alert(numAsStringObject.length);
if(numAsStringObject.length < 4)
	return false;

dd = parseFloat(dd); mm = parseFloat(mm); yy = parseFloat(yy);

if (yy < 100) yy += 2000;
if (yy < 1582 || yy > 4881) return false;
if (mm == 2 && (yy%400 == 0 || (yy%4 == 0 && yy%100 != 0))) day[mm-1]++;
if (mm < 1 || mm > 12) return false;
if (dd < 1 || dd > day[mm-1]) return false;
t.setDate(dd); t.setMonth(mm-1); t.setFullYear(yy);
if (rng == 'p' || rng == 'P') {
if (t > today) return false;
}
else if (rng == 'f' || rng == 'F') {
if (t < today) return false;
}
else if (rng != 'a' && rng != 'A') return false;
return true;
}

function validate_breakupdate(str)
{
	if(document.breakup.breakupdate.value == '')
	{	
		alert("Enter Breakup Date");	
		document.breakup.breakupdate.focus();
		return false;
	}
	
	
	
	// Validating break up date and start date
	
	if(document.breakup.breakupdate.value != '')
	{	
	//alert(str);
	var start = str.split("-");
	var start_date = start[1]+"/"+start[2]+"/"+start[0];
	//alert("test"+start_date);
	

   var str1  = start_date;

   var str2  = document.breakup.breakupdate.value;

   var dt1   = parseInt(str1.substring(0,2),10);

   var mon1  = parseInt(str1.substring(3,5),10);

   var yr1   = parseInt(str1.substring(6,10),10);

   var dt2   = parseInt(str2.substring(0,2),10);

   var mon2  = parseInt(str2.substring(3,5),10);

   var yr2   = parseInt(str2.substring(6,10),10);

   var date1 = new Date(yr1, mon1, dt1);

   var date2 = new Date(yr2, mon2, dt2);

   if(date2 < date1)

   {
      alert("Please check the break up date !");
      return false;

   }

	
}
	
	
	
	/*if(document.breakup.breakupdate.value < )
	{
	}
	*/
	if(!validateDate(document.breakup.breakupdate.value,document.breakup.dformat.value,document.breakup.range.value))
	{
		alert('Date is Invalid'); 
		document.breakup.breakupdate.focus();
		return false;
	}
	return true;
}

function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

function isNumeric(val)
{
	return(parseFloat(val,10)==(val*1));
}

function validate_amount()
{
	if(Trim(document.transfer.amount.value) == '')
	{
		alert("Enter amount")
		document.transfer.amount.focus()
		return false
	}		
	//alert(isNumeric(document.transfer.amount.value));
	
	if(isNumeric(document.transfer.amount.value) == false)
	{
		alert("Invalid amount")
		document.transfer.amount.focus()
		return false
	}
	var bal = parseInt(document.transfer.balance.value)
	if(document.transfer.amount.value > bal)
	{
		alert("Amount to be transferred should be less than current balance.")
		document.transfer.amount.focus()
		return false
	}
}

function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
	
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
	
function Trim(str)
{
	return LTrim(RTrim(str));
}

function validate_deposit()
{
	if(isBlank(document.payment.amount.value))
	{
		alert("Please enter amount");
		document.payment.amount.focus();
		return false;
	}
	if(isNumeric(document.payment.amount.value) == false)
	{
		alert("Invalid amount");
		document.payment.amount.focus();
		return false;
	}
}

function tell_email()
{
	for(var j=1; j<=10; j++)
	{
		if((document.f1.eval("fl"+j).value!="") || (document.f1.eval("ad"+j).value !=""))
		{
			var flag=1;
		}	
		
		
	
		
		if(document.f1.eval("fl"+j).value!="")
		{
			if(document.f1.eval("ad"+j).value!="")
			{
				var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
            	if (filter.test(document.f1.eval("ad"+j).value))
            	{//return true;
				}
	            else
            	{
        			alert("Invalid email address");
					document.f1.eval("ad"+j).focus();
        			return false;
            	}
			}
			else
			{
				alert("Please enter email address");
				document.f1.eval("ad"+j).focus();
				return false;
			}
			
		}
		
		
		if(document.f1.eval("ad"+j).value!="")
		{
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
            if (filter.test(document.f1.eval("ad"+j).value))
            {
				if(document.f1.eval("fl"+j).value=="")
				{
					alert("Please enter name");
					document.f1.eval("fl"+j).focus();
					return false;
				}
			
			}
	        else
            {
        		alert("Invalid email address");
				document.f1.eval("ad"+j).focus();
        		return false;
            }
				
			
			
			
		}
		
		
		
		
	}
	if(flag!=1)
	{
		alert("Cannot send a blank email");
		return false;
	}
	
	

}