﻿
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup1(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup1").css({
			"opacity": "0.8"
		});
		$("#backgroundPopup1").fadeIn("slow");
		$("#popupContact1").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup1(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup1").fadeOut("slow");
		$("#popupContact1").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup1(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact1").height();
	var popupWidth = $("#popupContact1").width();
	var fullHeight	=$(document).height();
	//centering
	$("#popupContact1").css({
		"position": "",
		"bottom": 2,
		"left": windowWidth/2-popupWidth/2				   
						   
		/*"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2*/
	});
	//only need force for IE6
	
	$("#backgroundPopup1").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose1").click(function(){
		disablePopup1(); // must call this to have SimpleModal 
	//	document.location.href	=	base_url_4_js+"/Index";
	});
	//Click out event!
	$("#backgroundPopup1").click(function(){
		disablePopup1();
	});
	
	$("#cancel1").click(function(){
		disablePopup1();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup1();
		}
	});

});

function submit_enquiry1()
{
	
	var str	= "";//for taking the error msg
	var ctr	= "";//for taking the controllername for focus
	
	var email	=	$("#email2").val();
	if($("#name1").val()==""){
		str	= 'Please give your name';
		ctr = "name1";
	}
	
	else if($("#email2").val()==""){
		str	= 'Please give your email id';
		ctr = "email2";
	}
	else if($("#email2").val()!='' && !checkemail(email) ){	
	
		str	= 'Enter a valid email id';
		ctr = "email2";
	}
	else if($("#phone1").val()==""){
		str	= 'Please give your phone number';
		ctr = "phone1";
	}
	else if($("#country1").val()==""){
		str	= 'Please give your country';
		ctr = "country1";
	}
	else if($("#subject1").val()==""){
		str	= 'Please give your subject';
		ctr = "subject1";
	}
	
	else if($("#comments1").val()==""){
		str	= 'Please give your comments';
		ctr = "comments1";
	}
	
	else {
		
			//$('#load_msg').html('<img src="image/al_loading.gif" />');
			var datas	= "name="+$("#name1").val()+"&email="+$("#email2").val()+"&phone="+$("#phone1").val()+"&country="+$("#country1").val()+"&subject="+$("#subject1").val()+"&comments="+$("#comments1").val();
	
			$.ajax({
				   type: "POST",
					url: base_site_url+'/Rates/enquiry',
					data:  datas,
					success: function(data){
					//alert(data);
					if(data=='success'){
						$('#load_msg1').html('<script type="text/javascript" language="javascript">comments1("Thank you for your enquiry, we will reply as soon as we can");</script>');
						clear_form1();
					}else{				
						$('#load_msg1').html('<script type="text/javascript" language="javascript">comments1("Sorry..Some error has been occured. Try again!!");</script>');
						//disablePopup();
						clear_form1()
					}
				}
			}); 
	
	}
	
	if(str!="")
	$('#err_msg1').html(str+' | &nbsp;<a  href="javascript:void(0);" onClick="javascript:div_hide1(\''+ctr+'\');" >Hide</a>');	
}
//function for hide message box
function div_hide1(ctr){
	
	$('#err_msg1').html("");
	$('#load_msg1').html("");
	document.getElementById(ctr).focus();
}

function clear_form1()
{
	$("#name1").val('');	
	$("#email2").val('');
	$("#phone1").val('');	
	$("#country1").val('');
	$("#subject1").val('');
	$("#comments1").val('');
	$('#err_msg1').html("");
	
}

function checkemail(em)   //Email validation 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(em))
	return true
	else
	return false
}	

