// JScript source code
// Replaces all instances of the given substring.
String.prototype.replaceAll = function( 
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
var strText = this;
var intIndexOfMatch = strText.indexOf( strTarget );
 

// Keep looping while an instance of the target string
// still exists in the string.
while (intIndexOfMatch != -1){
// Relace out the current instance.
strText = strText.replace( strTarget, strSubString )
 

// Get the index of any next matching substring.
intIndexOfMatch = strText.indexOf( strTarget );
}
 

// Return the updated string with ALL the target strings
// replaced out with the new substring.
return( strText );
}
/* GRAL. AJAX OBJECT *****************************************************************************************************************************************************/
	var xmlHttp;
    var requestURL = 'http://localhost/misctest/getusernames.aspx?q=';
    var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
    var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
    var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
    //netscape, safari, mozilla behave the same???
    var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;
    function GetXmlHttpObject(handler) {
        var objXmlHttp = null;    //Holds the local xmlHTTP object instance
        //Depending on the browser, try to create the xmlHttp object
        if (is_ie){
            //The object to create depends on version of IE
            //If it isn't ie5, then default to the Msxml2.XMLHTTP object
            var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';            
            //Attempt to create the object
            try{objXmlHttp = new ActiveXObject(strObjName);
                objXmlHttp.onreadystatechange = handler;
            }
            catch(e){//Object creation errored
                alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
                return;
            }
        }
        else if (is_opera){//Opera has some issues with xmlHttp object functionality
            alert('Opera detected. The page may not behave as expected.');
            return;
        }
        else{// Mozilla | Netscape | Safari
            objXmlHttp = new XMLHttpRequest();
            objXmlHttp.onload = handler;
            objXmlHttp.onerror = handler;
        }        
        //Return the instantiated object
        return objXmlHttp;
    }    
    // XMLHttp send GET request
    function xmlHttp_Get(xmlhttp, url) {
        xmlhttp.open('GET', url, true);
        xmlhttp.send(null);}
	// XMLHttp send POST request 
	function xmlHttp_Post(xmlhttp, url, params) { 
		xmlhttp.open('POST', url, true); 
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')   			
		xmlhttp.send(params);} 

	var divOut
    function perfomAjax(url,salida){
		divOut = salida
        if (url.length > 0){
            xmlHttp = GetXmlHttpObject(sCh_ListNames);            
            xmlHttp_Get(xmlHttp, url);
        }
        else {document.getElementById(divOut).innerHTML = '';}
    }
	
	function perfomAjax2(url,salida){
		divOut = salida
        if (url.length > 0){
            xmlHttp = GetXmlHttpObject(sCh_ListNames2);            
            xmlHttp_Get(xmlHttp, url);
        }
        else {document.getElementById(divOut).innerHTML = '';}
    }

    function sCh_ListNames()
    {	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
            var str = xmlHttp.responseText;			
            document.getElementById(divOut).innerHTML = str.replaceAll('&lt;','<').replaceAll('&gt;','>');
        }
		else{
			document.getElementById(divOut).innerHTML = '<br><br><center><img src="images/ajaxLoader.gif" border=0 align=center valign=middle></center>';
			}
    } 
	function sCh_ListNames2()
    {	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
            var str = xmlHttp.responseText;			
            document.getElementById(divOut).innerHTML = '<div style="padding:15px; padding-top:25px;">'+str.replaceAll('&lt;','<').replaceAll('&gt;','>')+"</div>";
        }
		else{
			document.getElementById(divOut).innerHTML = '<br><br><center><img src="images/ajaxLoader.gif" border=0 align=center valign=middle></center>';
			}
    }

    //EJEMPLO - FUNCION DE USO PARA GET *************************************************************
    /*
    //stateChangeHandler will fire when the state has changed, i.e. data is received back
    // This is non-blocking (asynchronous)
    function stateChangeHandler()
    {   //readyState of 4 or 'complete' represents that data has been returned
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
            //Gather the results from the callback
            var str = xmlHttp.responseText;
            //Populate the innerHTML of the div with the results
            document.getElementById('nameList').innerHTML = str;
        }
    }           
    
    function show_data(strName){
        if (strName.length > 0){
            var url = requestURL + strName;            
            xmlHttp = GetXmlHttpObject(stateChangeHandler);            
            xmlHttp_Get(xmlHttp, url);
        }
        else {document.getElementById('nameList').innerHTML = '';}
    }
    */
    //EJEMPLO - FUNCION DE USO PARA POST *************************************************************    
    /*
	function registraSiebel(){ 
			var url = 'http://www.crmservices.it/NESTLE/webform/webform.php'; 	             
			xmlHttp = GetXmlHttpObject(schSiebel); 	             
			//cargamos parametros
			var params = '';
			//cargamos parametros
			params +=(params=='')?'':'&'
			params += 'retURL=' + escape(document.getElementById("retURL").value);
			params +=(params=='')?'':'&'
			params += 'formName=' + escape(document.getElementById("formName").value);
			params += "\n";
			xmlHttp_Post(xmlHttp, url,params); 
	} 
	function schSiebel() 
	{ 	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
		var str = xmlHttp.responseText; 
		alert(str);} 
	} 
	*/    
