// JavaScript Document
function ShowHide(id) {
    if(document.getElementById(id).className != "oculta"){
        document.getElementById(id).className = "oculta";
    } else {
        document.getElementById(id).className = "muestra";
    }
}

function Hide(id) {  
        document.getElementById(id).className = "oculta";    
}
function Show(id) {  
        document.getElementById(id).className = "muestra";    
}
function pop_open(object,title,message,type,qs,divhtml,formu,file){
	var url_pp = object+"?"+qs+'&type='+type;
  jQuery.prettyPhoto.open(url_pp,title,message,divhtml,formu,file);	

}
function valida_portfolio(TheForm){	
	var error=0;
	if ($('name').value.length==0){Show('err_name'); error=1;} 
	if ($('details').value.length==0){ Show('err_details');  error=1; } 
	
	if(error==1) {	return false;	}
	if(error==0){	TheForm.submit;	return true;	}	
}
function valida_customers(TheForm){	
	var error=0;
	if ($('name').value.length==0){Show('err_name'); error=1;} 
	if ($('info').value.length==0){ Show('err_info');  error=1; } 
	
	if(error==1) {	return false;	}
	if(error==0){	pop_open('changes.php','Modulo de clientes','Cambios Realizados Con Exito','answer','ajax=true&width=400&height=160','answer','customers','changes.php');	}	
}
function valida_news(TheForm){	
	var error=0;
	if ($('title').value.length==0){Show('err_title'); error=1;} 
	if ($('details').value.length==0){ Show('err_details');  error=1; }  
	if ($('body').value.length==0){ Show('err_body');  error=1; }
	
	if(error==1) {	return false;	}
	if(error==0){	TheForm.submit;	return true;	}	
}
function valida_content(TheForm){	
	var error=0;
	if ($('title').value.length==0){Show('err_title'); error=1;} 
	if ($('details').value.length==0){ Show('err_details');  error=1; }  
	if ($('body').value.length==0){ Show('err_body');  error=1; }
	
	if(error==1) {	return false;	}
	if(error==0){	TheForm.submit;	return true;	}	
}
function carga_contenido(div,str)
{ 
  var url=str; 
  new Ajax.Updater(div, url);
}
function Muestracalendar(NombreInput,NomrbeImagen)
{	  
		  function updateFields(cal) {
              var date = cal.selection.get();
              if (date) {
                      date = Calendar.intToDate(date);
                      document.getElementById(NombreInput).value = Calendar.printDate(date, "%Y-%m-%d");
              }
             
      	  };
		Calendar.setup({
				
        trigger    : NomrbeImagen,
        inputField : NombreInput,
		animation : true,
		onSelect     : updateFields	,
        onTimeChange : updateFields
    });
}
function ValidaContact(TheForm){	
	var error=0;
	if ($('c_name').value.length==0){Show('errc_name'); error=1;} 
	if ($('c_profession').value.length==0){ Show('errc_profession');  error=1; } 
	if ($('c_job_title').value.length==0){Show('errc_job');error=1; } 
	if ($('c_company').value.length==0){Show('errc_company');error=1; } 
	if ($('c_email').value.length==0){Show('errc_email');error=1; } 
	if ($('comments').value.length==0){Show('errcomments');error=1; } 
	
	if(error==1) {	return false;	}
	if(error==0){	TheForm.submit;	return true;	}	
}
function ValidaNwslttr(TheForm){	
	var error=0;
	if ($('n_name').value.length==0){error=1;} 
	if ($('n_company').value.length==0){error=1; } 
	if ($('n_email').value.length==0){error=1; } 
	
	if(error==1) {alert('Datos Insuficientes!');return false;	}
	if(error==0){TheForm.submit;return true;	}	
}
//coloca texto previo en el input 
function PlaceHolderBlur(input,text){
	if($(input).value==''){ $(input).value=text};
}
//coloca texto previo en el input 
function PlaceHolderFocus(input,text){
	if($(input).value==text){$(input).value='';}
}
function EnviaPost(divHtml,linkCompleto,Formulario)
{
	var Envia = "";
	for (var i = 0 ;i < document[Formulario].elements.length; i++)	{
		var Campo = document[Formulario].elements[i];
		if(Campo.type == 'checkbox'){
			//Envia += Campo.name+'='+Campo.checked+'&';
			if(Campo.checked){
				Envia += Campo.name+'='+Campo.name+'&';
			}
		}
		else if(Campo.type == 'radio'){
			if(Campo.checked){
				Envia += Campo.name+'='+Campo.value+'&';
			}
		}
		else{
			Envia += Campo.name+'='+Campo.value+'&';
		}
	}
	var postData = str_replace('?', "|*", Envia);
	
	new Ajax.Updater(divHtml,linkCompleto,{ method:'post' , parameters: postData , onFailure: regresoError});
}
function str_replace(search, replace, subject) {

    // Replace all occurrences of the search string with the replacement string

    // 

    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_str_replace/

    // +       version: 805.3114

    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

    // +   improved by: Gabriel Paderni

    // +   improved by: Philip Peterson

    // +   improved by: Simon Willison (http://simonwillison.net)

    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)

    // -    depends on: is_array

    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');

    // *     returns 1: 'Kevin.van.Zonneveld'

    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');

    // *     returns 2: 'hemmo, mars'    

    

    var f = search, r = replace, s = subject;
    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
	while (j = 0, i--) {

        while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};

    };
	return sa ? s : s[0];

}
function is_array( mixed_var ) {

    // Finds whether a variable is an array

    // 

    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_array/

    // +       version: 804.1712

    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

    // +   improved by: Legaev Andrey

    // +   bugfixed by: Cord

    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);

    // *     returns 1: true

    // *     example 2: is_array('Kevin van Zonneveld');

    // *     returns 2: false
    return ( mixed_var instanceof Array );
}
function regresoError(){

alert("Error: No se pudo cargar la página");

}
