// JavaScript Document
function showLoginBox(divId)
{
	if(divId=="divbasiclogin")
	{
		var userType=0;
		document.getElementById('txtusertype').value="0";	
	}else if(divId=="divviplogin"){
		var userType=1;
		document.getElementById('txtusertype').value="1";	
	}else if(divId=="divfemalelogin"){
		var userType=2;
		document.getElementById('txtusertype').value="2";	
	}	
	if(userType==2){
		$('#guyjointype').css('display','none');
		$('#femalejointype').css('display','block');
	}else{
		$('#femalejointype').css('display','none');
		$('#guyjointype').css('display','block');
	}
	
	
//	var scrWidth=$(window).width();
//	var scrHeight=$(window).height();
	if(window.innerWidth){
		var scrWidth=window.innerWidth;
		var scrHeight=window.innerHeight;
	}else{
		var scrWidth=$(window).width();
		var scrHeight=$(window).height();
	}
	//alert('Screen Width = '+scrWidth);
	//alert('Screen Height = '+scrHeight);
	
	var leftPos;
	//	if(scrWidth>218){
			leftPos= parseInt(scrWidth)-parseInt(218);
			leftPos=parseInt(leftPos/2);			
	//	}else{
		//	leftPos=0;
	//	}
	var topPos;
		//if(scrHeight>180){
			topPos = parseInt(scrHeight)-parseInt(180);
			topPos=parseInt(topPos/2);
//		}else{
//			topPos=0;
//		}	
	$('#loginbox').css('position','absolute');
	$('#loginbox').css('left',leftPos+'px');
	$('#loginbox').css('top',topPos+'px');
	$('#loginbox').css('display','block');
	var fullScrHeight=$(document).height();
	$('#greybgprelogin').css('display','block');
	$('#greybgprelogin').css('height',fullScrHeight+'px');
}
function closeLoginBox(){
	if(document.getElementById('txthiddenprofid')){
	document.getElementById('txthiddenprofid').value='';
	}
	if(document.getElementById('txthiddenimg')){
	document.getElementById('txthiddenimg').value='';
	}if(document.getElementById('txtsignuploginusername')){
	document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
	}
	if(document.getElementById('txtsignuploginpassword')){
		document.getElementById('txtsignuploginpassword').value="PASSWORD";
	}
	$('#divloginsignup').css('display','none');
	
	document.getElementById('txtloginusername').value='USERNAME/EMAIL';
	document.getElementById('txtloginpassword').value='PASSWORD';
	document.getElementById('txtusertype').value="";
	$("#loginbox").css('display','none');
	
	$('#greybgprelogin').css('display','none');
}
function chkLogin(){
	if(document.getElementById('txtloginusername').value.replace(/^\s*|\s*$/g,'')=="USERNAME/EMAIL" || document.getElementById('txtloginusername').value.replace(/^\s*|\s*$/g,'')==""){
		alert('Please enter valid username or email');
		document.getElementById('txtloginusername').value="";
		document.getElementById('txtloginusername').focus();
	}else if(document.getElementById('txtloginpassword').value.replace(/^\s*|\s*$/g,'')=="PASSWORD" || document.getElementById('txtloginpassword').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter valid password');
		document.getElementById('txtloginpassword').value="";
		document.getElementById('txtloginpassword').focus();
	}else{
		document.efloginform.submit();
	}
}

function checkDirectLogin()
{
	if(document.getElementById('txtdirectloginusername').value.replace(/^\s*|\s*$/g,'')=="USERNAME/EMAIL" || document.getElementById('txtdirectloginusername').value.replace(/^\s*|\s*$/g,'')==""){
		alert('Please enter valid username or email');
		document.getElementById('txtdirectloginusername').value="";
		document.getElementById('txtdirectloginusername').focus();
	}else if(document.getElementById('txtdirectloginpassword').value.replace(/^\s*|\s*$/g,'')=="PASSWORD" || document.getElementById('txtdirectloginpassword').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter valid password');
		document.getElementById('txtdirectloginpassword').value="";
		document.getElementById('txtdirectloginpassword').focus();
	}else{
		document.directloginform.submit();
		//alert('done');
	}
}

