// JavaScript Document


function chkSignupUserName(){
	if(document.getElementById('txtsignuploginusername').value.replace(/^\s*|\s*$/g,'')=='USERNAME/EMAIL'){
		document.getElementById('txtsignuploginusername').value="";
	}
}
function chkSignupPassword()
{
	if(document.getElementById('txtsignuploginpassword').value.replace(/^\s*|\s*$/g,'')=='PASSWORD')
	{
		document.getElementById('txtsignuploginpassword').value="";
	}
}

function showProfile(profId,img)
{
	window.scrollTo(0,0);
	$.ajax({
		type:'GET',
		url:'ajax/chksessiononoff.php',
		data:'',
		success:function(msg){
			if(msg==0)
			{
			
				$('#divloginsignup').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(218);
					leftPos=parseInt( parseInt(leftPos)/2);
					
				var topPos;					
					topPos = parseInt(scrHeight)-parseInt(180);
					topPos=parseInt( parseInt(topPos)/2);
					
				$('#divloginsignup').css('position','absolute');
				$('#divloginsignup').css('left',leftPos+'px');
				$('#divloginsignup').css('top',topPos+'px');
				
				
				document.getElementById('txthiddenprofid').value=profId;
				document.getElementById('txthiddenimg').value=img;
				$('#greybgprelogin').css('display','block');
				var fullScrHeight=$(document).height();
				$('#greybgprelogin').css('height',fullScrHeight+'px');
				
			}else{
				//showProfileDetail(profId,img);
				location.href='mypage.php';
			}
		}
	});
}
function closeLoginSignup(showProf)
{
	var showPro = ( showProf == null ) ? 0 : showProf;
	var profId=document.getElementById('txthiddenprofid').value;
	var img=document.getElementById('txthiddenimg').value;
	document.getElementById('txthiddenprofid').value='';
	document.getElementById('txthiddenimg').value='';
	document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
	document.getElementById('txtsignuploginpassword').value="PASSWORD";
	document.getElementById('divloginsignup').style.display='none';
	$('#greybgprelogin').css('display','none');
	/*if(showPro==1)
	{
		showProfileDetail(profId,img);
	} */
}
function chkLogin2()
{
	var userName=document.getElementById('txtsignuploginusername').value.replace(/^\s*|\s*$/g,'');
	var passWord=document.getElementById('txtsignuploginpassword').value.replace(/^\s*|\s*$/g,'');
	
	if(userName=="" || userName=="USERNAME/EMAIL")
	{
		alert('Please enter valid username or email');
		document.getElementById('txtsignuploginusername').value='';
		document.getElementById('txtsignuploginusername').focus();
	}else if(passWord=="" || passWord=="PASSWORD")
	{
		alert('Please enter valid password');
		document.getElementById('txtsignuploginpassword').value='';
		document.getElementById('txtsignuploginpassword').focus();
	}else{
		$.ajax({
			type:'POST',
			url:'ajax/chkuserlogin.php',
			data:'username='+encodeURIComponent(userName)+'&password='+encodeURIComponent(passWord),
			success:function(msg){
				if(msg.replace(/^\s*|\s*$/g,'')=="invalid")
				{	
					alert('Invalid username or password');
					document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
					document.getElementById('txtsignuploginpassword').value="PASSWORD";	
					document.getElementById('txtsignuploginusername').focus();
						
				}else if(msg.replace(/^\s*|\s*$/g,'')=="1")
				{
					/*	
					alert('Account not yet approved.');
					document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
					document.getElementById('txtsignuploginpassword').value="PASSWORD";	
					document.getElementById('txtsignuploginusername').focus();
					closeLoginSignup();
					*/
					location.href='guyshelp.php';
				}else if(msg.replace(/^\s*|\s*$/g,'')=="2")
				{	
					alert('Please check your email and click the verfication link');
					document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
					document.getElementById('txtsignuploginpassword').value="PASSWORD";	
					document.getElementById('txtsignuploginusername').focus();
					closeLoginSignup();
				}else if(msg.replace(/^\s*|\s*$/g,'')=="3")
				{
					/*	
					alert('Your account cannot be approved at this time. To update your information you can re-register, or you can click "contact" and provide additional information in the comments');
					document.getElementById('txtsignuploginusername').value="USERNAME/EMAIL";
					document.getElementById('txtsignuploginpassword').value="PASSWORD";	
					document.getElementById('txtsignuploginusername').focus();
					closeLoginSignup();
					*/
					location.href='guyshelp.php';
				}else{
					//closeLoginSignup(1);
					location.href='mypage.php';
				}
			}
		});
	}
}

