
function submitonce1(valor){
	if (valor==1) {
		document.getElementById('SubmitButton').style.display="none"
		document.getElementById('ProcessMsg').style.display="block"
		document.getElementById('SubmitButtonT').style.display="none"
		document.getElementById('ProcessMsgT').style.display="block"
	} else {
		document.getElementById('SubmitButton').style.display="block"
		document.getElementById('ProcessMsg').style.display="none"
	}
}
function submitonce(valor){
	if (valor==1) {
		document.getElementById('SubmitButton').style.display="none"
		document.getElementById('ProcessMsg').style.display="block"
	} else {
		document.getElementById('SubmitButton').style.display="block"
		document.getElementById('ProcessMsg').style.display="none"
	}
}
function FocusField(formInst,elementInst){
	if(document.forms.length>0){document.forms[formInst].elements[elementInst].focus();}
}

/*========================================================
Validación de formulario basica
onSubmit="MM_validateForm('nombre','','R','ciudad','','R','email','','RisEmail','usuario','','R','password1','','R','password2','','R');return document.MM_returnValue"
=========================================================*/

function MM_findObj(n,d){
	var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){
	d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
	if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);
	if(!x&&d.getElementById)x=d.getElementById(n);return x;
}
function MM_validateForm(){
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for(i=0;i<(args.length-2);i+=3){
		test=args[i+2];val=MM_findObj(args[i]);
		if(val){
			nm=val.name;
			if((val=val.value)!=""){
				if(test.indexOf('isEmail')!=-1){
					p=val.indexOf('@');
					if(p<1||p==(val.length-1))errors+='- '+nm+' must contain an e-mail address.\n';
				}else if(test.indexOf('checklegal')!=-1){
					
				}else if(test!='R'){
					num=parseFloat(val);
					if(isNaN(val))errors+='- '+nm+' must contain a number.\n';
					if(test.indexOf('inRange')!=-1){
						p=test.indexOf(':');
						min=test.substring(8,p);max=test.substring(p+1);
						if(num<min||max<num)errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
				if(test.indexOf('isDataActual')!=-1){
					var v_DateErrors=isValidDate();
					if (v_DateErrors) {errors=v_DateErrors;}
				}
				if(test.indexOf('checklegal')!=-1){
					if (document.formPost.condiciones.checked == false){errors+='Para continuar debe aceptar las condiciones legales.';}i
				}
			}else if(test.charAt(0)=='R'){
				errors+=' \n';
			}
		}
	}
	if(errors){alert('ATENCIÓ: Heu d\'omplir tots els camps marcats amb *\n'+errors);
	document.MM_returnValue=(errors=='');} else { document.MM_returnValue=(submitonce(1)); }
}

/*
(C) www.dhtmlgoodies.com, October 2005 This is a script from
www.dhtmlgoodies.com. You will find this and a lot of other scripts at
our website. Terms of use: You are free to use this script as long as
the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission. Thank you!
www.dhtmlgoodies.com Alf Magne Kalleland
*/
var fromBoxArray=new Array();var toBoxArray=new Array();var
selectBoxIndex=0;function moveSingleElement(){var selectBoxIndex=
this.parentNode.parentNode.id.replace(/[^\d]/g,'');var tmpFromBox;var
tmpToBox;if(this.tagName.toLowerCase()=='select'){tmpFromBox=this;
if(tmpFromBox==fromBoxArray[selectBoxIndex])tmpToBox=
toBoxArray[selectBoxIndex];else tmpToBox=
fromBoxArray[selectBoxIndex];}else{
if(this.value.indexOf('>')>=0){tmpFromBox=
fromBoxArray[selectBoxIndex];tmpToBox=toBoxArray[selectBoxIndex];
}else{tmpFromBox=toBoxArray[selectBoxIndex];tmpToBox=
fromBoxArray[selectBoxIndex];}}for(var
no=0;no<tmpFromBox.options.length;no++){
if(tmpFromBox.options[no].selected){tmpFromBox.options[no].selected=
false;tmpToBox.options[tmpToBox.options.length]=new
Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);
for(var no2=no;no2<(tmpFromBox.options.length-1);no2++){
tmpFromBox.options[no2].value=tmpFromBox.options[no2+1].value;
tmpFromBox.options[no2].text=tmpFromBox.options[no2+1].text;
tmpFromBox.options[no2].selected=tmpFromBox.options[no2+1].selected;
}no=no-1;tmpFromBox.options.length=tmpFromBox.options.length-1;
}}var tmpTextArray=new Array();for(var
no=0;no<tmpFromBox.options.length;no++){
tmpTextArray.push(tmpFromBox.options[no].text+'___'+
tmpFromBox.options[no].value);}tmpTextArray.sort();var tmpTextArray2
=new Array();for(var no=0;no<tmpToBox.options.length;no++){
tmpTextArray2.push(tmpToBox.options[no].text+'___'+
tmpToBox.options[no].value);}tmpTextArray2.sort();for(var
no=0;no<tmpTextArray.length;no++){var items=
tmpTextArray[no].split('___');tmpFromBox.options[no]=new
Option(items[0],items[1]);}for(var
no=0;no<tmpTextArray2.length;no++){var items=
tmpTextArray2[no].split('___');tmpToBox.options[no]=new
Option(items[0],items[1]);}}function moveAllElements(){var
selectBoxIndex=this.parentNode.parentNode.id.replace(/[^\d]/g,'');
var tmpFromBox;var tmpToBox;if(this.value.indexOf('>')>=0){
tmpFromBox=fromBoxArray[selectBoxIndex];tmpToBox=
toBoxArray[selectBoxIndex];}else{tmpFromBox=
toBoxArray[selectBoxIndex];tmpToBox=fromBoxArray[selectBoxIndex];}
for(var no=0;no<tmpFromBox.options.length;no++){
tmpToBox.options[tmpToBox.options.length]=new
Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);}
tmpFromBox.options.length=0;}function
createMovableOptions(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight)
{fromObj=document.getElementById(fromBox);toObj=
document.getElementById(toBox);fromObj.ondblclick=moveSingleElement;
toObj.ondblclick=moveSingleElement;fromBoxArray.push(fromObj);
toBoxArray.push(toObj);var parentEl=fromObj.parentNode;var
parentDiv=document.createElement('DIV');
parentDiv.className='multipleSelectBoxControl';parentDiv.id=
'selectBoxGroup'+selectBoxIndex;parentDiv.style.width=(Math.floor(totalWidth)+35)+
'px';parentDiv.style.height=totalHeight+'px';
parentEl.insertBefore(parentDiv,fromObj);var subDiv=
document.createElement('DIV');subDiv.style.width=
(Math.floor(totalWidth/2)-15)+'px';fromObj.style.width=
(Math.floor(totalWidth/2)-15)+'px';var label=
document.createElement('SPAN');label.innerHTML=labelLeft;
subDiv.appendChild(label);subDiv.appendChild(fromObj);
subDiv.className='multipleSelectBoxDiv';
parentDiv.appendChild(subDiv);var buttonDiv=
document.createElement('DIV');buttonDiv.style.verticalAlign=
'middle';buttonDiv.style.paddingTop=(totalHeight/2)-50+'px';
buttonDiv.style.width='55px';buttonDiv.style.textAlign='center';
parentDiv.appendChild(buttonDiv);var buttonRight=
document.createElement('INPUT');buttonRight.type='button';
buttonRight.value='>';buttonDiv.appendChild(buttonRight);
buttonRight.onclick=moveSingleElement;var buttonAllRight=
document.createElement('INPUT');buttonAllRight.type='button';
buttonAllRight.value='>>';buttonAllRight.onclick=
moveAllElements;buttonDiv.appendChild(buttonAllRight);var buttonLeft
=document.createElement('INPUT');buttonLeft.style.marginTop='20px';
buttonLeft.type='button';buttonLeft.value='<';buttonLeft.onclick
=moveSingleElement;buttonDiv.appendChild(buttonLeft);var
buttonAllLeft=document.createElement('INPUT');
buttonAllLeft.type='button';buttonAllLeft.value='<<';
buttonAllLeft.onclick=moveAllElements;
buttonDiv.appendChild(buttonAllLeft);var subDiv=
document.createElement('DIV');subDiv.style.width=
(Math.floor(totalWidth/2)-15)+'px';toObj.style.width=
(Math.floor(totalWidth/2)-15)+'px';var label=
document.createElement('SPAN');label.innerHTML=labelRight;
subDiv.appendChild(label);subDiv.appendChild(toObj);
parentDiv.appendChild(subDiv);toObj.style.height=(totalHeight-
label.offsetHeight)+'px';fromObj.style.height=(totalHeight-
label.offsetHeight)+'px';selectBoxIndex++;}