function chkUserName(){ 
	if(document.getElementById('txtloginusername').value.replace(/^\s*|\s*$/g,'')=='USERNAME/EMAIL'){
		document.getElementById('txtloginusername').value="";
	}
}
function chkPassword(){
	if(document.getElementById('txtloginpassword').value.replace(/^\s*|\s*$/g,'')=='PASSWORD')
	{
		document.getElementById('txtloginpassword').value="";
	}
}


function chkDirectUserName(){ 
	if(document.getElementById('txtdirectloginusername').value.replace(/^\s*|\s*$/g,'')=='USERNAME/EMAIL'){
		document.getElementById('txtdirectloginusername').value="";
	}
}
function chkDirectUsernameBlur(){
	if(document.getElementById('txtdirectloginusername').value.replace(/^\s*|\s*$/g,'')=='')
	{
		document.getElementById('txtdirectloginusername').value="USERNAME/EMAIL";
	}
}
function chkDirectPassword(){
	if(document.getElementById('txtdirectloginpassword').value.replace(/^\s*|\s*$/g,'')=='PASSWORD')
	{
		document.getElementById('txtdirectloginpassword').value="";
	}
}



function showContactForm(){
	window.scrollTo(0,0);
	var fullScrHeight=$(document).height();
	$('#greybgprelogin').css('display','block');
	$('#processor').css('display','block');
	$.ajax({
		type:'POST',
		url:'ajax/contactus.php',
		data:'',
		success:function(msg){
			$('#processor').css('display','none');
			$("#contactarea").css('display','block');
			if(window.innerWidth){
				var scrWidth=window.innerWidth;
				var scrHeight=window.innerHeight;
			}else{
				var scrWidth=$(window).width();
				var scrHeight=$(window).height();
			}
			var leftPos;				
				leftPos= parseInt(scrWidth)-parseInt(756);
				leftPos=parseInt( parseInt(leftPos)/2);
				
			var topPos;				
				topPos = parseInt(scrHeight)-parseInt(282);
				topPos=parseInt( parseInt(topPos)/2);
				
			$('#contactarea').css('position','absolute');
			$('#contactarea').css('left',leftPos+'px');
			$('#contactarea').css('top',topPos+'px');
			
			
			$('#greybgprelogin').css('height',fullScrHeight+'px');
			$('#contactarea').html(msg);
		}	
	});
}
function closeContactForm(){
	document.getElementById('contactarea').innerHTML='';
	$("#contactarea").css('display','none');
	$('#greybgprelogin').css('display','none');
}
function changeCategory(){
	if(document.getElementById('txtcat').value.replace(/^\s*|\s*$/g,'')=="Upgrade Membership")
	{
		$('#divbodyarea').css('display','none');
		$('#dropdowns').css('display','block');
	}else{
		$('#divbodyarea').css('display','block');		
		$('#dropdowns').css('display','none');
	}
}
function sendMsg(){
	var filter=/^.+@.+\..{2,3}$/;
	var emailId=document.getElementById('txtemail').value.replace(/^\s*|\s*$/g,'');
	var cat=document.getElementById('txtcat').value.replace(/^\s*|\s*$/g,'');

	var execute=1;
	if(emailId=="" || filter.test(document.getElementById('txtemail').value.replace(/^\s*|\s*$/g,''))==false)	
	{
		alert('Please enter valid email');		
		document.getElementById('txtemail').value="";
		document.getElementById('txtemail').focus();
		execute=0;
	}else if(document.getElementById('txtcat').value.replace(/^\s*|\s*$/g,'')!="Upgrade Membership")
	{
		if(document.getElementById('txtbody').value.replace(/^\s*|\s*$/g,'')=="")
		{
			alert('Please enter valid message');
			document.getElementById('txtbody').value='';
			document.getElementById('txtbody').focus();
			execute=0;
		}
	}
	
	if(execute==1)
	{	
		var sendStr='';
		sendStr='email='+emailId+'&cat='+document.getElementById('txtcat').value.replace(/^\s*|\s*$/g,'');
		if(document.getElementById('txtbody')){
			sendStr+='&msg='+document.getElementById('txtbody').value.replace(/^\s*|\s*$/g,'');
		}
		if(document.getElementById('txtcat').value.replace(/^\s*|\s*$/g,'')=="Upgrade Membership")
		{
			sendStr+'&female1='+txtfemale1+'&female2='+txtfemale2+'&female3='+txtfemale3;
		}
		
		$('#processor').css('display','block');
		$.ajax({
			type:'post',
			url:'ajax/sendcontactinfo.php',
			data:sendStr,
			success:function(msg){
				$('#processor').css('display','none');
				alert('Your contact info has been sent, We will contact you shortly');
				closeContactForm();
			}
		});
	}
}

