// JavaScript Document
$(document).ready(function(){
$("#btn_sendmail").click(function(){
	//alert($('input[name="sendmail_name"]').attr("value"));
	
	if($('input[name="sendmail_name"]').attr("value") == ""){
		csscody.error('<h1>Error</h1><em></em><br/><p>Please fill the Name</p>');
		return;
	}
	
	if($('input[name="sendmail_telephone"]').attr("value") == ""){
		csscody.error('<h1>Error</h1><em></em><br/><p>Please fill the Telephone Number</p>');
		return;
	}
	//csscody.images('<img src="images/Popup.jpg" />');
	$.post('mail.php', {
		name:$('input[name="sendmail_name"]').attr("value"),
		telephone:$('input[name="sendmail_telephone"]').attr("value")   
		   }
		   , function(data) {
	if(data == 'sent'){
		//csscody.alert('<h1>Information</h1><br/><p>Message Sent!</p>');
		csscody.images('<img src="images/Popup.jpg" />');
		$('input[name="sendmail_name"]').attr("value","");
		$('input[name="sendmail_telephone"]').attr("value","");
	}else{
		
		csscody.error('<h1>Error</h1><em></em><br/><p>Error while sending email!<br>'+error+'</p>');
	}
});

	
	
	
});

$.post("feed.php",  function(data) {
	$(".blogfeed").html(data);
});

});



$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//START CLEAR FORM
		$('input[name="namefseor"]').attr("value","");
		$('input[name="emailfseor"]').attr("value","");
		$('input[name="urlfseor"]').attr("value","");
		$('#dialog1 .info').html('');
		//END CLEAR FORM//
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		/*e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();*/
		
		
	//alert($('input[name="sendmail_name"]').attr("value"));
	
	var error = '';
	if($('input[name="namefseor"]').attr("value") == ""){
		error = ('<strong>Error:Please fill the Name</strong>');
		$(this).css("border-color", "#FF0000");
		setseomsgboxError(error);
		return;
	}
	
	if($('input[name="emailfseor"]').attr("value") == ""){
		error = ('<strong>Error:Please fill the email</strong>');
		setseomsgboxError(error);
		return; 
	}
	
	if(!validateEmail($('input[name="emailfseor"]').attr("value"))){
		error = ('<strong>Error:Invalid email</strong>');
		setseomsgboxError(error);
		return; 
	}
	
	if($('input[name="urlfseor"]').attr("value") == ""){
		error = ('<strong>Error:Please fill the Url</strong>');
		setseomsgboxError(error);
		return;
	}

	//csscody.images('<img src="images/Popup.jpg" />');
	$.post('mail.php', {
		name:$('input[name="namefseor"]').attr("value"),
		email:$('input[name="emailfseor"]').attr("value"),
		option:"seorequestemail",
		url:$('input[name="urlfseor"]').attr("value")   
		   }
		   , function(data) {
	if(data == 'sent'){
		//csscody.alert('<h1>Information</h1><br/><p>Message Sent!</p>');
		csscody.images('<img src="images/Popup.jpg" />');
		$('input[name="namefseor"]').attr("value","");
		$('input[name="emailfseor"]').attr("value","");
		$('input[name="urlfseor"]').attr("value","");
		$('#dialog1 .info').html('');
		$('#mask').hide();
		$('.window').hide();
		//csscody.alert('<h1>Information</h1><br/><p>Message Sent!</p>');
	}else{
		
		$('input[name="namefseor"]').attr("value","");
		$('input[name="emailfseor"]').attr("value","");
		$('input[name="urlfseor"]').attr("value","");
		$('#dialog1 .info').html('');
		setseomsgboxError('<strong>Error:Email sending fail</strong>');
		//csscody.error('<h1>Error</h1><em></em><br/><p>Error while sending email!<br>'+error+'</p>');
		
		
	}
	});

	
	
	
//end
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

function setseomsgboxError(message){
	$('#dialog1 .info').html(message);
}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
     // alert('Invalid Email Address');
      return false;
   }else
   return true;
}
