﻿$(document).ready(function(){
	var Revealer = function(relativeParent,absoluteChild,speed) {
		var revealHeight = absoluteChild.height();
		relativeParent.height(revealHeight);
		relativeParent.addClass('hidden');
		this.toggleReveal = function() {
			if (!relativeParent.parent().find(':animated').length) {
				if (relativeParent.css('display')!='none' ) {
	        		relativeParent.animate({height:0}, speed, function() {
						relativeParent.hide();
					});
				} else {
	        		relativeParent.height(0).show().animate({height: revealHeight}, speed);
				}
			}
		};
	};
	function trim(str) {
        return str.replace(/^\s+|\s+$/g,"");
    }
	$('label em').hide();
	$('#info').after($('#info-form'));
	
	var contactForm = new Revealer(
		$('#info-form .flow'),				// the relatively positioned container
		$('#info-form .flow .headform'),		// the absolutely positioned child
		1000										// the speed of the animation 300
	);
	
	$('.info-link').live('click',function(){
	    $('html, body').animate({scrollTop:0}, 'fast');
        contactForm.toggleReveal();
		return false;
	});
	$('#info-form input[type="reset"]').live('click',function(){
        contactForm.toggleReveal();
        $('#info-form .headform .fcontainer input').val('');
        $('#info-form .headform textarea').val('');
        $('#info-form .headform em').hide();
		return false;
    });
 
	
   
	//submission scripts
  $('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('e-mail');
		var cform = document.getElementById('c-form');
		if (!filter.test(email.value)) {
			$('.email-missing').show();
		} else {$('.email-missing').hide();}
		if (trim(cform.name.value) == "") {
			$('.name-missing').show();
		} else {$('.name-missing').hide();}	
		if (trim(cform.message.value) == "") {
			$('.message-missing').show();
		} else {$('.message-missing').hide();}		
		if ((cform.name.value == "") || (!filter.test(email.value)) || (cform.message.value == "")){
			return false;
		} 
		
		if ((cform.name.value != "") && (filter.test(email.value)) && (cform.message.value != "")) {
			//hide the form
			$('.contactForm').hide();
		
			
			//send the ajax request
			$.post('http://www.projects4web.com/include/index.php',{name:$('#name').val(),
							  email:$('#e-mail').val(),
							  message:$('#message').val()},
		
			//return the data
			function(data){
			$('#contactForm').removeClass('error');
			$('#contactForm').removeClass('success');
			  //hide the graphic
			  	if(data.email_check == 'valid'){
			  		$('#info_response').addClass('success').html("<h2>Thank you &laquo;"+data.name+"&raquo; !</h2><ul><li>Contact Form Submitted!</li></ul><h4>We will be in touch soon.</h4><p>Message sent on: <span>"+data.date+"</span></p>").fadeIn(6500);
			  	} else {
			  		$('#info_response').addClass('error').html("<h2>Sorry &laquo;"+data.name+"&raquo; !</h2><ul><li>Error Submitting The Form !</li></ul><h4>please "+data.name+" try again later on.</h4><p>Message not sent.</p>");
			  		$('#info_response').show().fadeOut(9000, function() {
			  			$('.contactForm').fadeIn(3500);
			  		});
			  	}
			}, "json");
			
			//waits 2000, then closes the form 
			 setTimeout(function() {
			contactForm.toggleReveal();
			}, 8000);
			//stay on the page
			return false;
		} 
  });
	//Modal sticky : select all the a tag with name equal to modal  
    $('a[class=modal]').click(function(e) {  
        //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 height 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();  
                
         var y=0;
if (self.pageYOffset) // all except Explorer
{
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
y = document.body.clientHeight;
}

//Get the window height and width
var winH = y;       
        //Set the popup window to center  
        $('.window').css('top',  winH/2+$('.window').height()/2);  
        $('.window').css('left', winW/2-$('.window').width()/2);  
      
        //transition effect  
        $(id).fadeIn(2000);   
      
    });  
      
    //if close button is clicked  
    $('.window .close').click(function (e) {  
        //Cancel the link behavior  
        e.preventDefault();  
        $('#mask, .window').hide();  
    });       
      
    //if mask is clicked  
    $('#mask').click(function () {  
        $(this).hide();  
        $('.window').hide();  
    });  
    $(document).keyup(function(e) {
	if(e.keyCode == 27) {  
    $('#mask, .window').hide();
  	}
  	});
 
// submit client
 	$('input.text').css({backgroundColor:"#FFFFFF"});
  	$('input.text').focus(function(){
    	$(this).css({backgroundColor:"#FFDDAA"});
  	});
  	$('input.text').blur(function(){
    	$(this).css({backgroundColor:"#FFFFFF"});
  	});

  	$(".sendbutton").click(function() {
    	$('#g-form label em').hide();
	  	var usr = $("input#username").val();
		if (usr == "") {
      		$("em.usr_error").show();
      		$("input#username").focus();
      		return false;
    	}
		var pwd = $("input#password").val();
		if (pwd == "") {
     		$("em.pwd_error").show();
     		$("input#password").focus();
      		return false;
    	}
		$.post("../include/guest.php", {username:$('#username').val(),
							  password:$('#password').val(),
							  remember:$('#remember').val()},
		function(data){
		$('.message_post').removeClass('error');
		$('.message_post').removeClass('success');
			$('#g-form fieldset').hide();
			if(data.name_check == 'valid'){
				
				$('input#password').val('');
				$('input#username').val('');
				$('input#remember').attr('checked', false);
				$('.message_post').addClass('success').html("<h2>Congratulation !</h2><p>You will be redirect in 10s...</p>").show().fadeOut(10000, function() {
					top.location = data.url;
					});
			} else {
				$('input#password').val('');
				$('.message_post').addClass('error').html("<h2>Incorrect Data !</h2><ul><li>Login error !</li></ul><p>check your username and password.</p>");
				$('.message_post').show().fadeOut(10000, function() {
					$('#g-form fieldset').fadeIn(3500);
				});
			}
				
		}, "json");
		return false;
	});

//submission FAQ

  	$(".faqbtn").click(function() {
    	$('#f-form label em').hide();
    	var qfilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	  	var imail = document.getElementById('faqemail');
		var qform = document.getElementById('f-form');
		
		if (!qfilter.test(imail.value)) {
			$('.iel_wrong').show();
		} else {$('.iel_wrong').hide();}
		if (qform.faqsub.value == "") {
			$('.isb_wrong').show();
		} else {$('.isb_wrong').hide();}	
		if (qform.faqmsg.value == "") {
			$('.imsg_wrong').show();
		} else {$('.imsg_wrong').hide();}			
		if ((qform.faqsub.value == "") || (!qfilter.test(imail.value)) || (qform.faqmsg.value == "")){
			return false;
		} 
		
		if ((qform.faqsub.value != "") && (qfilter.test(imail.value)) && (qform.faqmsg.value != "")) {
			//hide the form
			$('#f-form fieldset').hide();
		
    
		$.post('../include/faq.php', {faqemail:$('#faqemail').val(),faqsub:$('#faqsub').val(),faqmsg:$('#faqmsg').val()},
		function(data){
		$('.message_post').removeClass('error');
		$('.message_post').removeClass('success');
		
			if(data.email_check == 'valid'){
					$('.message_post').addClass('success').html("<h2>Congratulation !</h2><ul><li>Question Submitted!</li><p>We will reply as soon as possible.</p>").fadeIn(6500);
			} else {
				$('.message_post').addClass('error').html("<h2>ERROR!</h2><ul><li>Error Submitting The Form !</li></ul><h4>Try again later</h4><p>question not send.</p>").show().fadeOut(9000, function() {
			  			$('#f-form fieldset').fadeIn(3500);
			  		});
			}		
		}, "json");
		
		return false;
		}
	});
	//submission QUOTE
$('#rcancel').click(function(){
        $('#rcancel input').val('');
        $('#rcancel textarea').val('');
        $('#rcancel em').hide();
        top.location = '../development/web-services.html';
		return false;
    });
  	$(".qotbtn").click(function() {
    	$('#p-form label em').hide();
    	var pfilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	  	var pmail = document.getElementById('pmail');
		var pform = document.getElementById('p-form');
		
		if (!pfilter.test(pmail.value)) {
			$('.pil_wrong').show();
		} else {$('.pil_wrong').hide();}
		if (pform.pname.value == "") {
			$('.pne_wrong').show();
		} else {$('.pne_wrong').hide();}
		if (pform.pphone.value == "") {
			$('.pho_wrong').show();
		} else {$('.pho_wrong').hide();}
		if (pform.poverview.value == "") {
			$('.pew_wrong').show();
		} else {$('.pew_wrong').hide();}		
		if ((pform.pname.value == "") || (!pfilter.test(pmail.value)) || (pform.pphone.value == "") || (pform.poverview.value == "")){
			return false;
		} 
		
		if ((pform.pname.value != "") && (pfilter.test(pmail.value)) && (pform.pphone.value != "") && (pform.poverview.value != "")) {
			//hide the submit
			$('#p-form fieldset').hide();
		
    
		$.post('../include/quote.php', {pmail:$('#pmail').val(),pname:$('#pname').val(),pcompany:$('#pcompany').val(),pphone:$('#pphone').val(),purl:$('#purl').val(),poverview:$('#poverview').val()},
		function(data){
		$('.message_post').removeClass('error');
		$('.message_post').removeClass('success');
			if(data.data_check == 'valid'){
				$('.message_post').addClass('success').html("<h2>Congratulation !</h2><ul><li>Form Submitted!</li></ul><h4>Thank you for your interest!</h4><p>We will reply as soon as possible.</p>").fadeIn(6500, function() {
					top.location = '../development/web-services.html';
				});
			} else {
				$('.message_post').addClass('error').html("<h2>ERROR!</h2><ul><li>Error Submitting The Form !</li></ul><h4>Try again later</h4>").show().fadeOut(9000, function() {
					$('#p-form fieldset').fadeIn(3500);
					});
			}
		}, "json");
		return false;
		}
	});
});
	
