function delete_confirm_list(page_to_go) {
	var go = confirm("¿ Desea realmente eliminar éste elemento ?");
	if (go == true)  document.location.href = page_to_go;
}



/**********************************************************************************************/
/**********************************************************************************************/
/**********************************************************************************************/
/**********************************************************************************************/

/*
 * 
 * 
 * DESCOMENTAR LO QUE HAGA FALTA Y LUEGO BORRAR LO QUE NO SE USE
 * 
 * 
 */



lastClickedButton = "";


function doSubmit(form){
	var res =checkForm(form);
	if(res){	
		form.submit();
	}else{
		return false;
	} 
}


/*
function delete_confirm() {
	var go = confirm("¿ Confirma que desea eliminar realmente éste elemento ?");
	if (go == true)  return true;
	else return false;
}
*/



function confirmAction(page_to_go, msg) {
	var go = confirm(msg);
	if (go == true)  document.location.href = page_to_go;
}

function checkField(tag){
	if(tag.id == "fb_allow"){
		if(tag.value != ""){
			
			v = tag.value.toLowerCase();
			vpos = v.indexOf("id=") + 3;
			car = vpos; //desde el id hasta que no sea numerico
			
			console.log(car);
			
			var currCar = 0;
			var count = 0; //por seguridad para que no cuelgue el browser
			
			while(!isNaN(currCar) || count>20){
				currCar = v.charAt(car)
				car++ ;
				count++;
			}

			var nextPos = car -1 + 3;
			
			//facebookId
			var FBID =  v.substr(vpos,v.length - nextPos);
//			tag.value = FBID;
			button = document.getElementById("chkFBProfile");
			button.href = "http://www.facebook.com/profile.php?id=" + FBID;
			button.style.display="inline";
		}
		return;
	}	
	if(tag.getAttribute("required") == "true" && tag.value == ""){
		markFieldAs(tag, false);		
	}else{
		markFieldAs(tag, "correct");
	}
	
//	if(tag.getAttribute("subtype") == "mail" && validateEmail(tag,tag.getAttribute("tip")) ){
//		alert("FALSE");
//		markFieldAs(tag, false);		
//	}else{
//		alert("CORRECT");
//		markFieldAs(tag, "correct");
//	}
}

function markFieldAs(tag, valid, errorText){
	if(valid){
		tag.className = "formTextField";
		tag.title = errorText;
	}else if(valid == false){
		tag.className = "textFieldError";
		tag.title = errorText;
	}else if(valid == "correct"){
		tag.className = "textFieldCorrect";
		tag.title = errorText;
	}
}

function validateEmail ( emailField, errorMsg ) {
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_\-])*@([a-zA-Z0-9])+([a-zA-Z0-9_\-\.]+)+$/;
	if( !emailpat.test( emailField.value ) ) {
		emailField.focus();
		emailField.select();
		return false;
	}
	return true;
}

function checkForm(f){
	
	var validated = true;
	var focusMoved = false;
	
	for (var element=0; element < f.elements.length; element++){
		tag = f.elements[element];

		markFieldAs(tag, true, "");

		if (tag.getAttribute("required")=="true" && !tag.value){
			markFieldAs(tag, false, tag.getAttribute('tip'));
			alert(tag.getAttribute('tip'));
			if(tag.focusMoved == false){
				tag.focus();
				focusMoved = true;
			}
			if(validated != false) validated = false;
			break;
		}
		
//		if (tag.getAttribute("validator")){
//			if (!eval(tag.getAttribute("validator"))(tag)){
//				if(tag.focusMoved == false){
//					tag.focus();
//					focusMoved = true;
//				}
//
//				if(validated != false) validated = false;
//			}
//		}

//		//para combos
//		if(tag.getAttribute("required") == 'true'){
//			if(tag.selectedIndex ==-1 || tag.selectedIndex == 0){
//				markFieldAs(tag, false, tag.getAttribute('tip'));
//				if(tag.focusMoved == false){
//					tag.focus();
//					focusMoved = true;
//				}
//
//				if(validated != false) validated = false;
//			}
//		}
		
		if(tag.getAttribute("type") == "checkbox"){
			if(tag.getAttribute("required") == 'true' && tag.checked == false){
				
				markFieldAs(tag, false, tag.getAttribute('tip'));
				alert(tag.getAttribute('tip'));
				if(tag.focusMoved == false){
					tag.focus();
					focusMoved = true;
				}
				if(validated != false) validated = false;
			}
		}
	}
	
	return validated;
}