function allSelect(){
	List=document.forms[0].toBox;
	//if(List.length==0) {alert('eeeepp');return;}
	for(i=0;i<List.length;i++) {List.options[i].selected=true;}
}
	
/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;

						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}	
	
/*
(C) www.dhtmlgoodies.com, October 2005
This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.
Thank you!
www.dhtmlgoodies.com
Alf Magne Kalleland
*/	

var ajax = new sack();

function ShowLoadingSel(){
	eval("contentObj.options[contentObj.options.length] = new Option('Actualizando...','0');");
}

function getZonesList(sel){
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_zone').options.length = 0;
	if(countryCode.length>0){
		contentObj = document.getElementById('id_zone');
		ajax.requestFile = webroot+'js/GetZones.php?id_country='+countryCode;
		//ajax.onLoading = contentObj.innerHTML = 'Loading list, please wait...';
		ajax.onLoading = ShowLoadingSel;
		ajax.onCompletion = createZones;
		ajax.runAJAX();
	}
}

function createZones()
{
	var obj = document.getElementById('id_zone');
	document.getElementById('id_zone').options.length = 0;
	eval(ajax.response);
}




function getZonesList_S(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_zone_Sf').options.length = 0;
	if(countryCode.length>0){
		contentObj = document.getElementById('id_zone_Sf');
		ajax.requestFile = common_js+'GetZones.php?id_country='+countryCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Loading...','0');");
		ajax.onCompletion = createZones_S;
		ajax.runAJAX();
	}
}

