function goSubmit()
{
	document.getElementById('general').target='_self';
	document.getElementById('general').submit();
}

function goSearch()
{
	document.getElementById('metodo').value='';
	goSubmit();
}

function goSort(pName, pAsc)
{
	document.getElementById('sort').value=  pName+'|'+pAsc;
	document.getElementById('metodo').value='';
	goSubmit();
}

function setPagina(pPagina)
{
	document.getElementById('pagina').value=pPagina;
	goSubmit();
}

function setCleanSearch()
{
	document.getElementById('buscar').value='';
	goSubmit();
}

function newElement()
{
	document.getElementById('metodo').value='mNew';
	goSubmit();
}

function exportElement()
{
	document.getElementById('metodo').value='mExport';
	goSubmit();
}

function cancelElement()
{
	goSubmit();
}

function editElement(pId)
{
	document.getElementById('cod_elemento').value=pId;
	document.getElementById('metodo').value='mEdit';
	goSubmit();
}

function editListElement()
{
	var frm = document.getElementById('general');
	var cuentaChecked=0;
		
	for(var i=0;i<frm.elements.length;i++) 
	{
		if(frm.elements[i].checked && frm.elements[i].id != 'chk_select_all')
		{
			cuentaChecked+=1;
			id_ = frm.elements[i].value;
		}
	}
	
	if (cuentaChecked==0)
	{
		window.alert ("Seleccione un Registro porfavor");
		return;
	}
	
	if(cuentaChecked>1)
	{
		window.alert("Solo debe seleccione  un registro para editar");
		return;
	}

	if(cuentaChecked==1)
	{
		editElement(id_);
	}
}

function saveElement()
{
	if (hay_caracter())
	{
		document.getElementById('metodo').value='mSave';
		goSubmit();
	}
}

function updElement()
{
	if (hay_caracter())
	{
		document.getElementById('metodo').value='mUpdate';
		goSubmit();
	}
}

function delElement()
{
	verf=0;
	var frm = document.getElementById('general');	
	for (i=0;i<frm.elements.length;i++)
	{
		if (frm.elements[i].checked && frm.elements[i].type == 'checkbox') {
			verf=1;
		}
	}
	if (verf==0)
	{
		window.alert ("Seleccione un Registro porfavor");
	}
	else
	{
		bResp=confirm("Esta Seguro de Eliminar los Registros Seleccionados?");
		if (bResp==true)
		{
			bResp=confirm("Este Proceso no tiene Marcha Atras\n Esta Completamente Seguro?");
			if (bResp==true)
			{
				document.getElementById('metodo').value='mDelete';
				frm.target='_self';
				frm.submit();	
			}
		}
	}
}

function onlyNum(pObj)
{
	regexp=/^[0-9]*$/
	if (pObj.value.match(regexp)==null)
	{
		pObj.value=pObj.value.substr(0,pObj.value.length-1);
	}
}

function validatePrice(pObj)
{
	regexp=/^[0-9]+\.?[0-9]*$/
	if (pObj.value.match(regexp)==null)
	{
		pObj.value=pObj.value.substr(0,pObj.value.length-1);
	}	
}

function trim(pStr)
{
	while (pStr.charAt(0) == ' ') pStr = pStr.substring(1);
	while (pStr.charAt(pStr.length - 1) == ' ') pStr = pStr.substring(0, pStr.length - 1);
	return pStr;
}

function checkEmail(pStr)
{
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	return (filter.test(pStr))
}

function popupWindopW(pMypage, pMyname, pW, pH, pScroll)
{
	var pWinl = (screen.pWidtpH - pW) / 2;
	var pWint = (screen.pHeigpHt - pH) / 2;
	pWinprops = 'pHeigpHt='+pH+',pWidtpH='+pW+',top='+pWint+',left='+pWinl+',pScrollbars='+pScroll+',menubar=no,status=no,resizable=no,modal=yes';
	pWin = pWindopW.open(pMypage, pMyname, pWinprops);
	if (!pWin.opener) 
	{
		pWin.opener = self;
	}	
	if (parseInt(navigator.appVersion) >= 4) { pWin.pWindopW.focus(); }
}

