var bUserAvail=1;

function verify_login(){
		var sUrl;
		var F = document.frmLogin;

		if(isEmpty(F.txt_uname.value)){
			alert("Please enter your e-mail address.");
			F.txt_uname.focus();
			return false;
		} 		

		if(isEmpty(F.txt_pass.value)){
			alert("Please enter your password.");
			F.txt_pass.focus();
			return false;
		} 		

 //--------------------- Code to verification username/password [BEG] --------------------
			sUrl = "/bhp_friends/login_availability.php?uname="+F.txt_uname.value+"&upass="+F.txt_pass.value;
			bUserAvail = procRequest(sUrl);
			//alert(bUserAvail);
			if(bUserAvail == 0)
			{
				alert('Sorry, but that log-in information was not correct. Please try again.');
				return false;
			}
 //--------------------- Code to verification username/password [END] --------------------
	return true;
}

function verify_signup(){
	
		var F = document.frmReg;

		if(isEmpty(F.u_fname.value)){
			alert("Please enter your first name.");
			F.u_fname.focus();
			return false;
		} 		
		//**************************** Verification for First Name *****************************//
		
		if(isEmpty(F.u_fname.value)){
			alert("Please enter your First Name.");
			F.u_fname.focus();
			return false;
		} 

		if(F.u_fname.value !="")
	 	{   
	 		var str = F.u_fname.value;
					
					for (var i = 0; i < str.length; i++) 
 						{
							var ch = str.substring(i, i + 1);
							if  ((ch < "a" || ch > "z" ) && (ch < "A" || ch > "Z" )  && (ch != " ") ) 
								{
									alert("Please enter valid first name!");
									F.u_fname.select();
									F.u_fname.focus();
									return false;
									break;
   								}
					}
			
		}

		//**************************** Verification for First Name END *****************************//
	
		if(isEmpty(F.u_email.value)){
			alert("Please enter your e-mail address.");
			F.u_email.focus();
			return false;
		} 		
	
		if(!isEmail(F.u_email)){
			F.u_email.focus();
			return false;
		}
	

		//----------------------------- Password Verification --------------------------------------//

		if(isEmpty(F.u_password.value)){
			alert("Please enter your password.");
			F.u_password.focus();
			return false;
		}

		if(F.u_password.value.length < 4){
			alert("The password must contain atleast 4 characters.");
			F.u_password.focus();
			return false;
		}

		if(isEmpty(F.u_rpassword.value)){
			alert("Please enter re-type password.");
			F.u_rpassword.focus();
			return false;
		}

		if(F.u_rpassword.value != F.u_password.value){
			alert("Invalid password confirmation.");
			F.u_rpassword.focus();
			return false;
		}

		if(F.u_rpassword.value.match(F.u_password.value) == null){
			alert("Invalid password confirmation.");
			F.u_rpassword.focus();
			return false;
		}
		
		//----------------------------- End Pass Verification --------------------------------------//

	/*	if(isEmpty(F.txtUname.value)){
			alert("Please enter User Name.");
			F.txtUname.focus();
			return false;
		}  */

		if(bUserAvail == 1){
			alert("E-mail address not available.");
			F.u_email.focus();
			return false;
		}

		if(bUserAvail == 2){
			alert("A site is already registered with this email.");
			F.u_email.focus();
			return false;
		} 
		
		if(bUserAvail == 3){
			alert("No need to sign up again. You are already a member.");
			F.u_email.focus();
			return false;
		} 
		
		if(isEmpty(F.txtNumber.value)){
			alert("Please enter verification code.");
			F.txtNumber.focus();
			return false;
		}
				
		
		/*if(!F.term_condition.checked){
			alert("Please agree to Terms of Use, Privacy Policy.");
			return false;
		}*/
		
		return true;
	}	
	
	function checkUser(){
		var F = document.frmReg;
		var sUrl;	
		var res = '';
		
		if(!isEmpty(F.u_email.value)){ // start if username not empty.
		
			/*res = alphanumeric(F.txtEmail.value);
			if(res == false)
			{
				bUserAvail = 3;
				document.getElementById("status_text").innerHTML = "<b>Username invalid</b>";
				document.getElementById("status_text").style.color = "#FF2600";
				document.getElementById("user_status").style.display = "block";
				return false;
			
			}*/
			//alert("The value is "+res);
			
			sUrl = "/bhp_friends/user_availability.php?uname="+F.u_email.value;
			bUserAvail = procRequest(sUrl);
			//alert('The value is '+bUserAvail);
			if(bUserAvail == 0){
		
				//document.getElementById("status_text").innerHTML = "<b>Email Available!</b>";
				//document.getElementById("status_text").style.color = "#488F48";
				//document.getElementById("user_status").style.display = "block";
				bUserAvail = 0;
				return true;
			} else if(bUserAvail == 1)
			{
				bUserAvail = 1;
			} else if(bUserAvail == 2)
			{
				bUserAvail = 2;
			} else {
				bUserAvail = 3;
				//document.getElementById("status_user_tr").style.display = "block";
				//document.getElementById("status_text").innerHTML = "<b>Email unavailable</b>";
				//document.getElementById("status_text").style.color = "#FF2600";
				//document.getElementById("user_status").style.display = "block";
				
				
				
				//alert("please choose other user name");
				//F.txtUname.focus();
			}
			
		} // End if not empty user name
		
		//alert(bUserAvail);
		
	}
	
	
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
    myWidth = window.clientWidth;
    myHeight = window.clientHeight;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }

  var iframe = document.getElementById("friends_div");

	   iframe.style.top = myHeight - 37;
		/*if(myWidth < 1)
			myWidth = 1000;
		if(	myHeight < 1)
			myHeight = 540;
		if(document.getElementById("top_value").value == 0)*/
			

	//  if( document.getElementById("top_value").value > 1)
  	  //		iframe.style.top = document.body.scrollTop + (myHeight - 37);
	  //else 
	  		//iframe.style.top = document.body.scrollTop + (myHeight - 37) - document.getElementById("top_value").value;
					
	  //document.getElementById("top_value").value = scrOfY;
	  
	  //setTimeout("getScrollXY()",1000);
}	

