// -----------------------------------------------------------------------
// Common functions
// -----------------------------------------------------------------------
var saveWidth = 0;
var wholemessage='';
var swidth=430;
var sheight=60;
var sbcolor="#355056"
var sspeed=1;
var srcolor="#CCFF00";
var resumesspeed=sspeed;
var primerslap=false;
var segundoslap=false;
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
function fnOver(strIdTd) {
	document.getElementById(strIdTd).background = "img/fondo_over_botonera.gif";
	return(true);
}
// -----------------------------------------------------------------------
function fnOut(strIdTd) {
	document.getElementById(strIdTd).background = "img/blank.gif";
	return(true);
}
// -----------------------------------------------------------------------
function scaleImg(what,maxW){
	//what = document.getElementById(what);


	if (document.body) {
		winW = (document.body.clientWidth);
		winH = (document.body.clientHeight);
	} else {
		winW = (window.innerWidth);
		winH = (window.innerHeight);
	}


	//if ( navigator.appName == "Netscape" ) {
	//	winW = window.innerWidth;
	//	winH = window.innerHeight;
	//}
	//if ( navigator.appName.indexOf("Microsoft") != -1 ) {
	//	winW = document.body.offsetWidth;
	//}

	if (maxW != 0){
		winW = maxW;
	} else {
		if ( what.height > winH){
			//winW = winH * what.width / what.height;
			winW = (winH * what.width / what.height)+80;

		}
	}

	if ( what.width > (winW-100) || saveWidth >(winW-100) ) {
		if ( what.width == (winW-100) ){
			what.width = saveWidth;
		} else {
			saveWidth = what.width;
			//what.style.cursor = "pointer";
			what.width = (winW-100);
		}
	}


}
// -----------------------------------------------------------------------
function newwindow(url,width,height,status,resize) {
	if (resize==''){
		resize='no';
	} else {
		resize='yes';
	}
	if (status==''){
		status='no';
	} else {
		status='yes';
	}
	win1=window.open(url,"","width=" + width + ", height=" + height + ", status=" + status + ", resizable=" + resize + ', scrollbars=yes');
}
// -----------------------------------------------------------------------
function roundNum(amount){  
	var s = "";
	var decimal;  
	amount = parseFloat(amount);  
	if (!(isNaN(amount))) {
		amount = Math.round(amount * 100);
		amount = amount / 100;
		s = new String(amount);
		decimal = s.indexOf(".");    
		if (decimal == -1) {      
			// whole number
			s+= ".00";    
		} else {      
			if (decimal == (s.length - 2)) {
				s+= "0";      
			}    
		}  
	} else {
		s = "0.00";  
	}  
	return s;
}
// -----------------------------------------------------------------------
function SS_start(){
	if (document.all) {
		iemarquee(slider);
	}else if(document.getElementById){
		ns6marquee(document.getElementById('slider'));
	}else if(document.layers){
		ns4marquee(document.slider1.document.slider2);
	}
}
// -----------------------------------------------------------------------
function iemarquee(whichdiv){
	iediv=eval(whichdiv);
	iediv.innerHTML=wholemessage; 
	iediv.style.pixelTop=sheight;
	sizeup=iediv.offsetHeight;
	ieslide();
}
// -----------------------------------------------------------------------
function ieslide(){
	if (iediv.style.pixelTop>=sizeup*(-1)){
		iediv.style.pixelTop-=sspeed;
		setTimeout("ieslide()",100);
	}else{
		iediv.style.pixelTop=sheight;
		ieslide();
	}
}
// -----------------------------------------------------------------------
function ns4marquee(whichlayer){
	ns4layer=eval(whichlayer);
	ns4layer.document.write(wholemessage);
	ns4layer.document.close();
	sizeup=ns4layer.document.height;
	ns4layer.top-=sizeup;
	ns4slide();
}
// -----------------------------------------------------------------------
function ns4slide(){
	if (ns4layer.top>=sizeup*(-1)){
		ns4layer.top-=sspeed;
		setTimeout("ns4slide()",100);
	}else{
		ns4layer.top=sheight;
		ns4slide();
	}
}
// -----------------------------------------------------------------------
function ns6marquee(whichdiv){
	ns6div=eval(whichdiv);
	ns6div.innerHTML=wholemessage;
	ns6div.style.top=sheight;
	sizeup=ns6div.offsetHeight;
	ns6slide();
}
// -----------------------------------------------------------------------
function ns6slide(){
	if (parseInt(ns6div.style.top)>=sizeup*(-1)){
		ns6div.style.top=parseInt(ns6div.style.top)-sspeed;
		setTimeout("ns6slide()",100);
	}else{
		ns6div.style.top=sheight;
		ns6slide();
	}
}
// -----------------------------------------------------------------------
function AmpliarImagen(strDIMGGRAN) {
	var altoPantalla = window.screen.height;
	var anchoPantalla = window.screen.width;
	var sPropsVentana;
	var left = (anchoPantalla / 2) - (500 / 2);
	var top = (altoPantalla / 2) - (600 / 2);
	sPropsVentana  = 'width=600,height=525';
	sPropsVentana += ',top=' + top + ',left=' + left;
	sPropsVentana += ',scrollbars=no,resizable=no';
	var imagepath="" + escape(strDIMGGRAN);
	var url = "view_image.php?simagen=" + imagepath ;
	window.open( url , 'imagen',sPropsVentana);
}
//------------------------------------------------------------
function Votar(encuesta,urlvoto){
	if ( encuesta != ''){
		url = "votar.php" + urlvoto + "&enc=" + encuesta;
		mywin = winaux(url,"votacion",430,340,"yes","yes","no","no","no",1);	
	}
}
//------------------------------------------------------------
function winaux(u,n,w,h,rs,sb,mb,tb,st,x) {
	var remote = null;
	var altoPantalla = window.screen.height;
	var anchoPantalla = window.screen.width;
	var left = (anchoPantalla / 2) - (w / 2);
	var top = (altoPantalla / 2) - (h / 2);
	if (rs == '' || rs == null || rs != 'yes'){ rs = 'no'; }
	if (sb == '' || sb == null || sb != 'yes'){ sb = 'no'; }
	if (mb == '' || mb == null || mb != 'yes'){ mb = 'no'; }
	if (tb == '' || tb == null || tb != 'yes'){ tb = 'no'; }
	var args = 'width='+w+',height='+h+',top='+top+',left='+left+',resizable='+rs+',scrollbars='+sb+',menubar='+mb+',toolbar='+tb+',status=no,location=no,directories=no';
	remote = window.open(u,n,args);
	if (remote != null) {
		if (remote.opener == null)
			remote.opener = self;
	}
	if (x == 1) { return remote; }
}
//------------------------------------------------------------
function First_Field_Focus(){
	var bFound = false; 
	for (f=0; f < document.forms.length; f++){ 
		for(i=0; i < document.forms[f].length; i++){ 
			if (document.forms[f][i].type != "hidden"){ 
				if (document.forms[f][i].disabled != true) { 
					document.forms[f][i].focus(); 
					var bFound = true; 
				} 
			} 
			if (bFound == true){ 
				break; 
			} 
		} 
		if (bFound == true){ 
			break; 
		} 
	} 
} 
//------------------------------------------------------------
function AddMod(col,coli,hcampo,formul) {

	if (formul[coli].selectedIndex > -1) { 
		sli = formul[coli].selectedIndex; 
		sl = formul[col].length ; 
		if (formul[coli].options[sli].value >"") { 
	   	doSub(hcampo,formul); 
			oText = formul[coli].options[sli].text; 
			oValue = formul[coli].options[sli].value; 
			var optionObj = new Option(oText, oValue, false, true); 
			formul[coli].options[sli] = null; 
			formul[col].options[sl] = optionObj; 
			doSub(hcampo,formul); 
		} 
	} 
} 
//------------------------------------------------------------
function makeList(col,formul) { 
	val = ""; 
	for (j=0; j<formul[col].length; j++) { 
		if (val > "") { 
			val += "~"; 
		} 
		if (formul[col].options[j].value > "") val += formul[col].options[j].value; 
	} 
	return val; 
} 
//------------------------------------------------------------
function doSub(hcampo,formul) { 
	col = hcampo; 
	formul[hcampo+'_lst'].value = makeList(col,formul); 
	return true; 
} 
//------------------------------------------------------------
function hide(whichLayer) { 
	if (document.getElementById) { 
		document.getElementById(whichLayer).style.visibility = "hidden"; 
	} else if (document.all) { 
		document.all[whichlayer].style.visibility = "hidden"; 
	} else if (document.layers) { 
		document.layers[whichLayer].visibility = "hidden"; 
	} 
} 
//------------------------------------------------------------
function show(whichLayer) { 
	if (document.getElementById) { 
		document.getElementById(whichLayer).style.visibility = "visible"; 
	} else if (document.all) { 
		document.all[whichlayer].style.visibility = "visible"; 
	}	else if (document.layers) { 
		document.layers[whichLayer].visibility = "visible"; 
	} 
} 
//------------------------------------------------------------
function DaysInMonth(WhichMonth, WhichYear){ 
	var DaysInMonth = 31; 
	if (WhichMonth == "4" || WhichMonth == "5" || WhichMonth == "9" || WhichMonth == "11") DaysInMonth = 30; 
	if (WhichMonth == "2" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28; 
	if (WhichMonth == "2" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29; 
	return DaysInMonth; 
} 
//------------------------------------------------------------
function ShowCalendar(campo_form){ 
	var ranNum= Math.floor(Math.random()*5); 
	var altoPantalla = window.screen.height; 
	var anchoPantalla = window.screen.width; 
	var sPropsVentana; 
	var height = "200"; 
	var width = "200"; 
	var left = (anchoPantalla / 2) - (width / 2); 
	var top = (altoPantalla / 2) - (height / 2); 
	sPropsVentana  = 'width=' + width + ',height=' + height; 
	sPropsVentana += ',top=' + top + ',left=' + left; 
	sPropsVentana += ', status=no,resizable=no,scrollbars=no'; 
	url = "popcalendar.php?campo=" + campo_form; 
	calendario=window.open( url , "cal_" + ranNum + "_ar" , sPropsVentana); 
} 
//------------------------------------------------------------
function IsNumeric(valor){ 
	var log=valor.length; var sw="S"; 
	for (x=0; x<log; x++){ 
		v1=valor.substr(x,1); 
		v2 = parseInt(v1); 
	// --------------------------------- 
	//	Compruebo si es un valor numérico 
	// --------------------------------- 
	if (isNaN(v2)){sw= "N";} 
	} 
	if (sw=="S") {return true;} else {return false; } 
	} 
	 
	var primerslap=false; 
	var segundoslap=false; 
//------------------------------------------------------------
function formateahora(fecha){ 
	var long = fecha.length; 
	var hora; 
	var minuto; 
	 
	if ((long>=2) && (primerslap==false)) { hora=fecha.substr(0,2); 
	if ((IsNumeric(hora)==true) && (hora<=24)) { fecha=fecha.substr(0,2)+":"+fecha.substr(3,5); primerslap=true; } 
	else { fecha=""; primerslap=false;} 
	} 
	else 
	{ dia=fecha.substr(0,1); 
	if (IsNumeric(dia)==false) 
	{fecha="";} 
	if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; } 
	} 
	if ((long>=5) && (segundoslap==false)) 
	{ minuto=fecha.substr(3,2); 
	if ((IsNumeric(minuto)==true) &&(minuto<=59)) { fecha=fecha.substr(0,5); segundoslap=true; } 
	else { fecha=fecha.substr(0,3);; segundoslap=false;} 
	} 
	else { if ((long<=5) && (segundoslap=true)) { fecha=fecha.substr(0,4); segundoslap=false; } } 
	 
	return (fecha); 
} 
//------------------------------------------------------------
function formateafecha(fecha) {
	var long = fecha.length;
	var dia;
	var mes;
	var ano;
	var separator="/"

	if ((long>=2) && (primerslap==false)) { 
		dia=fecha.substr(0,2);
		if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { 
			fecha=fecha.substr(0,2)+ separator +fecha.substr(3,7); 
			primerslap=true; 
		} else { 
			fecha=""; 
			primerslap=false;
		}
	} else { 
		dia=fecha.substr(0,1);
		if (IsNumeric(dia)==false){
			fecha="";
		}
		if ((long<=2) && (primerslap=true)) {
			fecha=fecha.substr(0,1); 
			primerslap=false; 
		}
	}
	if ((long>=5) && (segundoslap==false)) { 
		mes=fecha.substr(3,2);
		if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { 
			fecha=fecha.substr(0,5)+separator+fecha.substr(6,4); 
			segundoslap=true; 
		} else { 
			fecha=fecha.substr(0,3);
			segundoslap=false;
		}
	} else { 
		if ((long<=5) && (segundoslap=true)) { 
			fecha=fecha.substr(0,4); 
			segundoslap=false; 
		} 
	}
	if (long>=7) { 
		ano=fecha.substr(6,4);
		if (IsNumeric(ano)==false) { 
			fecha=fecha.substr(0,6); 
		} else { 
			if (long==10){ 
				if ((ano==0) || (ano<1900) || (ano>2100)) { 
					fecha=fecha.substr(0,6); 
				} 
			} 
		}
	}
	if (long>=10) {
		fecha=fecha.substr(0,10);
		dia=fecha.substr(0,2);
		mes=fecha.substr(3,2);
		ano=fecha.substr(6,4);
		// Anioo no viciesto y es febrero y el dia es mayor a 28
		if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { 
			fecha=fecha.substr(0,2)+separator; 
		}
	}
	return (fecha);
}
//------------------------------------------------------------
function winaux2(u,n,w,h,rs,sb,mb,tb,st,x,t,l) {
	var remote = null;
	var altoPantalla = window.screen.height;
	var anchoPantalla = window.screen.width;
	var top = (altoPantalla / 2) - (h / 2);
	var left = (anchoPantalla / 2) - (w / 2);
	if (t != '' || t != null ){ 
		top = t;
	}
	if (l != '' || l != null ){ 
		left = l;
	}
	if (rs == '' || rs == null || rs != 'yes'){ rs = 'no'; }
	if (sb == '' || sb == null || sb != 'yes'){ sb = 'no'; }
	if (mb == '' || mb == null || mb != 'yes'){ mb = 'no'; }
	if (tb == '' || tb == null || tb != 'yes'){ tb = 'no'; }
	var args = 'width='+w+',height='+h+',top='+top+',left='+left+',resizable='+rs+',scrollbars='+sb+',menubar='+mb+',toolbar='+tb+',status=no,location=no,directories=no';
	remote = window.open(u,n,args);
	if (remote != null) {
		if (remote.opener == null)
			remote.opener = self;
	}
	if (x == 1) { return remote; }
}
//------------------------------------------------------------
function ViewSocio(socio){
	if ( socio != ''){
		url = "viewsocio.php?socio_id=" + socio;
		mywin = winaux2(url,"socio",520,725,"yes","yes","no","no","no",1,0,0);	
	}
}
//------------------------------------------------------------
function ViewJob(job){
	if ( job != ''){
		url = "viewjob.php?job_id=" + job;
		mywin = winaux2(url,"jobs",590,630,"yes","yes","no","no","no",1,0,0);	
	}
}
//------------------------------------------------------------
//------------------------------------------------------------
function onfocus_input(o){
	if(o.value==o.title){
		o.value='';
	}
}
//------------------------------------------------------------
function onblur_input(o){
	if(o.value==o.title || o.value==''){
		o.value = o.title;
	}
}
//------------------------------------------------------------
function onfocus_pass(o){
	if(o.value==o.title){
		changeInputType(o,"password",o.title,true,false)		
	}
}
//------------------------------------------------------------
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
 
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.title) newElm.title = oldElm.title;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;

}
//------------------------------------------------------------  