function pStrReplace(pBusca, pRepla, pOrig)
{
	pStr 	= new String(pOrig);
	rExp	= "/"+pBusca+"/g";
	rExp	= eval(rExp);
	newS	= String(pRepla);
	pStr = new String(pStr.pReplace(rExp, newS));
	return pStr;
}

function checkedFirst()
{
	var frm = document.getElementById('general');
	var cuenta_checks_forms		= 0;
	var cuenta_checks_marcados	= 0;
	
	for(var i=0;i<frm.elements.length;i++)
	{
		if(frm.elements[i].name!='chk_select_all' && frm.elements[i].id.substr(0,10)=='delete_id_' && frm.elements[i].type=='checkbox')
		{
			cuenta_checks_forms =  cuenta_checks_forms + 1;
		}
	}
	
	for(var i=0;i<frm.elements.length;i++)
	{
		if(frm.elements[i].checked && frm.elements[i].name!='chk_select_all' && frm.elements[i].id.substr(0,10)=='delete_id_' && frm.elements[i].type=='checkbox')
		{
			cuenta_checks_marcados = cuenta_checks_marcados + 1;
		}
	}
	
	if(cuenta_checks_forms==cuenta_checks_marcados)
	{
		frm.chk_select_all.checked=1;
	}
	else
	{
		frm.chk_select_all.checked=0;
	}
}

function selectRow(event,rowId,range)
{
	//alert(rowId);
	
    var rowOb = document.getElementById('row' + rowId);
    if (document.getElementById('delete_id_' + rowId)!=null)
    {
	var StateChk= document.getElementById('delete_id_' + rowId).checked;

    if (!rowOb) {
        return;
    }
    if(event=='click'){
    	if(StateChk==true){
    		rowOb.style.backgroundColor='#ffc'
    	}else{
    		rowOb.style.backgroundColor='#ffffff';
    	}
	if(range==1)
	{
    	checkedFirst();
	}
    }
    if(event=='out'){
    	if(StateChk==true){
    		rowOb.style.backgroundColor='#ffc'
    	}else{
    		rowOb.style.backgroundColor='#ffffff'
    	}
    }
    
    if(event=='over'){    
    	if(StateChk==true){
    		rowOb.style.backgroundColor='#ffc'
    	}else{
    	rowOb.style.backgroundColor='#f3f3f3'
    	}
    }
    }
}

var id_back='';
function selectRowRadio(event,rowId,range)
{   

	var rowOb = document.getElementById('row' + rowId);
	//alert(rowOb.id);
    var StateChk= document.getElementById('delete_id_' + rowId).checked;

//	alert(id_back);
    if (!rowOb) {
        return;
    }

    if(event=='click')
    {
    	if(id_back!='')
    	{
	    	if(rowId!=id_back)
	    	{
			    rowOb = document.getElementById('row' + id_back);
	    		rowOb.style.backgroundColor='#ffffff';
	    		rowOb = document.getElementById('row' + rowId);
	    		rowOb.style.backgroundColor='#ffc';
	    		

	    		id_back=rowId;
	    	}
	    	else
	    	{
	    		rowOb.style.backgroundColor='#ffc';
	    		id_back=rowId;
	    	}
    	}
    	else
    	{
    		document.getElementById('delete_id_' + rowId).checked=1;
    		rowOb.style.backgroundColor='#ffc';    		
	   		id_back=rowId;
    	}

//    	
//    	if(StateChk==true)
//    	{
//    	}
//    	
//    	if(rowId)
//    	
//    	else
//    	{
//    		rowOb.style.backgroundColor='#ffffff';
//    	}
//		
//    	if(range==1)
//		{
//	    	checkedFirst();
//		}
    }
    
    if(event=='out'){
    	if(StateChk==true){
    		rowOb.style.backgroundColor='#ffc'
    	}else{
    		rowOb.style.backgroundColor='#ffffff'
    	}
    }
    
    if(event=='over'){    
    	if(StateChk==true){
    		rowOb.style.backgroundColor='#ffc'
    	}else{
    		rowOb.style.backgroundColor='#f3f3f3'
    	}
    }
}

function checkColor(rowId)
{
    var rowOb = document.getElementById('row' + rowId);
    var StateChk= 1;
    if (!rowOb) {return;}
    if(StateChk==1){
		document.getElementById('delete_id_' + rowId).checked =1;
		rowOb.style.backgroundColor='#ffc'
	}else{
		document.getElementById('delete_id_' + rowId).checked =0;		
		rowOb.style.backgroundColor='#ffffff'
	}
}