//--------------------------------------- Code to Add as Bookmark [START]--------------------------------------
bUserAvails = 0;
function add_bookmark(sname, uid, domain, link_name)
{
		var sUrl;	
		var res = '';
//alert(domain); 
//alert(link_name);
//alert('http://'+domain+link_name);

		sUrl = "/bhp_friends/add_favourites.php?sname="+sname+"&uid="+uid;
		bUserAvails = procRequest(sUrl);
		//alert(bUserAvails);
		if(bUserAvails == 2){
			alert('This site has been added to your favorites list');
			//alert(domain+link_name)
			//location.href = "http://"+domain+link_name; //domain+link_name;
			location.href = domain+link_name; //domain+link_name;
		} else if(bUserAvails == 1){
			alert('The site already exists in your favorites list');
		} else {
			alert('Unable to add as your favorites list');
		}
		
		
}
//--------------------------------------- Code to Add as Bookmark [END]----------------------------------------

//---------------------------------------- To add me as a friend ----------------------------------------------

function request_to_add_me(my_id, sitename,user_status, domain, link_name)
{
//alert(my_id);
//alert(user_status);
//alert(domain+link_name)
//alert('The sitename is '+sitename);
	var sUrl;	
	var us ='';

	if(user_status =='')
	{
		us ='register';
	} else {
		us ='unregister';
	}
	
	if(my_id != '' && sitename != '')
	{
			sUrl = "/bhp_friends/request_to_add_me.php?site="+sitename+"&my_id="+my_id+"&ustatus="+us;
			bFriendAvails = procRequest(sUrl);
			//alert(bFriendAvails);
			if(bFriendAvails == "added"){
				alert('Your friend request has been sent. Check back soon!');
				location.href = domain+link_name;
			} else if(bFriendAvails == "request"){
				alert('You have already sent a friend request to the owner of this site.');
			} else if(bFriendAvails == "exist"){
				alert('This site is already in your friends list.');
			} else if(bFriendAvails == "same"){
				alert("You can't add yourself as a friend.");
			} else if(bFriendAvails == "approved"){
				alert('This site has been added to your friends list.');				
			} else {
				alert('Unable to sent your request.');
				//alert(bFriendAvails);
			}
			
	} else {
			alert('We are unable to send your request.');
			return false;
	}
	
	return true;
}
//---------------------------------------- End to add me as a friend ------------------------------------------

//--------------------------------------- UpDate Friend Request (Approve/Reject) ------------------------------

