this.pngfix = function() {
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	if (jQuery.browser.msie && (ie55 || ie6)) {		
		$("*").each(function(){
			var bgIMG = $(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				$(this).css('background-image', 'none');
				$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='crop')";
			};
		});
	};		
};

this.form = function(){	
	
	this.validate = function(fname, lname, company, job, city, country, email, message){
		$("span.error").remove();
		var valid = true;
		if(fname == "") {
			error($("#fname"),"Por favor ingrese su nombre.")
			valid = false;
		};	
		if(lname == "") {
			error($("#lname"),"Por favor ingrese su apellido.")
			valid = false;
		};
		if(company == "") {
			error($("#company"),"Por favor ingrese el nombre de su empresa.")
			valid = false;
		};
		if(job == "") {
			error($("#job"),"Por favor ingrese su cargo.")
			valid = false;
		};
		if(city == "") {
			error($("#city"),"Por favor su ciudad de ubicacion.")
			valid = false;
		};
		if(country == "") {
			error($("#country"),"Por favor seleccione el pais de su ubicacion.")
			valid = false;
		};
		if(!checkEmail(email)) {
			error($("#email"),"Por favor ingrese un email valido.")
			valid = false;
		};
		if(message == "") {
			error($("#message"),"Por favor ingrese los comentarios o requerimientos especiales.")
			valid = false;
		};					
		return valid;
	};
	
	this.checkEmail = function(str){
	  var regEx = /^[^@]+@[^@]+.[a-z]{2,}$/;
	  return (str.search(regEx) != -1);
	};	
	
	this.error = function(obj,text){
		var parent = $(obj).parent();
		parent.append("<span class=\"error\">"+ text +"</span>");
		$("span.error",parent).hide().show("fast");
	};	
		
	$("#contactForm button").click(function(){								
		var fname = $("#fname").val();
		var lname = $("#lname").val();
		var company = $("#company").val();
		var job = $("#job").val();
		var city = $("#city").val();
		var country = $("#country").val();
		var email = $("#email").val(); 		
		var message = $("#message").val();	 				
		if(validate(fname, lname, company, job, city, country, email, message)) return true;
		return false;
	});	
};

this.init = function() {
	form();
	pngfix();
};

$(document).ready(function(){	
	init();
});