function showProfileDetail(proId,img)
{
	window.scrollTo(0,0);
	var scrWidth=$(window).width();
	var scrHeight=$(window).height();
	
	var fullScrHeight=$(document).height();
	
	var leftPos = (parseInt(scrWidth) - parseInt(856) ) /2;
	var topPos=0;

	$.ajax({
		type:'GET',
		url:'ajax/showfemaleprofile.php',
		data:'profileid='+proId+'&currimg='+img,
		success:function(msg){
			$('#greybg').css('display','block');
			$('#profilecontainer').css('display','block');
			$('#profilecontainer').css('position','absolute');
			$('#profilecontainer').css('left',leftPos+'px');
			$('#profilecontainer').css('top',topPos+'px');
		
			$('#profilecontainer').css('width','856px');
			document.getElementById('profilecontainer').innerHTML=msg;
			
			$('#profilecontainer').css('height',$(document).height()+'px');
		   $('#greybg').css('height',$(document).height()+'px');
		   
			/*Date.format = 'mm/dd/yyyy';

			$(function()
			{
				$('.date-pick').datePicker({clickInput:true})
			});
			$('.date-pick').datePicker()
			$('#checkin').bind(
				'dpClosed',
				function(e, selectedDates)
				{
					var d = selectedDates[0];
					if (d) {
						d = new Date(d);
						$('#checkout').dpSetStartDate(d.addDays(1).asString());
					}
				}
			);
			*/
		}	
	});
}
function closeProfileBox()
{
	document.getElementById('profilecontainer').innerHTML='';
	$('#profilecontainer').css('display','none');
	$('#greybg').css('display','none');
}
function showImgMove(profId,imgNo,cmd){
	$('#profileimages').fadeOut("200");
	$.ajax({
		type:'GET',
		url:'ajax/showprofileimages.php',
		data:'profileid='+profId+'&imgno='+imgNo+'&cmd='+cmd,
		success:function(msg){
			document.getElementById('profileimages').innerHTML=msg;
			$('#profileimages').hide().fadeIn('200');
		}
	});
}

function sendProfileInfo(profId)
{
	var place=document.getElementById('txtplace').value.replace(/^\s*|\s*$/g,'');
//	var dateVal=document.getElementById('checkin').value.replace(/^\s*|\s*$/g,'');
	var timeVal=document.getElementById('txttime').value.replace(/^\s*|\s*$/g,'');
	var Msg=document.getElementById('txtconatctme').value.replace(/^\s*|\s*$/g,'');
	if(place=="")
	{
		alert('Please select valid place');
		document.getElementById('txtplace').focus();
	}/*else if(dateVal=="")
	{
		alert('Please select valid date');
		document.getElementById('checkin').focus();
	}*/else if(timeVal==""){
		alert('Please select valid time');
		document.getElementById('txttime').focus();
	}else if(Msg=="")
	{
		alert('Please enter valid message');
		document.getElementById('txtconatctme').focus();
	}else{
		$.ajax({
			type:'POST',
			url:'ajax/sendprofileinfo.php',
			data:'place='+place+'&profileid='+profId+'&times='+timeVal+'&msg='+Msg,
			success:function(msg){
				alert('Your contact info has been sent');
				closeProfileBox();
			}
		});
	}
}	

/*
function showContactForm(){
	window.scrollTo(0,0);
	var fullScrHeight=$(document).height();
	$.ajax({
		type:'POST',
		url:'ajax/contactus.php',
		data:'',
		success:function(msg){
			$("#contactarea").css('display','block');
			$('#greybgprelogin').css('display','block');
			$('#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');
	}else{
		$('#divbodyarea').css('display','block');
	}
}
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,'');
		}
		$.ajax({
			type:'post',
			url:'ajax/sendcontactinfo.php',
			data:sendStr,
			success:function(msg){
				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()
{
	document.getElementById('txtloginusername').value='USERNAME/EMAIL';
	document.getElementById('txtloginpassword').value='PASSWORD';
	document.getElementById('txtusertype').value="";
	$("#loginbox").css('display','none');
	$("#divforgotpassword").css('display','block');
}
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');
		$.ajax({
			type:'GET',
			url:'ajax/resendpassword.php',
			data:'email='+emailId,
			success:function(msg){
				if(msg=="0"){
					alert('Email id doesnot exist, Please enter valid emailid');
					showFotgotPassword();					
				}else{
					alert(msg);
					document.getElementById('txtforgotemail').value='';
					$("#divforgotpassword").css('display','none');
					$("#greybgprelogin").css('display','none');
				}
			}
		});
	}
}

function showRegiForm(){
	$('#registrationform').css('display','block');
	$.ajax({
		type:'GET',
		data:'',
		url:'ajax/showregistrationform.php',
		success:function(msg){
			$('#registrationform').html(msg);
		}
	});
}
*/