function selectAllChecks()
{
	var frm = document.getElementById('general');
	for (i=0;i<frm.elements.length;i++) 
	{
		if (frm.elements[i].name!='select_all' && frm.elements[i].type=='checkbox')
		{
			if (frm.chk_select_all.checked==1)
			{		
				frm.elements[i].checked=1;
				rowId = frm.elements[i].value;
				if(rowId!='on') selectRow('click',rowId,0);
			}else{
				frm.elements[i].checked=0;
				rowId = frm.elements[i].value;				
				if(rowId!='on') selectRow('click',rowId,0);
			}
		}
	}
}

function validateFkc(pName)
{
	for ( i = 0; i < parent.frames.length; ++i ){
		if ( parent.frames[i].FCK ){
			parent.frames[i].FCK.UpdateLinkedField();
		}
	}
	
	if(document.getElementById(pName).value=='')
	{
		return 1;
	}	
	return 0;
}

function validateExts(pFileId, pExts)
{
	var file = document.getElementById(pFileId).value;
	extensiones_permitidas = pExts;
	mierror = "";
	extension = (file.substring(file.lastIndexOf("."))).toLowerCase();
	permitida = false;
	for (var i = 0; i < extensiones_permitidas.length; i++) 
	{
	    if (extensiones_permitidas[i] == extension) 
	    {
	        permitida = true;
	        break;
	    }
	}	
	return permitida;
}


var theObj="";
 
function toolTip(text,me) {
       theObj=me;
       theObj.onmousemove=updatePos;
       document.getElementById('toolTipBox').innerHTML=text;
       document.getElementById('toolTipBox').style.display="block";
       window.onscroll=updatePos;
}
function updatePos() {
       var ev=arguments[0]?arguments[0]:event;
       var x=ev.clientX;
       var y=ev.clientY;
       diffX=20;
       diffY=20;
       document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop+ "px";
       document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
       theObj.onmouseout=hideMe;
}
 
function hideMe() {
       document.getElementById('toolTipBox').style.display="none";
}

function checkConfirmPass(pPass1, pPass2)
{
	return (pPass1)==(pPass2)?1:0;
}

function displayOrder(pFieldOrder, pFieldOrderEdit, pUrl, pParams)
{
	orderCmb=document.getElementById(pFieldOrder);
	while(orderCmb.hasChildNodes())
	{
		orderCmb.removeChild(orderCmb.firstChild);
	}	
	myoption=document.createElement('option');
	myoption.value=0;
	myoption.innerHTML='Actualizando valores porfavor espere..';
	orderCmb.appendChild(myoption);
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
   	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   		xmlhttp = new XMLHttpRequest();
   	}
	try
	{
//		alert(pUrl)
//		
//		pUrl = '/payet/admin/index.php?/experiencias'
//		
	   	xmlhttp.open("POST", pUrl, true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	   	xmlhttp.send(pParams);
	   	xmlhttp.onreadystatechange=function() 
	   	{
			if (xmlhttp.readyState==4) 
			{
				forcheck = xmlhttp.responseText;
				orderCmb.removeChild(orderCmb.firstChild);

				if(parseInt(forcheck)==0)
				{
					forcheck=1;
				}

				if(pFieldOrderEdit=='')
				{
					forcheck++;
					editOrder = forcheck;
				}
				else
				{
					editOrder = document.getElementById(pFieldOrderEdit).value;
				}
				
				for(i=1;i<=parseInt(forcheck);i++)
				{
					myoption=document.createElement('option');
					myoption.value=i;
					myoption.innerHTML=i;
					
					if(editOrder!='')
					{
						if(i==editOrder)
						{
							myoption.selected=true;
						}
					}

					orderCmb.appendChild(myoption);
				}
			}
		}
	}
	catch(ee)
	{
	    alert(ee);
	}
}

function validateUrl(pId)
{
	var url = document.getElementById(pId).value;
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    return !v.test(url)?0:1;
}

