
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
};


function getHTMLContent(url, contentId, func, method){
	if (method == null){
		method = "POST";
	}
	
	var conn = new XHConn();
	if (!conn)
	{
		alert('Error en el objeto XMLHTTP');
	}
	else
	{
		var result = function(xml){
			document.getElementById(contentId).innerHTML = xml.responseText;
			func(xml);
		};
		
		conn.connect(url, method, '', result);
	}
};

function pngFix(){
	if ( ($.browser.msie && $.browser.version < 7)) { 
		$(".pngTransparent").each(function(i){	
			var repeticion = $(this).css('background-repeat');	
			var url = $(this).css('background-image');
			$(this).css('background', 'none');
			url = url.replace(new RegExp(/^url\(\"/i),"");
			url = url.replace(new RegExp(/\"\)/i),"");					
			if(repeticion == 'no-repeat'){
				$(this).css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + url + '", sizingMethod="crop")');
			}else{
				$(this).css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + url + '", sizingMethod="scale")');
			}					
		});
	}	
};

function validateForm(form){
	
		var returnValue = true;
		var errorMessage = '';
		var focusField = null;
		var i = 0;
		
		if(form.nombre){
			if (!form.nombre.value){
				if(!focusField){
					focusField = form.nombre;
				}
				i++;
				if(form.lang.value == 'en'){
					errorMessage += 'Name,';
				}else{
					errorMessage += 'Nombre,';
				}
				
				returnValue = false;
			}
		}
		if(form.movil){
			if (!form.movil.value){
				if(!focusField){
					focusField = form.movil;
				}
				i++;
				returnValue = false;
				if(form.lang.value == 'en'){
					errorMessage += 'Mobile,';
				}else{
					errorMessage += 'Movil,';
				}
			}
		}
		if(form.mail){
			if (!form.mail.value){
				if(!focusField){
					focusField = form.mail;
				}
				i++;
				returnValue = false;
				errorMessage += 'E-mail,';
			}
		}
		if(form.observacionesDemanda){
			if (!form.observacionesDemanda.value){
				if(!focusField){
					focusField = form.observacionesDemanda;
				}
				i++;
				returnValue = false;
				if(form.lang.value == 'en'){
					errorMessage += 'Comment,';
				}else{
					errorMessage += 'Observaciones,';
				}
			}
		}
		
				
		if (!returnValue){
			errorMessage = errorMessage.substring(0,errorMessage.length-1);
			if (i>1){
				if(form.lang.value == 'en'){
					alert('The Fields (' + errorMessage + ') are required');
				}else{
					alert('Los campos (' + errorMessage + ') son obligatorios');
				}
			}else{
				if(form.lang.value == 'en'){
					alert('The field ' + errorMessage + ' is required');
				}else{
					alert('El campo ' + errorMessage + ' es obligatorio');
				}
			}
			if(focusField){
				focusField.focus();
			}
		}
		
		return returnValue;

}

function formFocus(){
	$('form input:text, form textarea, form select').each(function(){
		$(this).focus(function(){
			
			$(this).css("background-color","#f1f1f1");
		});
		$(this).blur(function(){
			$(this).css("background","none");
		});
	});
}


$(document).ready(function(){ 
	pngFix(); 
	formFocus();
});


function validateFormPedido(form){
	
		var returnValue = true;
		var errorMessage = '';
		var focusField = null;
		var i = 0;
		
		if(form.fecha){
			if (!form.fecha.value){
				if(!focusField){
					focusField = form.fecha;
				}
				i++;
				if(form.lang.value == 'en'){
					errorMessage += 'Date,';
				}else{
					errorMessage += 'Fecha,';
				}
				
				returnValue = false;
			}
		}
		if(form.empresa){
			if (!form.empresa.value){
				if(!focusField){
					focusField = form.empresa;
				}
				i++;
				returnValue = false;
				if(form.lang.value == 'en'){
					errorMessage += 'Company,';
				}else{
					errorMessage += 'Empresa,';
				}
			}
		}
		if(form.mail){
			if (!form.mail.value){
				if(!focusField){
					focusField = form.mail;
				}
				i++;
				returnValue = false;
				errorMessage += 'E-mail,';
			}
		}
		
				
		if (!returnValue){
			errorMessage = errorMessage.substring(0,errorMessage.length-1);
			if (i>1){
				if(form.lang.value == 'en'){
					alert('The Fields (' + errorMessage + ') are required');
				}else{
					alert('Los campos (' + errorMessage + ') son obligatorios');
				}
			}else{
				if(form.lang.value == 'en'){
					alert('The field ' + errorMessage + ' is required');
				}else{
					alert('El campo ' + errorMessage + ' es obligatorio');
				}
			}
			if(focusField){
				focusField.focus();
			}
		}
		
		return returnValue;

}