function closeForgotPassword(){
	document.getElementById('txtforgotemail').value='';
	$("#divforgotpassword").css('display','none');
	$("#greybgprelogin").css('display','none');
}
function showFotgotPassword()
{
	$('#registrationform').html('');
	$('#registrationform').css('display','none');
	$('#greybgprelogin').css('display','block');
	
	if(document.getElementById('txthiddenprofid')){
	document.getElementById('txthiddenprofid').value='';
	}
	if(document.getElementById('txthiddenimg')){
	document.getElementById('txthiddenimg').value='';
	}if(document.getElementById('txtsignuploginusername')){
	document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
	}
	if(document.getElementById('txtsignuploginpassword')){
		document.getElementById('txtsignuploginpassword').value="PASSWORD";
	}
	$('#divloginsignup').css('display','none');
	
	document.getElementById('txtloginusername').value='USERNAME/EMAIL';
	document.getElementById('txtloginpassword').value='PASSWORD';
	document.getElementById('txtusertype').value="";
	$("#loginbox").css('display','none');
	
	
	$("#divforgotpassword").css('display','block');
	
	if(window.innerWidth){
		var scrWidth=window.innerWidth;
		var scrHeight=window.innerHeight;
	}else{
		var scrWidth=$(window).width();
		var scrHeight=$(window).height();
	}
	var leftPos;		
			leftPos= parseInt(scrWidth)-parseInt(462);
			leftPos=parseInt( parseInt(leftPos)/2);
		
	var topPos;		
			topPos = parseInt(scrHeight)-parseInt(156);
			topPos=parseInt( parseInt(topPos)/2);
		
	$('#divforgotpassword').css('position','absolute');
	$('#divforgotpassword').css('left',leftPos+'px');
	$('#divforgotpassword').css('top',topPos+'px');
	
}
function sendNewPassword()
{
	var filter=/^.+@.+\..{2,3}$/;

	var emailId=document.getElementById('txtforgotemail').value.replace(/^\s*|\s*$/g,'');
	if(emailId=="" || filter.test(emailId)==false)
	{
	 	alert('Please enter valid email id');
		document.getElementById('txtforgotemail').value='';
		document.getElementById('txtforgotemail').focus();
	}else{
		document.getElementById('txtforgotemail').value='';
		$("#divforgotpassword").css('display','none');
		$('#processor').css('display','block');
		$.ajax({
			type:'GET',
			url:'ajax/resendpassword.php',
			data:'email='+emailId,
			success:function(msg){
				if(msg=="0"){
					$('#processor').css('display','none');
					alert('Email id doesnot exist, Please enter valid emailid');
					showFotgotPassword();					
				}else{
					$('#processor').css('display','none');
					alert(msg);
					document.getElementById('txtforgotemail').value='';
					$("#divforgotpassword").css('display','none');
					$("#greybgprelogin").css('display','none');
				}
			}
		});
	}
}

