function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (!i) break;   
	}  
	return null;
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function creaXML(){
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp=false;
	  }
	 }
	@else
	 xmlhttp=false
	 @end @*/
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function lp(objeto){
	if(objeto.value.indexOf('Write your knowledge')!=-1)
		objeto.value="";
}

function validaciones(formsici){
	if(formsici.dato.value=='' || formsici.dato.value.indexOf('Write your knowledge')!=-1){
		alert('Write your knowledge, please');
		return false;
	}
	if(GetCookie('iduser')){
		idu=document.createElement('input');
		idu.setAttribute('type','hidden');
		idu.name='iduser';
		idu.value=GetCookie('iduser');
		formsici.appendChild(idu);
	}
	else if(!formsici.getElementsByTagName('div').length){
		emailu=document.createElement('input');
		emailu.setAttribute('type','hidden');
		emailu.name='email';
		emailu.value='sin@mail.com';
		txnombre=document.createTextNode('Your name: ');
		nombre=document.createElement('input');
		nombre.name='nombreu';
		nombre.id='nombreu';
		nombre.value='Anonimous';
		
		spcont=document.createElement('div');
		spcont.className="frsp"
		spcont.appendChild(txnombre);
		spcont.appendChild(nombre);
		spcont.appendChild(emailu);
		formsici.appendChild(spcont);
		return false;
	}
	else{
		if(formsici.nombreu.value==''){
			alert('Write your name, please');
			return false;
		}
	}
	return true;
}

function mp(formsici){
	if(validaciones(formsici)){
		padform=formsici.parentNode;
		vcion=document.createElement('div');
		am('/comun/gpajax.php',vcion,formsici)
		padform.replaceChild(vcion,formsici);
	}
	return false;
}

//La cosa es asi de simple si se envia por post

function am(parametrourl,lugar,formsici){
	xmlhttpa=creaXML();
	var i=0;
	valores='?pt=ajax';
	for(i=0;i<formsici.elements.length;i++){
			valores+='&'+formsici.elements[i].name+'='+formsici.elements[i].value.replace(new RegExp('&','gi'),'phpand');
	}
	xmlhttpa.open("POST",parametrourl,true);
	xmlhttpa.onreadystatechange=function() {
		if (xmlhttpa.readyState==4) {
		   docXML=xmlhttpa.responseText;
		   if(typeof(lugar)=='object'){
				  lugar.innerHTML=docXML;
			}
		}
	}
	xmlhttpa.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttpa.send(valores);
}

function escrfrmc(idres,nombci){
/*
	dtar='Write your knowledge about '+nombci+'...';
	frmo='<form class="sici" onsubmit="return mp(this)">';
	frmo+='		<textarea name="dato" onfocus="lp(this)">'+dtar+'</textarea>';
	frmo+='		<input name="enviar" type="submit" value="Send data" class="boton" />';
	frmo+='		<input name="idciudad" type="hidden" value="'+idres+'" />';
	frmo+='		<input name="idpais" type="hidden" value="0" />';
	frmo+='		<input name="nombre" type="hidden" value="'+nombci+'" />';
	frmo+='	</form>';
	document.write(frmo);
*/
}

function escrfrmp(idres,nombci){
/*
	dtar='Write your knowledge about '+nombci+'...';
	frmo='<form class="sici" onsubmit="return mp(this)">';
	frmo+='		<textarea name="dato" onfocus="lp(this)">'+dtar+'</textarea>';
	frmo+='		<input name="enviar" type="submit" value="Send data" class="boton" />';
	frmo+='		<input name="idciudad" type="hidden" value="0" />';
	frmo+='		<input name="idpais" type="hidden" value="'+idres+'" />';
	frmo+='		<input name="nombre" type="hidden" value="'+nombci+'" />';
	frmo+='	</form>';
	document.write(frmo);
*/
}


function papre(idCiudad){
	window.open("/comun/question.php?id_pais=0&id_ciudad="+idCiudad,"edic","width=511,height=400");
}

function paipre(idPais){
	window.open("/comun/question.php?id_pais="+idPais+"&id_ciudad=0","edic","width=511,height=400");
}

function pnow(idCiudad,lugar){
	window.open("/comun/edciudad.php?id_ciudad="+idCiudad+"&dato="+lugar,"edic","width=511,height=400");
}