
function openLoginBox(){
	var html = '<div class="forgotPass" id="login-box-new" ><h1>Login</h1>';	
	html += '<div id="sendPassForm" name="sendPassForm">';
	html += '<form id="loginForm" name="loginForm" action="geo-account.html" method="post">';
    	html += '<font color="grey" font size="2">Enter your email and  password:<br/><br/></font>';
    	html += '<p><label for="user_email" class="popLabel">Email *</label>';
        html += '<input  type="text" name="user_email" id="user_email" class="regular required" /><span class="errormsg" id="msgemail"></span></p><br/>';
        html += '<p><label for="user_pass" class="popLabel" id="logpass">Password *</label>';
        html += '<input  type="password" id="user_pass" name="user_pass" class="regular required" />';
        html += '<span class="errormsg" id="msgreq"></span></p>';
        html += '<p><input type="submit" src="img/send.jpg" title="send" value="" name="send-login" id="send-login" class="login-btn" /></p>'; 
        
        html += '<br/><p><span class="errormsg" id="loginfail"></span></p>';
    	html += '<p class="fp"><a href="pop-passforgot.html" id="passRestoare" rel="opBox" onclick="return forgotPass();">Forgot password?</a></p>';
    	html += '</div></form></div>';
    	
   	$.facebox.settings.opacity = 0.3;   	
	jQuery.facebox(html);	
	$("#send-login").click(function(){
	
		var email = checkEmail("user_email","msgemail");
		var pass = reqfield("user_pass" , "msgreq");

		if (!email || !pass)
			return false;
		else 
			return true;
	});
	return false;
}


function openCallbackBox(){
	var html = '<div class="forgotPass" id="login-box-new" ><h1>Request A Callback</h1>';	
	html += '<div id="sendPassForm" name="sendPassForm">';
	html += '<form id="loginForm" name="loginForm" action="callback.html" method="post">';
    	html += '<font color="grey" font size="2">Please enter your details and one of our representatives will call you back!<br/><br/></font>';
    	
    	html += '<p><label for="name" class="popLabel">Name *</label>';
        html += '<input  type="text" name="name" id="name" class="regular required" /><span class="errormsg" id="msgemail"></span></p><br/>';
        html += '<p><label for="company" class="popLabel" id="logpass"> Company Name *</label>';
        html += '<input  type="text" id="company" name="company" class="regular required" />';
        html += '<span class="errormsg" id="msgreq"></span></p><br/>';
        
        html += '<p><label for="phone" class="popLabel" id="logpass"> Phone *</label>';
        html += '<input  type="text" id="phone" name="phone" class="regular required" />';
        html += '<span class="errormsg" id="msgreq"></span></p>';
        
        html += '<p><input type="image" src="img/btn-send.png" title="send" value="" name="send-login" id="send-login" class="login-btn" /></p>'; 
        
        html += '<br/><p><span class="errormsg" id="loginfail"></span></p>';
    	
    	html += '</div></form></div>';
    	
   	$.facebox.settings.opacity = 0.3;   	
	jQuery.facebox(html);	
	$("#send-login").click(function(){
		var fails = new Array();
		$("#sendPassForm input[type='text']").each(function(){
			
			$(this).focus(function(){
				$(this).parent().find("span").text("");
			});
			if ($(this).attr("value") == ""){
				$(this).parent().find("span").text("Required field! ");
				fails.push(1);
			}	
		});
		
		if (fails.length > 0){
			return false;
		}else{
			return true;
		}
		
	});
	return false;
}

function showCallbackConfirm(){
	var html = '<div class="forgotPass" id="login-box-new" ><h1>Your callback request has been sent!</h1>';	
	html += '<div id="sendPassForm" name="sendPassForm"></div></div>';
	$.facebox.settings.opacity = 0.3;   	
	jQuery.facebox(html);
	return false;
}


function forgotPass(){
	setTimeout ( "showForgrotPass()", 500 );	
	return false;	
}
function reqfield(fieldId , msgId){

	if ($("#" + fieldId).attr("value") == ""){
		var msg = ' Required field';
		$("#" + msgId).text(msg);

		$("#" + fieldId).click(function(){
    			$("#" + msgId).text("");
    		});
		return false;
		
	}else{
		return true;
	}
}
function checkEmail(emailElementId, msgId ){
	var inputvalue = $("#" + emailElementId).attr("value");
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
    		var msg = ' Invalid email';
    		$("#" + msgId).text(msg);
    		

    		$("#" + emailElementId).click(function(){
    			$("#" + msgId).text("");
    		});
		return false;
    }
}

function chkPassword(passId,repassId , msgId){
	var pass = $("#" + passId).attr("value");
	var repass = $("#" + repassId).attr("value");
	var msg = "";
	if (pass != repass)
		msg = "Two Passwords Not Egual!";
	else if (pass.length < 6)
		msg = "Password should be at least 6 chars!";
		
	if (msg != ""){
		$("#" + msgId).text(msg);
		$("#" + passId).click(function(){
    			$("#" + msgId).text("");
    		});
    		$("#" + repassId).click(function(){
    			$("#" + msgId).text("");
    		});
	}else{
		return true;
	}
		
}
function showForgrotPass(){

	//$("#sendPassForm").hide();
	$(".forgotPass").attr("id","");

	var html = '<h1>Password recovery</h1>';
    	html += '<form id="sendPassForm" name="sendPassForm" action="send-pass.html" method="post">';
    	html += '<font color="grey" font size="2">Enter your email account as used to register to the service and GeoSurf will send you a new ';
	html += 'password:<br/><br/></font>';
	 html += '<label for="retrPassEmail" class="popLabel">Enter your email *</label>';
        html += '<p><input type="text" name="retr_email" id="retrPassEmail" class="regular required" /></p>';
      
        html += '<p><span class="errormsg" id="msgemail"></span></p>';
      
        html += '<p class="clear frmDiv"><!-- --></p>';        
 
        html += '<div style="padding:10px 0 20px 0; text-align:right; width:355px;">';
	html += '<input type="image" id="send" src="img/btn-send.png" /></div>';

  	html += '</form>';

    	$(".forgotPass").html(html);
    	$(".forgotPass").show();

	$("#send").click(function(){
		return checkEmail("retrPassEmail","msgemail");
	});
    	


}