function showRegiForm()
{
	var fullScrHeight=$(document).height();
	$('#greybgprelogin').css('display','block');
	$('#greybgprelogin').css('height',fullScrHeight+'px');
	if(document.getElementById('txthiddenprofid')){
	document.getElementById('txthiddenprofid').value='';
	}
	if(document.getElementById('txthiddenimg')){
	document.getElementById('txthiddenimg').value='';
	}if(document.getElementById('txtsignuploginusername')){
	document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
	}
	if(document.getElementById('txtsignuploginpassword')){
		document.getElementById('txtsignuploginpassword').value="PASSWORD";
	}
	$('#divloginsignup').css('display','none');
	
	document.getElementById('txtloginusername').value='USERNAME/EMAIL';
	document.getElementById('txtloginpassword').value='PASSWORD';
	document.getElementById('txtusertype').value="";
	$("#loginbox").css('display','none');	
	$('#processor').css('display','block');
	$.ajax({
		type:'GET',
		data:'',
		url:'ajax/showregistrationform.php',
		success:function(msg){
			$('#processor').css('display','none');
			
			$('#registrationform').css('display','block');
			
			var scrWidth=$(window).width();
			var scrHeight=$(window).height();
			var leftPos;
				if(scrWidth>462){
					leftPos= parseInt(scrWidth)-parseInt(462);
					leftPos=parseInt( parseInt(leftPos)/2);
				}else{
					leftPos=0;
				}
			var topPos;
				if(scrHeight>542){
					topPos = parseInt(scrHeight)-parseInt(542);
					topPos=parseInt( parseInt(topPos)/2);
				}else{
					topPos=0;
				}	
			$('#registrationform').css('position','absolute');
			$('#registrationform').css('left',leftPos+'px');
			$('#registrationform').css('top',topPos+'px');
				
			$('#registrationform').html(msg);
		}
	});
}

