var name;
var email
var coment;
var tel;
var empresa;
var Dialogoso;
var Err;
var sector;
var premium;

function showContactoNeo(Palabra){
	var style_normal = "1px solid #D8ECF3";
	Dialogoso = new Dialog();
	
	$("name").value = "";
	$("empresa").value = "";
	$("mail").value = "";
	$("coment").value = "";
	$("phone").value = "";

	$("name").style.border = style_normal; 
	$("name").style.background = "";
	$("empresa").style.border = style_normal; 	
	$("empresa").style.background = "";
	$("mail").style.border = style_normal; 	
	$("mail").style.background = "";
	$("coment").style.border = style_normal; 
	$("coment").style.background = "";
	$("phone").style.border = style_normal; 	
	$("phone").style.background = "";
	
	Dialogoso.Show("Divcontact_neo");
	
	if(!/MSIE/.test(navigator.userAgent)){
		$("ContactoInformation").style.left = "45px";
	}
	
	$("ContenidoContacto").show();
	$("TituloContacto").innerHTML = Palabra;
	$("ContactoInformation").innerHTML = "";
	
	
}
function hideContactoNeo(){
	Dialogoso.Hide("Divcontact_neo");		
}

function verificadatos(){
		var tControl = "";
		var style_error = "1px solid #FF0000";
		var style_normal = "1px solid";
		var Regex_Mail = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
		var Regex_Tel = new RegExp(/^([0-9- ])+$/);
		var car_esp = new RegExp(/^([a-zA-Z0-9_\.\-\! ])+$/);
		Err = 0;

		email = $("mail").value;
		coment = $("coment").value;
		sector = $("sector").value;
		
		//campo email
		if(!trim(email) == ""){	
			if(email.match(Regex_Mail)){
				$("mail").style.border = style_normal; 
				$("mail").style.background = "";
			}else{
				$("mail").style.border = style_error; 
				$("mail").style.background = "#FFEDEC";
				Err = 1;

			}
		}else{
			$("mail").style.border = style_error; 
			$("mail").style.background = "#FFEDEC";
			Err = 1;
		}

		//campo comentario
		if(!trim(coment) == ""){	
			if(!coment.lenght < 2){
				$("coment").style.border = style_normal; 
				$("coment").style.background = "#fff";
			} else {
				$("coment").style.border = style_error; 
				$("coment").style.background = "#FFEDEC";
				Err = 1;
			}
		} else {
			$("coment").style.border = style_error; 
			$("coment").style.background = "#FFEDEC";
			Err = 1;
		}
		
		//campo sector
		if(sector != -1){
			$("sector").style.border = style_normal; 
			$("sector").style.background = "#fff";
		} else {
			$("sector").style.border = style_error; 
			$("sector").style.background = "#FFEDEC";
			Err = 1;
		}
		
		if (Err == 0) {
			if($("premium").value == 1) {
				enviarAjaxMail = 'a=chk&mail=' + $("mail").value;

				AJAX = new Request ('ajax/consultas.php');
				AJAX.Async(enviarAjaxMail, Callback_enviarMail, this, false);
			} else {
				//if (Err ==0) enviarReg(name,empresa,email,tel,coment);
				 premium = 0;
				 enviarReg(email,sector,coment, premium);			 
			}
		}
}

function Callback_enviarMail(varExtra, aData){

		$("divEnviado").innerHTML = "Ticket enviado";				
}

function VerificarCampoNombre(){	

		var style_error = "1px solid #FF0000";
		var style_normal = "1px solid";

		if(!trim($("name").value) == ""){	
			if(!$("name").value.lenght < 2){
				$("name").style.border = style_normal; 
				$("name").style.background = "#fff";
				//$("iNombre").style.visibility = "visible";
				//$("iNombreD").style.visibility = "hidden";
			}else{	
				$("name").style.border = style_error; 
				$("name").style.background = "#FFEDEC";
			}
		}else{
			$("name").style.border = style_error; 
			$("name").style.background = "#FFEDEC";
		}
}
function VerificarCampoEmpresa(){	


}

function VerificarCampoComent(){	

		var style_error = "1px solid #FF0000";
		var style_normal = "1px solid";

		if(!trim($("coment").value) == ""){	
			if(!$("coment").value.lenght < 2){
				$("coment").style.border = style_normal; 
				$("coment").style.background = "#fff";
				//$("iComent").style.visibility = "visible";
				//$("iComentD").style.visibility = "hidden";
			}else{	
				$("coment").style.border = style_error; 
				$("coment").style.background = "#FFEDEC";				
			}
		}else{
			$("coment").style.border = style_error; 
			$("coment").style.background = "#FFEDEC";
		}
}
function VerificarCampoEmail(){
	
	var Regex_Mail = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	var style_error = "1px solid #FF0000";
	var style_normal = "1px solid";
	if(!trim($("mail").value) == ""){	
			if($("mail").value.match(Regex_Mail)){
				$("mail").style.border = style_normal; 
				$("mail").style.background = "#fff";
			}else{
				$("mail").style.border = style_error; 
				$("mail").style.background = "#FFEDEC";
			}
		}else{
			$("mail").style.border = style_error; 
			$("mail").style.background = "#FFEDEC";
		}
}



function VerificarCampoTelefono(){

}
function trim (string) {
	string = string.replace(/^\s+/, '');
	for (var i = string.length; i > 0; i--) {
		if (/\S/.test(string.charAt(i))) {
			string = string.substring(0, i);
			break;
		}
	}
	return string;
}
	
function FieldChecker(name, minLen, maxLen, checkerName, errorMessage) {
	this.name = name;
	this.minLen = minLen;
	this.maxLen = maxLen;
	this.checkerName = checkerName;
	this.errorMessage = errorMessage;
}
FieldChecker.prototype = {
	validate: function(thisValue) {
		elems = document.getElementsByName(this.name);
		if (elems.length == 0) return false;
		htmlObj = elems[0];
		return true;
		
		htmlObj.scrollIntoView(true);
		htmlObj.focus();
	}
}
	function enviarReg(mail,sector, com, premium){
		//enviarAjax= 'a=reg&nom=' + nombre + '&empre=' + empr + '&mail=' + mail + '&tel=' + phone + '&coment=' + com;
		enviarAjax= 'a=reg&mail=' + mail + '&sector=' + sector + '&coment=' + com + '&premium=' + premium;
		
		if ($('lang')) { enviarAjax += '&lang=' + $('lang').value}
		
		AJAX = new Request ('ajax/consultas.php');
		AJAX.Async(enviarAjax, Callback_enviarReg, this, false);

	}

function Callback_enviarReg(varExtra, aData){ /*se utliza en ingreso y en contact*/
    if(aData.responseText == 'Ticket agregado'){
        try{$("divEnviado").innerHTML = $("divMailEnviado").innerHTML;}catch(e){}
        try{$("consulta_enviada").show();}catch(e){}
        try{
            $("mail").value = "";
            $("coment").value = "";
        }catch(e){}
    }
}
