var root = '/';
//var root = '/sitio/';

function toggleContent(id,mode){
	mode = mode || null;
	
	if(mode == '1'){
		jQuery('#'+id).fadeIn();
	}else if(mode == '0'){
		jQuery('#'+id).fadeOut();
	}else if(document.getElementById(id).style.display == 'none'){
		jQuery('#'+id).fadeIn();
	}else{
		jQuery('#'+id).fadeOut();
	}
}

var Vcontainer;
function showCities(val,container){
Vcontainer = container || "contenedor";
	
document.getElementById(Vcontainer).innerHTML = '';
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ('Tu explorador no soporta AJAX !');
return;
}
var params = "id="+val;

if(val == '#' || val == '2') return;

xmlHttp.onreadystatechange = doShowCities;
xmlHttp.open("POST",root+"admin/_funciones_front/generar_ciudades.php",true);
xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
}

function doShowCities(){
if (xmlHttp.readyState==4){
document.getElementById(Vcontainer).innerHTML = xmlHttp.responseText;
}
}

function showSalario(id){
	var tipos = ['','salario_1','salario_2','salario_3'];
	var elem = tipos[id];
	
	jQuery('#'+tipos[1]).fadeOut();
	jQuery('#'+tipos[2]).fadeOut();
	jQuery('#'+tipos[3]).fadeOut();
	jQuery('#'+elem).fadeIn();
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src=root+'img/inputfile.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

function popup(msg,fade,color){
	Mcolor = color || "#FFF";
	jQuery.blockUI({ css: { 
		border: 'none', 
		padding: '20px', 
		backgroundColor: '#000', 
		fontSize: '16px', 
		'-webkit-border-radius': '10px', 
		'-moz-border-radius': '10px', 
		opacity: '.9', 
		color: Mcolor
 },message: msg });
 
 if(fade>0) setTimeout(jQuery.unblockUI, fade); 
}

function submitNewsletter(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX !');
		return;
	} 
	var params = "mail="+document.getElementById('mail').value;
	xmlHttp.onreadystatechange = NewsLetterDo;
	xmlHttp.open("POST","contacto/newsletter.php",true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
	document.getElementById('form').innerHTML = "Cargando...";
} 

function NewsLetterDo(){ 
	if (xmlHttp.readyState==4){ 
		document.getElementById('form').innerHTML = xmlHttp.responseText;
	}
}

function validate(status,id){
	if(status == 0){
		document.getElementById(id).style.borderColor = '#f00';
		document.getElementById(id).style.color= '#f00';
		errores++;
	}else{
		document.getElementById(id).style.borderColor = '';
		document.getElementById(id).style.color= '';
	}
}

function setval(id,val){
	document.getElementById(id).value = val;
}
function getval(id){
	return document.getElementById(id).value;
}
function getcheck(id){
	return document.getElementById(id).checked;
}
function gettype(id){
	return document.getElementById(id).type;
}
function getMultiple(ob){
	ob = document.getElementById(ob);
	selected = new Array();
	for(var i = 0; i < ob.options.length; i++) if(ob.options[i].selected) selected.push(ob.options[i].value);
	return selected;
}

function parseParams(params){
	var s = '';
	for(var i in params){
		var t = gettype(params[i]);
		if(t == 'checkbox' || t == 'radio'){
			s += params[i]+'='+getcheck(params[i])+'&'
		}else if(t == 'select-multiple'){
			s += params[i]+'='+getMultiple(params[i])+'&'
		}else{
			s += params[i]+'='+escape(getval(params[i]))+'&'
		}
	}
	return s.substr(0,s.length-1);
}

var errores = 0;
var loading = false;

var xmlHttp;
function GetXmlHttpObject(){var xmlHttp=null;try{xmlHttp=new XMLHttpRequest();}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;}

function redir(url,timeout){
	setTimeout('doRedir(\''+url+'\')',timeout);
}
function doRedir(url){
	window.location = url;
}
