var w = screen.width;
var h = screen.height;
var title = "";
var link = "";

function initBookmark() {
	title = document.title;
	link = document.URL;
}

function phpOnlineBookmarkingClass(url){
	link = encodeURIComponent(link);	
	title = encodeURIComponent(title);
	var url = url.replace('{PERMALINK}', link);
	var url = url.replace('{TITLE}', title);
	openWindow(url);
}

function openWindow(url)  {
   window.open(url, 'PhpOnlineBookmarkingClass', 'width=' + w + ', height=' + h + ', menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes');
}

function load(module,taskValue)
{
	if(document.forms[0].bsq_buscar)
	{
		document.forms[0].bsq_buscar.value='';
	}
	document.forms[0].action=module;
	document.forms[0].task.value=taskValue;
	document.forms[0].target='_self';	
	document.forms[0].submit();
}

function goPagina(pagIr)
{
	document.forms[0].pag_pagIr.value=pagIr;
	document.forms[0].task.value='mList';
	document.forms[0].target='_self';	
	document.forms[0].submit();	
}

function delete_element()
{
	verf='';
	for (i=0;i<document.forms[0].elements.length;i++)
	{
		if (document.forms[0].elements[i].checked && document.forms[0].elements[i].type == 'checkbox') {
			verf='OK';
		}
	}
	if (verf=='')
	{
		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.forms[0].task.value='mDelete';
				document.forms[0].target='_self';				
				document.forms[0].submit();	
			}
		}
	}
}

function new_element()
{
	document.forms[0].task.value='mNew';
	document.forms[0].target='_self';	
	document.forms[0].submit();	
}

function save_element()
{
	if(hay_caracter())
	{
		document.forms[0].task.value='mSave';
		document.forms[0].target='_self';
		document.forms[0].submit();	
	}
}

function export_element()
{
	document.forms[0].task.value = 'mExport';
	document.forms[0].target = '_self';
	document.forms[0].submit();	
}


function edit_elemento(codigo)
{
	document.forms[0].cod_elemento.value=codigo;
	document.forms[0].task.value='mEdit';
	document.forms[0].target='_self';	
	document.forms[0].submit();	
}

function update_element()
{
	if(hay_caracter())
	{
		document.forms[0].task.value='mUpdate';
		document.forms[0].target='_self';		
		document.forms[0].submit();	
	}
}


function cancel()
{
	document.forms[0].task.value='mList';
	document.forms[0].target='_self';	
	document.forms[0].submit();	
}

function only_num(nombre)
{
	regexp=/^[0-9]+\.?[0-9]*$/
	//try to deprecate the use of getElementById and upgrade to the use of the object instead
	if((typeof nombre)=='object')
	{
		elemento=nombre;
	}else{
		elemento=document.getElementById(nombre);
	}
	if (elemento.value.match(regexp)==null)
	{
		elemento.value=elemento.value.substr(0,elemento.value.length-1);
	}
}

function verf_mail(nombre)
{
	var regEmail = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;
	Email=document.getElementById(nombre).value;
	if(Email!='')
	{
		if(!(regEmail.test (Email)))
		{
			alert('Ingrese un Email Valido Porfavor');
			document.getElementById(nombre).focus();
		}
	}
}

function checkPass(input1,input2)
{
	if(document.getElementById(input1).value==document.getElementById(input2).value)
	{
		return true;
	}else{
		document.getElementById(input1).focus();
		return false;
	}
}

function go_main()
{
	document.forms[0].action='home';
	document.forms[0].target='_self';
	document.forms[0].submit();
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

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;
}

function goSubmit()
{
	document.forms[0].target='_self';
	document.forms[0].submit();
}

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

function onSearch(obj)
{
	obj.value='';
	obj.focus();
}

function mSearch(pUrl)
{
	document.forms[0].action = pUrl;
	goSubmit();
}

function goWorkWithUs(pUrl)
{
	document.forms[0].action = pUrl;
	goSubmit();	
}

function vSearch(pUrl, e) 
{
	document.forms[0].action = pUrl;
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla == 13) {
		goSubmit();
	}
}