function checkContactNo(){
	if(document.getElementById('txtcontactno').value.replace(/^\s*|\s*$/g,'')!="")
	{
		var num=document.getElementById('txtcontactno').value.replace(/^\s*|\s*$/g,'');
		var arr=num.split('');
		var newString='';
		for(var i=0;i<arr.length;i++)
		{
			if(arr[i]>=0 && arr[i]<=9)
			{
				newString+=arr[i];
			}
		}	
		document.getElementById('txtcontactno').value=newString.replace(/\W/,'');
	}
	
}
function closeRegiForm(){
	$('#registrationform').html('');
	$('#registrationform').css('display','none');
	$('#greybgprelogin').css('display','none');
}
function doCheckGuysJoin()
{
	var filter=/^.+@.+\..{2,3}$/;
	var illegalChars = /\W/;
	var execute=1;
	if(document.getElementById('txtfirstlastname').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter valid first and lastname');
		document.getElementById('txtfirstlastname').value='';
		document.getElementById('txtfirstlastname').focus();
		execute=0;
	}else if(document.getElementById('txtcontactno').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter your Contact Phone.');
		document.getElementById('txtcontactno').value='';
		document.getElementById('txtcontactno').focus();
		execute=0;
	}else if(document.getElementById('txtemail').value.replace(/^\s*|\s*$/g,'')=="" || filter.test(document.getElementById('txtemail').value.replace(/^\s*|\s*$/g,''))==false)
	{
		alert('Please enter valid Email Address.');
		document.getElementById('txtemail').value='';
		document.getElementById('txtemail').focus();
		execute=0;
	}else if(document.getElementById('txtemail').value.replace(/^\s*|\s*$/g,'')!=document.getElementById('txtconfirmemail').value.replace(/^\s*|\s*$/g,''))
	{	
		alert('Email does not macth');
		document.getElementById('txtemail').value='';
		document.getElementById('txtconfirmemail').value='';
		document.getElementById('txtemail').focus();
		execute=0;
	}else if(document.getElementById('txtp411').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter your P411 ID. If you do not have one, enter N/A.');
		document.getElementById('txtp411').value='';
		document.getElementById('txtp411').focus();
		execute=0;
	}else if(document.getElementById('txtdatecheck').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter your Date Check ID. If you do not have one, enter N/A.');
		document.getElementById('txtdatecheck').value='';
		document.getElementById('txtdatecheck').focus();
		execute=0;
	}else if(document.getElementById('txtrs2k').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter your RS2K ID. If you do not have one, enter N/A.');
		document.getElementById('txtrs2k').value='';
		document.getElementById('txtrs2k').focus();
		execute=0;
	}else if(document.getElementById('txthomephone').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter your Home Phone. This should be different than your Contact Phone. If you do not have one, enter N/A.');
		document.getElementById('txthomephone').value='';
		document.getElementById('txthomephone').focus();
		execute=0;
	}else if(document.getElementById('txthomezipcode').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter valid home zipcode');
		document.getElementById('txthomezipcode').value='';
		document.getElementById('txthomezipcode').focus();
		execute=0;
	}else if(document.getElementById('txtemployment').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter your Place of Work, Job Title, Landline/Work Phone, and Website (if applicable).');
		document.getElementById('txtemployment').value='';
		document.getElementById('txtemployment').focus();
		execute=0;
	}else if(document.getElementById('txtreference1').value.replace(/^\s*|\s*$/g,'')=="" && document.getElementById('txtreference2').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter Name and Contact Info for Reference #1.');
		document.getElementById('txtreference1').value='';
		document.getElementById('txtreference1').focus();
		execute=0;
	}else if(document.getElementById('txtnewpassword').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter valid password');
		document.getElementById('txtnewpassword').value='';
		document.getElementById('txtnewpassword').focus();
		execute=0;
	}else if(document.getElementById('txtnewpassword').value.replace(/^\s*|\s*$/g,'')!=document.getElementById('txtretypepassword').value.replace(/^\s*|\s*$/g,''))
	{
		alert('Password does not match');
		document.getElementById('txtnewpassword').value='';
		document.getElementById('txtretypepassword').value='';
		document.getElementById('txtnewpassword').focus();
		execute=0;
	}else if(document.getElementById('txtusername').value.replace(/^\s*|\s*$/g,'')=="")
	{
		alert('Please enter valid username');
		document.getElementById('txtusername').value='';
		document.getElementById('txtusername').focus();
		execute=0;
	}else if(illegalChars.test(document.getElementById('txtusername').value.replace(/^\s*|\s*$/g,'')))
	{
		alert('Username shouldnot contain white space');
		document.getElementById('txtusername').value='';
		document.getElementById('txtusername').focus();
		execute=0;
	}else if((document.getElementById('radioyesvisit').checked==true) && (document.getElementById('txtguysstate').value.replace(/^\s*|\s*$/g,'')=="" || document.getElementById('txtguyscity').value.replace(/^\s*|\s*$/g,'')==""))
	{
		alert('Please choose valid visited city and state');
		document.getElementById('txtguysstate').focus();
		execute=0;
	}else if(document.getElementById('radioagree').checked==false)
	{
		alert('Please agree terms of use');
		document.getElementById('radioagree').focus();
		execute=0;
	}
	if(execute==1){
		var passWord=document.getElementById('txtnewpassword').value.replace(/^\s*|\s*$/g,'');
		$('#processor').css('display','block');
		if(passWord.length>=7 && passWord.length<=25)
		{
			$.ajax({
				type:'GET',
				url:'ajax/checkuserexist.php',
				data:'username='+encodeURIComponent(document.getElementById('txtusername').value).replace(/^\s*|\s*$/g,'')+'&email='+encodeURIComponent(document.getElementById('txtemail').value).replace(/^\s*|\s*$/g,''),
				success:function(msg){
					if(msg=='0')
					{				
						document.guysjoin.submit();
					}else if(msg=='2')
					{
						$('#processor').css('display','none');
						alert('E-mail address already exists. Please click \'forgot password\' below.');
						document.getElementById('txtemail').value='';
						document.getElementById('txtemail').focus();
					}else{
						$('#processor').css('display','none');
						alert('Username taken, please choose a different username.');
						document.getElementById('txtusername').value='';
						document.getElementById('txtusername').focus();
					}
				}	
			});
		}else{
			$('#processor').css('display','none');
			alert('Password should be 7-25 characters long');
			document.getElementById('txtnewpassword').focus();
		}
	} 
}

function showCityState(cmd)
{
	if(document.getElementById('radioyesvisit').checked==true)
	{		
		$('#dividchoosestate').css('display','block');
		$('#dividchoosecity').css('display','block');
		$('#greybgprelogin').css('height',$(document).height()+'px');
	}else if(document.getElementById('radionovisit').checked==true){	
		$('#dividchoosestate').css('display','none');
		$('#dividchoosecity').css('display','none');
		$('#greybgprelogin').css('height',$(document).height()+'px');
	}
}

function setLoadGuysCity(divId,changeDIV,setCITY){
	var state=document.getElementById(changeDIV).value;
	$.ajax({
		url:'ajax/loadcitystate.php',
		type:'GET',
		data:'statename='+state+'&divcity='+setCITY,
		success:function(msg){
			document.getElementById(divId).innerHTML=msg;
		}
	});
}
function checkEnteLogin(e)
{
	var keyCODE= e.keyCode;
	if(keyCODE==13)
	{	
		checkDirectLogin();
	}
}