function update_request(status, record_id, requested_id, my_id, user_status, domain, link_name)
{


	var sUrl;	
	var us ='';
	var bFriendAvails = ''

	if(user_status =='')
	{
		us ='register';
	} else {
		us ='unregister';
	}
	
	if(my_id != '')
	{
		
		sUrl = "/bhp_friends/add_friend.submit.php?choice="+status+"&requested_id="+requested_id+"&my_id="+my_id+"&us="+us+"&record_id="+record_id;
		//alert(sUrl);
			//sUrl = "../bhp_friends/request_to_add_me.php?site="+sitename+"&my_id="+my_id+"&ustatus="+us;
		bFriendAvails = procRequest(sUrl);
			//alert(bFriendAvails); 
			if(bFriendAvails == "approve"){
				alert('Friend has been approved.');
				//location.href = "http://"+domain+link_name;
				location.href = domain+link_name;	
			} else if(bFriendAvails == "ignore"){
				alert('Friend has been rejected/ignored.');
				//location.href = "http://"+domain+link_name;
				location.href = domain+link_name;
			} else if(status == "approved"){
				alert('Unable to approve the friend request.');
			} else if(status == "ignored"){
				alert('Unable to reject the friend request.');
			} else {
				alert("Error. Unable to do this processs");
				//alert(status);
			}
			
	}
	
}

//--------------------------------------- END UPdate Friend Request -------------------------------------------

//---------------------------------------- Remove Selected Friends INI -------------------------------
function remove_selected_friends(domain, link_name)
{

//alert(domain);
//alert(link_name);
var bFriendAvails = ''
var sUrl;
var flag = true;
var str='';
var count = document.getElementById('count_checkboxes').value;
	for(i=0; i<count; i++){
		if(document.getElementById('EditId'+i).checked == true){
			flag = false;
			str += document.getElementById('EditId'+i).value+'B';
			//alert(document.getElementById('EditId'+i).value);
		}
	}

		if(flag){
			alert('Please select a friend from the list to remove');
			return false;
		} else {
			
			sUrl = "/bhp_friends/add_friend.submit.php?choice=removed&str_ids="+str;
			//alert(sUrl);
			bFriendAvails = procRequest(sUrl);
			//alert(bFriendAvails);
				if(bFriendAvails == "yes"){
					alert('Friend has been removed.');
					//location.href = 'http://'+domain+link_name;
					location.href = domain+link_name;
				} else {
					alert('Error. Not able to remove this friend.');
				}
		}


}
//---------------------------------------- Remove Selected Friends END -------------------------------

//------------------------------ Show/Hide Friend Updates INI --------------------------------
function show_hide_update(rec_id, rec_status, domain, link_name)
{
	//alert('record id is '+rec_id);
	//alert(domain);
	//alert('record status '+rec_status);
	var bSite_status = ''
	var sUrl;
	//sUrl = "../bhp_friends/add_friend.submit.php?choice="+rec_status+"&rec_id="+rec_id;
	sUrl = domain+"/bhp_friends/add_friend.submit.php?choice="+rec_status+"&rec_id="+rec_id;
			//alert(sUrl);
			bSite_status = procRequest(sUrl);
			//alert(bSite_status);
				if(bSite_status == "yes"){
					alert('We will '+rec_status+' updates from this friend.');
					//location.href = 'http://'+domain+link_name;
					location.href = domain+link_name;
				} else {
					alert('Unable to '+rec_status+' update(s) of your friend.');
				}
}
//------------------------------ Show/Hide Friend Updates END --------------------------------

//------------------------------ Validate Contact Name , Message -----------------------------
function verify_vcontactus(){
		var F = document.frmContactsVisitor;

		if(isEmpty(F.your_message.value)){
			alert("Please type your Message.");
			F.your_message.focus();
			return false;
		} 		

		if(isEmpty(F.ur_name.value)){
			alert("Please enter your Name.");
			F.ur_name.focus();
			return false;
		} 		

		if(isEmpty(F.u_email.value)){
			alert("Please enter your e-mail address.");
			F.u_email.focus();
			return false;
		} 		

		if(!isEmail(F.u_email)){
			F.u_email.focus();
			return false;
		}

		if(isEmpty(F.txtNumber.value)){
			alert("Please enter the verification code.");
			F.txtNumber.focus();
			return false;
		}
		

	return true;
}

function v_contactus(){
		//alert("testing");
		var F = document.frmContacts;


		if(isEmpty(F.your_message.value)){
			alert("Please type your Message.");
			F.your_message.focus();
			return false;
		} 		


		if(isEmpty(F.txtNumber.value)){
			alert("Please enter the verification code.");
			F.txtNumber.focus();
			return false;
		}
		

	return true; 
}
//------------------------------ End Validate Contact Name, MSG  -----------------------------
function fil_login_box(ob){
	if(ob.value == "E-mail Address or Username")
	{
		ob.value = '';
	} else {
		if(ob.value.length <1)
		{
			ob.value = 'E-mail Address or Username';
		}
	}
}