function createZones_S()
{
	var obj = document.getElementById('id_zone_Sf');
	document.getElementById('id_zone_Sf').options.length = 0;
	eval("obj.options[obj.options.length] = new Option('...Todas','Todas');"+ajax.response);
}

function getProvincesList(sel, path){
	var provinceCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_loc_province').options.length = 0;
	document.getElementById('id_loc_city').options.length = 0;
	if(provinceCode.length>0){
		contentObj = document.getElementById('id_loc_province');
		ajax.requestFile = path+'js/GetProvinces.php?id_zone='+provinceCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Actualizando...','0');");
		ajax.onCompletion = createProvinces;
		ajax.runAJAX();
	}
}
function createProvinces(){
	var obj = document.getElementById('id_loc_province');
	document.getElementById('id_loc_province').options.length = 0;
	eval(ajax.response);
}

function getCitiesList(sel, path){
	var cityCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_loc_city').options.length = 0;
	if(cityCode.length>0){
		contentObj = document.getElementById('id_loc_city');
		ajax.requestFile = path+'js/GetCities.php?id_loc_province='+cityCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Actualizando...','0');");
		ajax.onCompletion = createCities;
		ajax.runAJAX();
	}
}
function createCities(){
	var obj = document.getElementById('id_loc_city');
	document.getElementById('id_loc_city').options.length = 0;
	eval(ajax.response);
}

