// JavaScript Document
function chr(c) {
	var h = c . toString (16);
	h = unescape ('%'+h);
	return h;
}

function extension(str_filename){
	var i = str_filename.length;
	var slicer = String(slicer)
	var ext = String('')
	do{ 
		slicer = str_filename.slice(i-1,i);
		ext = slicer+ext
		i--
	} 
	while(slicer != '.' && i > 1)
	
	ext = ext.toLowerCase();
	return(ext);
}

//funcion encargada de crear el objeto
 function obj_ajax() {         
	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(); }
  return xmlhttp
 }

function addFileInput( elem ) {
		if ( false != elem )
		{
			filepath = elem.value.split("\\");
			filename = filepath[filepath.length-1];
			extensionpath = filename.split(".");
			extension = extensionpath[extensionpath.length-1];
		 	if( !extension.match(/(jpg)|(jpeg)|(gif)|(png)/) )
			{
				alert ( "Sólo se permite subir imágenes: jpg, gif y png" );
				return false;
			}
			$(elem).hide();
			$("#file_list").append("<li style='display:none'>&bull; "+filename+" <a href='javascript:;' onclick='delFile(this,"+($("#file_list li").size()+1)+")' style='color:red'>[x]</small></a></li>\n");
			$("#file_list li:last").slideDown("slow");
		}
		$("#Submit").get(0).disabled = false;
		$("#file_inputs").append('<input name="file'+($("#file_list li").size()+1)+'" type="file" id="file'+($("#file_list li").size()+1)+'" size="35" onChange="addFileInput(this);"  class="input">\n');

}

function delFile ( el, file )
{
	$(el.parentNode).remove();
	$("#file"+file).remove();
}

function Resize(){
try{

    var frameWidth;
    var frameHeight;
    var obj;

    if (self.innerWidth){
      frameWidth = self.innerWidth;
      frameHeight = self.innerHeight;
    }else if (document.documentElement && document.documentElement.clientWidth){
      frameWidth = document.documentElement.clientWidth;
      frameHeight = document.documentElement.clientHeight;
    }else if (document.body){
      frameWidth = document.body.clientWidth;
      frameHeight = document.body.clientHeight;
    }else{
      return;
    }

    obj=document.getElementById("background_image");
    if ((obj)){
      // reset to default position on resize/load
      obj.style.top = obj.style.left = 0;
      var ratio = 1140/600;
      var ratio_width = frameHeight * ratio;
      if (ratio_width < frameWidth){
      }
      obj.style.height = frameHeight.toString() + "px";
      obj.style.width = ratio_width.toString() + "px";
	  
	  //calculo el espacio para centrar la caja
	  obj=document.getElementById("centrador");
	  espacio_left=(frameWidth-680)/2;
	  obj.style.width = espacio_left.toString() + "px";
	  $('centrador').show();
      $('background_image').show();
    }
    
    }catch (e){
    }
}

function Resize_intro(){
try{

    var frameWidth;
    var frameHeight;
    var obj;

    if (self.innerWidth){
      frameWidth = self.innerWidth;
      frameHeight = self.innerHeight;
    }else if (document.documentElement && document.documentElement.clientWidth){
      frameWidth = document.documentElement.clientWidth;
      frameHeight = document.documentElement.clientHeight;
    }else if (document.body){
      frameWidth = document.body.clientWidth;
      frameHeight = document.body.clientHeight;
    }else{
      return;
    }
	
    obj=document.getElementById("miFlash");
    if ((obj)){
      // reset to default position on resize/load
      obj.style.top = obj.style.left = 0;
      var ratio = 1140/600;
      var ratio_width = frameHeight * ratio;
      if (ratio_width < frameWidth){
      }
    obj.style.height = frameHeight.toString() + "px";
    obj.style.width = frameWidth.toString() + "px";
	}
    
    }catch (e){
    }
}

function Resize_proyectos(){
try{

    var frameWidth;
    var frameHeight;
    var obj;

    if (self.innerWidth){
      frameWidth = self.innerWidth;
      frameHeight = self.innerHeight;
    }else if (document.documentElement && document.documentElement.clientWidth){
      frameWidth = document.documentElement.clientWidth;
      frameHeight = document.documentElement.clientHeight;
    }else if (document.body){
      frameWidth = document.body.clientWidth;
      frameHeight = document.body.clientHeight;
    }else{
      return;
    }

   /* obj=document.getElementById("background_image");
    if ((obj)){
      // reset to default position on resize/load
      obj.style.top = obj.style.left = 0;
      var ratio = 1140/600;
      var ratio_width = frameHeight * ratio;
      if (ratio_width < frameWidth){
      }
      obj.style.height = frameHeight.toString() + "px";
      obj.style.width = ratio_width.toString() + "px";*/
	  
	  //calculo el espacio para centrar la caja
	  obj=document.getElementById("centrador");
	  espacio_left=(frameWidth-680)/2;
	  obj.style.width = espacio_left.toString() + "px";
	  
	  $('centrador').show();
      $('background_image').show();
    //}
    
    }catch (e){
    }
}

function ResetForm(which){
var pass=true
var first=-1
if (document.images){
	for (i=0;i<document.getElementById(which).length;i++){
		var tempobj=document.getElementById(which).elements[i]
		 if (tempobj.type=="text"){
			  eval(tempobj.value="")
			  if (first==-1) {first=i}
		 }
		 else 
		 	if (tempobj.type=="checkbox") {
		  		eval(tempobj.checked=0)
		  		if (first==-1) {first=i}
		 }
		 else if (tempobj.col!="") {
		  	eval(tempobj.value="")
		 	 if (first==-1) {first=i}
		 }
	}
}
document.getElementById(which).elements[first].focus()
return;
}

/*-------------------------------------------------------------------
| LTrim(s)
| Devuelve una cadena sin los espacios del principio
| 
|       12/09/2002 			Por El KuNi
-------------------------------------------------------------------*/
function LTrim(s){
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(j, s.length);
}

/*-------------------------------------------------------------------
| RTrim(s)
| Quita los espacios en blanco del final de la cadena
| 
|       12/09/2002 			Por El KuNi
-------------------------------------------------------------------*/
function RTrim(s){
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}

/*-------------------------------------------------------------------
| Trim(s)
| Quita los espacios del principio y del final
| 
|       12/09/2002 			Por El KuNi
-------------------------------------------------------------------*/
function Trim(s){
	return LTrim(RTrim(s));
}

/*-------------------------------------------------------------------
| UCase(s)
| Devuelve la cadena convertida a mayúsculas
| 
|       12/09/2002 			Por El KuNi
-------------------------------------------------------------------*/
function UCase(s){
	return s.toUpperCase();
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
