jQuery('document').ready(function(){

	jQuery('a.cleardata').click(function(){
		var formTarget = document.getElementById("form1");
		formTarget.reset();
		jQuery("span.required").html("");
	});
});
var checkEmail = function(email){
	var emailFormat = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,7}|\d+)$/i;
	return emailFormat.test(email);
};
var checkValue = function(){
	var onlynum = /^[0-9]+$/;
	var error = 0;
	if(document.form1.name.value==""){
		error++;
		jQuery("#nameSpan").html("Please type in name.");
	}else{
		jQuery("#nameSpan").html("");
	}
	if(document.form1.company.value==""){
		error++;
		jQuery("#companySpan").html("Please type in company.");
	}else{
		jQuery("#companySpan").html("");
	}
	if(document.form1.email.value==""){
		error++;
		jQuery("#emailSpan").html("Please type in email.");
	}
	if(document.form1.email.value!=""){
		if(checkEmail(document.form1.email.value)==false){
			error++;
			jQuery("#emailSpan").html("Please type in correct email format.");
		}else{
			jQuery("#emailSpan").html("");
		}
	}

	if(document.form1.msg.value==""){
		error++;
		jQuery("#msgSpan").html("Please type in message.");
	}else{
		jQuery("#msgSpan").html("");
	}
	if(error==0){
		if(typeof submitFunction == "function"){
			submitFunction();
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
};

var checkValue2 = function(){
	var onlynum = /^[0-9]+$/;
	var error = 0;
	if(document.form2.pegeto.value==""){
		error++;
		jQuery("#pegetoSpan").html("Please type in pegeto.");
	}else{
		jQuery("#pegetoSpan").html("");
	}
	if(document.form2.emailto.value==""){
		error++;
		jQuery("#emailtoSpan").html("Please type in email.");
	}
	if(document.form2.emailto.value!=""){
		if(checkEmail(document.form2.emailto.value)==false){
			error++;
			jQuery("#emailtoSpan").html("Please type in correct email format.");
		}else{
			jQuery("#emailtoSpan").html("");
		}
	}
	if(error==0){
		if(typeof submitFunction == "function"){
			submitFunction2();
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
};

var submitFunction = function(){
		if(jQuery(document.body).height() < document.body.scrollHeight){
			jQuery('#fade').css("height",document.body.scrollHeight+"px");
			jQuery('#lightboxframe').css("height",document.body.scrollHeight+"px");
		}else{
			jQuery('#fade').css("height",j(document.body).height());
			jQuery('#lightboxframe').css("height",j(document.body).height());
		}
		jQuery('#lightboxframe').css("display","block");
		var scrollTop = parseInt( jQuery( document ).scrollTop()+30 );
		jQuery('#popupwrapper').css("top",scrollTop);
		jQuery("#fade").fadeIn('slow');
		jqAjax('sendmail.php','popupcontent','form1',nextfunction);
		jQuery(window).scroll(function(){
			var pageScroll =  parseInt( jQuery( document ).scrollTop() );
			if(jQuery.browser.msie){
				//if IE browser
				jQuery('#popupwrapper').animate({top:pageScroll+100},0);
			}else{
				jQuery('#popupwrapper').animate({top:pageScroll+100},100);
			}
		});
		return false;
};

var submitFunction2 = function(){
		if(jQuery(document.body).height() < document.body.scrollHeight){
			jQuery('#fade').css("height",document.body.scrollHeight+"px");
			jQuery('#lightboxframe').css("height",document.body.scrollHeight+"px");
		}else{
			jQuery('#fade').css("height",j(document.body).height());
			jQuery('#lightboxframe').css("height",j(document.body).height());
		}
		jQuery('#lightboxframe').css("display","block");
		var scrollTop = parseInt( jQuery( document ).scrollTop()+30 );
		jQuery('#popupwrapper').css("top",scrollTop);
		jQuery("#fade").fadeIn('slow');
		jqAjax('sendmail_to.php','popupcontent','form2',nextfunction);
		jQuery(window).scroll(function(){
			var pageScroll =  parseInt( jQuery( document ).scrollTop() );
			if(jQuery.browser.msie){
				//if IE browser
				jQuery('#popupwrapper').animate({top:pageScroll+100},0);
			}else{
				jQuery('#popupwrapper').animate({top:pageScroll+100},100);
			}
		});
		return false;
};

var nextfunction = function(){
	jQuery("#popupclose a").click(function(){
		jQuery("#fade").fadeOut("slow");
		document.forms[0].reset();
		jQuery("#type").attr("disabled",true);
		jQuery("#size").attr("disabled",true);
		jQuery("td.tdsummary span").html("-");
		jQuery('#lightboxframe').css("display","none");
	});
};