function getSelectedItems(f){
	var In  = document.getElementById("noticias_selected");
	var optLen = In.options.length;
	for (var i = 0 ; i < optLen; i++) {
		In.options[i].selected = true;
	}
	 
	return checkForm(f);
}

function checkSelectedCombo(c){
	if(c.selectedIndex!=0 &&  c.selectedIndex!=-1){
		return true;	
	}else{
		return false;
	}
}

function openPopUp(url, title) {		
	window.open(url, title, 'toolbar=0,location=1,width=790,height=530,left=0,top=0,screenX=0,screenY=0,directories=0,status=0,menuBar=0,scrollBars=yes,resizable=0,fullscreen=0');		
}

/*
function selectAllCheckBoxes(checkerRoot){
	var inputs = document.getElementsByTagName("input");
	for(var element=0; element < inputs.length; element++){
		if( (inputs[element].getAttribute("type")=="checkbox") && (inputs[element]!=checkerRoot)){
			inputs[element].checked=checkerRoot.checked;
		}
	}
}
*/
/*
function getTip (f){
	var tip = f.getAttribute('tip');
	if (tip.substr(0,1) == '$')
		tip = eval (tip.substring(1));

	return tip;
}
*/
/*
function checkMail (f) {
	var emailStr = f.value;
	var emailPat=/^(.+)@(.+)$/
	
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("E-mail invalido")
		return false
	}
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null) {
		alert("E-mail invalido")
		return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("IP de destino invalida")
				return false
			}
		}
		return true
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("E-mail invalido")
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		alert("E-mail invalido")
		return false
	}
	
	if (len<2) {
		alert("E-mail invÃ¡lido")
		return false
	}
	
	// La direccion de email ingresada es Valida
	return true;
}
*/
/*
function moreInfo(f, tip, show, name){
	if (show==true){
		var inp = document.createElement('input');
		//var tip = getTip(f);			
		inp.setAttribute ("type","text");
		inp.setAttribute ("name", name);
		inp.setAttribute ("id", name);
		inp.setAttribute ("size","35");
		inp.setAttribute ("value",tip);
		//inp.setAttribute ("tip",tip);
		//inp.setAttribute ("required","true");
		inp.setAttribute ("onfocus","cleanText(this)");
		f.parentNode.appendChild(inp);
		
		//<input type="text" name="procedencia_otros" value="{$procedencia_otros}" size="50" disabled/>
		
		
	} else {
		var inp = document.getElementById(name);
		f.parentNode.removeChild(inp);
	}
}


function cleanText (t){
	//if (getTip(t) == t.value)
		t.value = "";
}*/
/*
function showInfo(id,show){
	var t = document.getElementById(id);
	t.style.display = show;
}

function showInfoC (id,c){
	var t = document.getElementById(id);
	t.style.display = c.checked ? '' : 'none';
}*/
function setSelected(myForm){
	var opt=myForm.noticias_selected.options.length
	for (var i = 0; i < opt; i++) {
			myForm.noticias_selected.options[i].selected=true;
		}
}
function addNews(){
	var Out = document.getElementById("noticias_list");
	var In  = document.getElementById("noticias_selected");
	var optLen = Out.options.length;
	for (var i = 0 ; i < optLen; i++) {
		if (Out.options[i].selected) {
			var newOpt=document.createElement('option');
  			newOpt.text=Out.options[i].text;
			newOpt.value=Out.options[i].value;
 			try
    		{
    			In.add(newOpt,null); // standards compliant
    		}
 			 catch(ex)
    		{
   				 In.add(newOpt); // IE only
    		}
		}
	}
	optLen = Out.options.length - 1;
	for (var i = optLen; i >= 0;i--) {
		if (Out.options[i].selected) {
			Out.remove(Out.options[i].index);
		}
	}
}
function delNews(){
	var Out = document.getElementById("noticias_selected");
	var In  = document.getElementById("noticias_list");
	var optLen = Out.options.length;
	for (var i = 0 ; i < optLen; i++) {
		if (Out.options[i].selected) {
			var newOpt=document.createElement('option');
  			newOpt.text=Out.options[i].text;
			newOpt.value=Out.options[i].value;
 			try
    		{
    			In.add(newOpt,null); // standards compliant
    		}
 			 catch(ex)
    		{
   				 In.add(newOpt); // IE only
    		}
		}
	}
	optLen = Out.options.length - 1;
	for (var i = optLen; i >= 0;i--) {
		if (Out.options[i].selected) {
			Out.remove(Out.options[i].index);
		}
	}
}
function upNews(){
	var news = document.getElementById("noticias_selected");
	var optLen = news.options.length;
	for (var i = 0 ; i < optLen; i++) {
		if (news.options[i].selected) {
				var idx = news.options[i].index
				var nxidx = idx-1
			    if (nxidx >= 0){
					var oldVal = news[idx].value
			    	var oldText = news[idx].text
			    	news[idx].value = news[nxidx].value
			    	news[idx].text = news[nxidx].text
			    	news[nxidx].value = oldVal
			    	news[nxidx].text = oldText
					news[idx].selected=false
			    	news[nxidx].selected=true	
				} 
			    
			}
	}
}
function dnNews(){
	var news = document.getElementById("noticias_selected");
	var optLen = news.options.length-1;
	for (var i = optLen; i >= 0; i--) {
		if (news.options[i].selected){
				var idx = news.options[i].index
				var nxidx = idx+1
			    if (nxidx <= optLen){
					var oldVal = news[idx].value
			    	var oldText = news[idx].text
			    	news[idx].value = news[nxidx].value
			    	news[idx].text = news[nxidx].text
			    	news[nxidx].value = oldVal
			    	news[nxidx].text = oldText
					news[idx].selected   = false
			    	news[nxidx].selected = true	
				} 
		}
	}
}
function shDiv(divname){
	var divM = document.getElementById(divname)
	if(divM.style.display == 'none' || divM.style.display == ''){
		showDiv(divname)
	}
	else{
		hideDiv(divname)
	}
}
function showDiv (divname){
	var divM = document.getElementById(divname);
	divM.style.display = 'block';
}  	
function hideDiv (divname){
	var divM = document.getElementById(divname);
	divM.style.display = 'none';
}  
function selected(menuname){
	var mm = document.getElementById(menuname);
	deselAll();
	if (mm) 
		mm.className = 'selected'
}
function deselAll(){
	//desel('home');
	desel('users');
	desel('profiles');
	//desel('incidencias');
	desel('consultas');
	desel('edcenters');
	desel('agenda');
	desel('activities');
	desel('communications');
	desel('logout');
}
function desel(menuname){
	var mm = document.getElementById(menuname);
	if (mm) 
		mm.className = ''
}

/**
Funcion de comprovacion de parametros para el formulario de consulta
*/
function checkFormChangeState() {
	if ($("select[name=change]").val() == "") {
		alert("No has seleccionado ninguna accion a realizar.");
		return false;
	}
	var i = $("form :checked").length;
	if (i == 0) {
		alert("Para realizar un cambio hay que seleccionar al menos un elemento.");
		return false;
	}
	return true;
}

function submitform(thisForm){
	var targetForm = document.getElementById(thisForm);
	targetForm.submit();
}

function clearText(theField)
{
if (theField.defaultValue == theField.value)
theField.value = '';
}


function showSubMenu(divname,parent){
	var divM = document.getElementById(divname)
	var divP = document.getElementById(parent)
	if(divM.style.display == 'none' || divM.style.display == ''){
		divM.style.display = 'block';
		divP.className = 'menuSelected';
	}
	else{
		divM.style.display = 'none';
		divP.className = 'option';
	}
}


function openThickBox(title, url){
	  tb_show(title, url);
	}
