/*
 * Shop4erp Custom Javascript
 */
 
function urlencode(str) {
	if(str){
		var ret = str;
	    ret = ret.toString();
	    ret = escape(ret);
	    ret = ret.replace(/%20/g, '+');
		return ret;
	}else{
		return false;
	}
}

$(document).ready(function(){
	$("form#contactForm").submit(function() {
		var name = urlencode($("#contactForm [name='name']").val());
		var company = urlencode($("#contactForm [name='company']").val());
		var position = urlencode($("#contactForm [name='position']").val());
		var email = urlencode($("#contactForm [name='email']").val());
		var phone = urlencode($("#contactForm [name='phone']").val());
		var question = urlencode($("#contactForm [name='question']").val());
		var contact_by_phone = 'no';
		//if($("#contactForm [name='contactMe']").attr('checked')){contact_by_phone = 'yes';}
		var email_whitepaper = 'no';
		//if($("#contactForm [name='emailLorem']").attr('checked')){email_whitepaper = 'yes';}
		var email_offers = 'no';
		//if($("#contactForm [name='specialOffers']").attr('checked')){email_offers = 'yes';}
		
		//
		if(name==''  || company==''|| position=='' || email==''){
			alert('Please fill in all the fields');
			return false;
		}
		
/* 		else{
			var rText = $.ajax({
	            type: "GET",
	            url: "http://www.shop4erp.com/send_email.php",
				data: "name="+name+"&company="+company+"&position="+position+"&email="+email+"&phone="+phone+"&question="+question+"&contact_by_phone="+contact_by_phone+"&email_whitepaper="+email_whitepaper+"&email_offers="+email_offers,
	            async: false
			}).responseText;
			$("#contactFormStatusMessage").html(rText);
			$("#contactFormStatusMessage").show("slow");
			return false;
		} */		

	});
	
	$("form#demoOptin").submit(function() {
		var name = $("#demoOptin [name='name']").val();
		var company = $("#demoOptin [name='company']").val();
		var email = $("#demoOptin [name='email']").val();
		if(name==''  || company=='' || email==''){
			alert('Please fill in all the fields');
			return false;
		}else{
			return true;
		}
	});
	
	//Link for logo, it's stuck in a bg image, ugh
	$("#shop4erpLogo").click(function () {
		document.location.href="/";
	});

	//30% off animation on the homepage
	q1 = {
		init: function() {
			//$("#slideDeal").click(function() {
			
			//var i=0;
			//while (i<=10){
				$("#slideDeal").fadeOut('slow', function() {
					$("#slideDeal").html("Up to <span>30% OFF</span>").fadeIn('slow');
				});
				//i=i+1;
			//}
			

/* 				$("#slideDeal").fadeOut('slow', function() {
					$("#slideDeal").html("Up to <span>30% OFF</span>").fadeIn('slow');
				}); */
			//});
		}
	}
	q1.init();

});