function isAfterSecond(MyDate)
{
	theotherDate=document.getElementById("str_date_end").value;
	if(theotherDate!='')
	{
		theotherdatearray=theotherDate.split("/");
		if(theotherdatearray.length==3)
		{
			var MyEnd = new Date();
			year=theotherdatearray[2];
			month=theotherdatearray[1]-1;
			day=theotherdatearray[0];
			MyEnd.setYear(year);
			MyEnd.setMonth(month);
			MyEnd.setDate(day);
			MyEnd.setHours(0, 0, 0, 0);
			MyDate.setHours(0, 0, 0, 0);
			if (MyDate.getTime() > MyEnd.getTime() )
			{
		  		return true; 
			}else{
		  		return;
			}
		
		}
	}
}

function isBeforeFirst(MyDate)
{
	theotherDate=document.getElementById("str_date_start").value;
	if(theotherDate!='')
	{
		theotherdatearray=theotherDate.split("/");
		if(theotherdatearray.length==3)
		{
			var MyStart = new Date();
			year=theotherdatearray[2];
			month=theotherdatearray[1]-1;
			day=theotherdatearray[0];
			MyStart.setYear(year);
			MyStart.setMonth(month);
			MyStart.setDate(day);
			MyStart.setHours(0, 0, 0, 0);
			MyDate.setHours(0, 0, 0, 0);
			if (MyDate.getTime() <= MyStart.getTime() )
			{
				return true; 
			}else{
				return;
			}
		}
	}
}

function isBeforeNow(MyDate)
{
	MyStart=new Date();
	MyStart.setHours(0, 0, 0, 0);
	MyDate.setHours(0, 0, 0, 0);
	if (MyDate.getTime() <= MyStart.getTime() )
	{
		return true; 
	}else{
		return;
	}
}

function setLang(pLang, pUrl)
{
	document.getElementById('lang').value = pLang;
	document.getElementById('general').action = pUrl;
	document.getElementById('general').submit();
}

function showDetail(pUrl)
{
	document.getElementById('general').action = pUrl;
	document.getElementById('general').submit();
}

function goPostUrl(pUrl)
{
	document.getElementById('general').action = pUrl;
	document.getElementById('general').submit();	
}

function mReturn(pUrl)
{
	document.getElementById('general').action = pUrl;
	document.getElementById('general').submit();	
}

function mOlnlyAlnumhyphen(objValue)
{
	var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
	return charpos>=0?1:0;
}

function goGetSearch(pUlr)
{
	var txt_search = escape(document.getElementById('txt_buscar').value);
	window.location.href = pUlr+'/'+txt_search;
}

/* vm funciones */
function limpiarBusqueda(obj) {
	obj.value='';
}

function defBusqueda(obj) {
	if (trim(obj.value)=='') { obj.value='inicie su búsqueda'; }
}

function popupsc(loc, name, width, height) {
	var _params = "width="+width+",height="+height+",resizable=no,status=no,scrollbars=no";

	// CENTER ON BROWSERS WHICH SUPPORT JSCRIPT 1.2
	if (bVer >= 4) {
		 _left = ( (screen.width-width) >>1 );
		 _top = ( (screen.height-height) >>1 );
	} else {
		 _left = ( (800-width) >>1 );
		 _top = ( (600-height) >>1 );
	}

	if (IE) _params += ",top=" + _top + ",left=" + _left;
	else if (NS) _params += ",screenX=" + _left + ",screenY=" + _top;

	newWin = window.open(loc, name, _params);
	if ( newWin!=null && !(IE && bVer<5) )
		newWin.focus(); // MSIE4 DOESN'T FOCUS WINDOWS
}

function strip_tags(str, allowed_tags) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i>,<b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    
    var key = '', tag = '';
    var matches = allowed_array = [];
    var allowed_keys = {};
    
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_tags  = allowed_tags.replace(/[\<\> ]+/g, '');;
        allowed_array = allowed_tags.split(',');
        
        for (key in allowed_array) {
            tag = allowed_array[key];
            allowed_keys['<' + tag + '>']   = true;
            allowed_keys['<' + tag + ' />'] = true;
            allowed_keys['</' + tag + '>']  = true;
        }
    }
    
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
    
    // Is tag not in allowed list? Remove from str! 
    for (key in matches) {
        tag = matches[key].toString();
        if (!allowed_keys[tag]) {
            reg = RegExp(tag, 'g');
            str = str.replace(reg, '');
        }
    }
    
    return str;
}