function getZonesList_S(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_zone_Sf').options.length = 0;
	if(countryCode.length>0){
		contentObj = document.getElementById('id_zone_Sf');
		ajax.requestFile = common_js+'GetZones.php?id_country='+countryCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Loading...','0');");
		ajax.onCompletion = createZones_S;
		ajax.runAJAX();
	}
}

function createZones_S()
{
	var obj = document.getElementById('id_zone_Sf');
	document.getElementById('id_zone_Sf').options.length = 0;
	eval("obj.options[obj.options.length] = new Option('...Todas','Todas');"+ajax.response);
}

/*
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
*/
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}

function OnlyNum(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
		var i;
		for (i = 0; i < myfield.form.elements.length; i++)
			if (myfield == myfield.form.elements[i])
				break;
		i = (i + 1) % myfield.form.elements.length;
		myfield.form.elements[i].focus();
		return false;
	} 
else
if (((keycode>47) && (keycode<58) )  || (keycode==46) || (keycode==44) || (keycode==45) || (keycode==8) || (keycode == 13)) {EnableSave(); return true;}
else return false;
}


function EnableSave(){
	unsaved_changes='Y';
	YAHOO.util.Dom.setStyle('SaveButton', 'display', 'inline');
	YAHOO.util.Dom.setStyle('SaveButtonDisabled', 'display', 'none');
	YAHOO.util.Dom.setStyle('msg_info', 'display', 'none');
}

function NoKeyReturn(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13) {
			var i;
			for (i = 0; i < myfield.form.elements.length; i++)
				if (myfield == myfield.form.elements[i])
					break;
			i = (i + 1) % myfield.form.elements.length;
			myfield.form.elements[i].focus();
			return false;
	} 
	
}


function channel(url) {
    ns4 = (document.layers)? true: false
    if (ns4) {
        h = screen.height;
        w = screen.width;
window.open(url,'','screenX=10,screenY=10,height='+(h-50)+',width='+(w-50)+',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
    }
    else {
	h = screen.height;
    w = screen.width;
	window.open(url,'','screenX=10,screenY=10,height='+(h-100)+',width='+(w-40)+',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no');
//window.open(url,'','fullscreen=yes,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no')
    }
}


function copyToClipboard(inElement) {
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    //if (range && BodyLoaded==1)
      range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="../../js/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

function whenLoading(){
	var e = document.getElementById('pagePosts'); 
	e.innerHTML = "Loading Data...";
}

function makeRequest(url, parameters) {
	ajax.requestFile = url+parameters;
	ajax.element = 'pagePosts';
	//ajax.onLoading = whenLoading;
	//ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}

function whenCompleted() {
   var e = document.getElementById('pagePosts'); 
	if (ajax.responseStatus){
		var string = "<p>Status Code: " + ajax.responseStatus[0] + "</p><p>Status Message: " + ajax.responseStatus[1] + "</p><p>URLString Sent: " + ajax.URLString + "</p>";
	} else {
		var string = "<p>URLString Sent: " + ajax.URLString + "</p>";
	}
	e.innerHTML = string;
}

function get(obj) {
  var getstr = "?";
  for (i=0; i<obj.childNodes.length; i++) {
	 if (obj.childNodes[i].tagName == "INPUT") {
		if (obj.childNodes[i].type == "text") {
		   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		if (obj.childNodes[i].type == "password") {
		   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		if (obj.childNodes[i].type == "hidden") {
		   getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}
		if (obj.childNodes[i].type == "checkbox") {
		   if (obj.childNodes[i].checked) {
			  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		   } else {
			  getstr += obj.childNodes[i].name + "=&";
		   }
		}
		if (obj.childNodes[i].type == "radio") {
		   if (obj.childNodes[i].checked) {
			  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		   }
		}
	 }   
	 if (obj.childNodes[i].tagName == "SELECT") {
		var sel = obj.childNodes[i];
		getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
	 }
	 if (obj.childNodes[i].tagName == "TEXTAREA") {
		getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value.replace(/\n/g,"<br>") + "&";
	 }
  }
  makeRequest('constructor/show_posts.php', getstr);
}


