/**
* aki ajax v1.4.4: Funciones simplificadas de ajax - http://joemakina.com.ar/
*
* aki ajax (c) 2007 Juan Manuel Barruffaldi (joemakina@hotmail.com) bajo las licencias (MIT License y LGPL Licence)
* http://www.opensource.org/licenses/mit-license.php
*

goAJAX(xW,xF, xP,Exec,Load)

xW-> es el div
xF -> es el archivo php
xP -> son los parametros deforma algo=12&asgo=34&etc=
Exec -> Es una funcion para ejecutar cuando este lista la solicitud (util para ajax dinámico=
Load -> un String para el texto cargando
solo los 2 primeros parametros son necesarios

*/


var strCargando='<p align="center">loading...</p>';
var navegador=navigator.appName;
var ie=document.all;
var dom=GetId;
var ns4=document.layers;
function getId(Id){
	return document.getElementById(Id);
	}
function GetId(Id){
	return document.getElementById(Id);
}
function get(Id){
	return document.getElementById(Id);
}
function putIn(id,html){
	get(id).innerHTML=html;
}
function putInVal(id, val){
	get(id).value=val;
}



	function goAJAX(xW, xF, xP, Exec, Load, replOnStart, replOnEnd){
		
		if ((Load=='')||(!isDefined(Load))){		
			Load=strCargando;
		} else {
			Load=Load;
		}
		
		var peticion = new Ajax.Request(xF, 
		{
			method:'post',
			postBody: xP,
			onCreate: 
				function () {
					if(((!isDefined(replOnStart))||(replOnStart==''))&& xW!='' && xW!=null){
						$(xW).innerHTML = Load;
					}
				},
			onSuccess: 
				function(response) {
					var respuesta 	= response.responseText;
					
					if(((replOnEnd=='')||(!isDefined(replOnEnd)))&& xW!=''&& xW!=null && isDefined(xW)){
						try{$(xW).innerHTML = respuesta;}catch(e){alert(e);}
					}
					
					eval(Exec);
				}, 
			onFailure: 
				function() { 
					alert("Error:\n"+File); 
				}
		});
	}



function isDefined(variable)
{
	return (!(!( variable||false )))
}
function strlen(strVar)
{
	return(strVar.length)
}
function diplayOverlay(){
	var objDiv = GetId("sOverlay")
	objDiv.style.display = "";
	if (navegador=="Microsoft Internet Explorer"){
		objDiv.style.height=document.documentElement.clientHeight*6;
	}else{
		objDiv.style.height=3* window.innerHeight+'px';
	}
}
function winajax(tit,w,h,f,p,Exec,Load){/*Function winajax and goAJAX under LGPL Licence*/
	GetId('btnCerrarVtna').style.display='';
	var oVtna = GetId("sVentana");
	GetId("TitVna").innerHTML=tit;
	oVtna.style.width=w+'px';
	oVtna.style.height=h+'px';
	//centet top window
	scroll_top=((ie)? truebody().scrollTop : window.pageYOffset)+100;
	if (navegador=="Microsoft Internet Explorer"){
		oVtna.style.top=scroll_top;
		oVtna.style.left=(document.body.offsetWidth/2)-(w/2);
	}else{

		oVtna.style.top=scroll_top+'px';
		oVtna.style.left='30%';
	}
	diplayOverlay();
	oVtna.style.display = "";
	goAJAX('ContentVentana',f,p,Exec,Load);
}
function truebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
	function OcultarVtna(){
		if ($("sOverlay")) {
			var objDiv = GetId("sOverlay");
			objDiv.style.display = "none";
		}
		if ($("sVentana")) {
			var objDiv = GetId("sVentana");
			objDiv.style.display = "none";
		}
		if ($('winConfigureModule')) {
			Windows.close("winConfigureModule");
		}
	}//fin goajax

function str_replace(search, replace, subject) {
	return subject.split(search).join(replace);
}
function akiSfrm(frm){
	o = document.forms[frm].elements[0];
	var xP=o.name+'='+encodeURIComponent(str_replace('+', 'kknd', o.value));
	var sxP=o.name+'='+encodeURIComponent(str_replace('+', 'kknd', o.value));
	for (i=1; i<document.forms[frm].elements.length; i++) {
		ob = document.forms[frm].elements[i];
		if (ob.checked){
			xP = xP + '&' + ob.name + '=' + 'ok'+encodeURIComponent(ob.value);
			sxP = sxP + '\n > ' + ob.name + '=' + 'ok'+encodeURIComponent(ob.value);
		}else{
			xP = xP + '&' + ob.name + '=' + encodeURIComponent(str_replace('+', 'kknd', ob.value));
			sxP = sxP + '\n > ' + ob.name + '=' + encodeURIComponent(str_replace('+', 'kknd', ob.value));
		}
	}
	//alert(sxP);
	return xP;
}