var idPost_onComent
function showFormComent(id_post){
	if(idPost_onComent != id_post){
			if(document.getElementById('tdFormComent'+idPost_onComent)){
				document.getElementById('tdFormComent'+idPost_onComent).style.display='none';
				}
			idPost_onComent = id_post;
		}
	if(document.getElementById('tdFormComent'+id_post).style.display == 'none'){
			document.getElementById('tdFormComent'+id_post).style.display = '';
		}
	else{
			document.getElementById('tdFormComent'+id_post).style.display = 'none';
		}
	}

function coment_popup(id_dip,id_post) {
	var obj_calwindow = window.open(
		'blog_Coment.asp?id_dip=' + id_dip + '&id_post=' + id_post,
		'Comentarios', 'width=400,height=450,status=yes,resizable=yes,dependent=yes,alwaysRaised=yes,scrollbars=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function popup(id_dip) {
	var obj_callwindow = window.open(
		'new.asp?id_dip=' + id_dip,
		'Newsletter', 'width=400,height=270,status=yes,resizable=yes,dependent=yes,alwaysRaised=yes,scrollbars=yes'
	);
	obj_callwindow.opener = window;
	obj_callwindow.focus();
}

function youtube(id_vid) {
	var obj_callwindow = window.open(
		'video.asp?id_vid=' + id_vid,
		'Videos', 'width=442,height=344,status=yes,resizable=yes,dependent=yes,alwaysRaised=yes,scrollbars=yes'
	);
	obj_callwindow.opener = window;
	obj_callwindow.focus();
}

function enviar_popup(id_dip,id_post) {
	var obj_calwindow = window.open(
		'enviar.asp?id_dip=' + id_dip + '&id_post=' + id_post,
		'Enviar', 'width=400,height=290,status=yes,resizable=yes,dependent=yes,alwaysRaised=yes,scrollbars=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function printDateHead(){
	var now = new Date()
	var dia = now.getDay()
	var mes = now.getMonth()
	var fecha
	
	//El día de la semana
	if(dia==0){
	 fecha="Domingo";
	}else if(dia==1){
	 fecha="Lunes";
	}else if(dia==2){
	 fecha="Martes";
	}else if(dia==3){
	 fecha="Miércoles";
	}else if(dia==4){
	 fecha="Jueves";
	}else if(dia==5){
	 fecha="Viernes";
	}else{
	 fecha="Sábado";
	}
	
	fecha = fecha + " " + now.getDate() + " de "
	//El nombre del mes
	if(mes==0){
	 fecha=fecha + "enero"
	}else if(mes==1){
	 fecha=fecha + "febrero"
	}else if(mes==2){
	 fecha=fecha + "marzo"
	}else if(mes==3){
	 fecha=fecha + "abril"
	}else if(mes==4){
	 fecha=fecha + "mayo"
	}else if(mes==5){
	 fecha=fecha + "junio"
	}else if(mes==6){
	 fecha=fecha + "julio"
	}else if(mes==7){
	 fecha=fecha + "agosto"
	}else if(mes==8){
	 fecha=fecha + "septiembre"
	}else if(mes==9){
	 fecha=fecha + "octubre"
	}else if(mes==10){
	 fecha=fecha + "noviembre"
	}else{
	 fecha=fecha + "diciembre"
	}
	
	fecha = fecha + " de " + now.getYear()
	
	document.write(fecha);
}


function findd(div)
{
	if (document.getElementById(div).style.visibility =='hidden')
	{
		document.getElementById("fName").style.visibility='hidden';
		document.getElementById("fEdo").style.visibility='hidden';
		document.getElementById(div).style.visibility='';
	}
	else
	{
		document.getElementById(div).style.visibility='hidden';
	}
} 

function findStr(campo)
{
	if (document.getElementById(campo).value.length > 0)
		perfomAjax('ajax/getNames.asp?strFind='+document.getElementById(campo).value,'divDefCuerpo')
	else
		alert("Escriba palabra a buscar");
}
//-->