function centerDivWindow(WindowId){
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset
	var dsoctop=document.all? iebody.scrollTop : pageYOffset
	oVtna = GetId(WindowId);
	oVtna.style.position="absolute";
	var vh=str_replace('px','',oVtna.style.height);
	var vw=str_replace('px','',oVtna.style.width);
	if (vw<1){vw=(iebody.clientWidth/2);}
	if (vh<1){vh=(iebody.clientHeight/2);}
	
	var theTop =(((iebody.clientHeight/2)+dsoctop)-((vh/2)));

	if(theTop<1){theTop='100';}
	oVtna.style.top = theTop + 'px';
	oVtna.style.left=(((iebody.clientWidth/2)+dsocleft)-((vw/2)))+'px';
}


function akShowHide(div){
	if (get(div).style.display==''){
		get(div).style.display='none';
	}else{
		get(div).style.display='';
	}
	return false;
}

function importJs(src){
  var scriptElem = document.createElement('script');
  scriptElem.setAttribute('src',src);
  scriptElem.setAttribute('type','text/javascript');
  document.getElementsByTagName('head')[0].appendChild(scriptElem);
}

function eventRefresh() {
	window.location.reload();
}
/* MAURO
function sendPollInfo(){
	
	if (GetId('q3_com').value != "" && GetId('q4_com').value != "" && GetId('q6_com').value != "") {
	
		info = "q1="+encodeURIComponent(GetId('q1_h').value);
		info += "&q2="+encodeURIComponent(GetId('q2_h').value);
		info += "&q5="+encodeURIComponent(GetId('q5_h').value);
		info += "&q7="+encodeURIComponent(GetId('q7_h').value);
		info += "&q9="+encodeURIComponent(GetId('q9_h').value);
		
		info += "&q1_com="+encodeURIComponent(GetId('q1_com').value);
		info += "&q2_com="+encodeURIComponent(GetId('q2_com').value);
		info += "&q3_com="+encodeURIComponent(GetId('q3_com').value);
		info += "&q4_com="+encodeURIComponent(GetId('q4_com').value);
		info += "&q5_com="+encodeURIComponent(GetId('q5_com').value);
		info += "&q6_com="+encodeURIComponent(GetId('q6_com').value);
		info += "&q7_com="+encodeURIComponent(GetId('q7_com').value);
		info += "&q9_com="+encodeURIComponent(GetId('q9_com').value);
		
		info += "&name="+encodeURIComponent(GetId('name').value);
		info += "&sex="+encodeURIComponent(GetId('sex').value);
		info += "&email="+encodeURIComponent(GetId('email').value);
		info += "&age="+encodeURIComponent(GetId('age').value);
		info += "&address="+encodeURIComponent(GetId('address').value);
		
		goAJAX('poll_div','poll_form.php',info);
		return false;
	
	} else {
		
		alert("Please, complete all fields.");
		if (GetId('q3_com').value == "") {
			GetId('q3_com').focus();
		} else if (GetId('q4_com').value == "") {
			GetId('q4_com').focus();
		} else if (GetId('q6_com').value == "") {
			GetId('q6_com').focus();
		}		

		return false;
		
	}
}

function sendContestInfo(){
	
	if (GetId('email').value == "" || GetId('fullname').value == "" || GetId('year').value == "" || GetId('zip').value == "" || GetId('guess').value == "") {
		
		alert("Please, complete all fields.");
		
		return false;
		exit;
	}
	
	if (GetId('TermCheck').value == 0) {
		
		alert("Please, agree to the terms of the Express Milwaukee");
		
		return false;
		exit;
	}
	
	info = "email="+GetId('email').value;
	info += "&name="+GetId('fullname').value;
	info += "&year="+GetId('year').value;
	info += "&zip="+GetId('zip').value;
	info += "&guess="+GetId('guess').value;
			
	info += "&r_emails="+GetId('r_emails').value;
	info += "&r_offers="+GetId('r_offers').value;
	
	alert(GetId('TermCheck').value);
	goAJAX('poll_div2','contest.php',info);
	return false;
		

}

 */

