// 2007
camps = new Array();
camps[0] = "nom";
camps[1] = "poblacio";
camps[2] = "correue";
camps[3] = "opinio";
function mostrar(obj){
	document.getElementById(obj).style.display = "block";	
}
function ocultar(obj){
	document.getElementById(obj).style.display = "none";
}
function checkProteccioDades(btnID,objID){
	if (document.getElementById(objID).checked == true ){
		mostrar(btnID);
		for (i=0; i<camps.length; i++){
			document.formOpinions[camps[i]].disabled = false;
		}		
	} else {
		ocultar(btnID);
		for (i=0; i<camps.length; i++){
			document.formOpinions[camps[i]].disabled = true;
		}
	}
}
//
campsC = new Array();
campsC[0] = "autor_clicks";
campsC[1] = "fotografia_clicks";
campsC[2] = "titol_clicks";
campsC[3] = "comentari_clicks";
function checkProteccioDadesClicks(btnID,objID){
	if (document.getElementById(objID).checked == true ){
		mostrar(btnID);
		for (i=0; i<campsC.length; i++){
			document.formElsVostres[campsC[i]].disabled = false;
		}		
	} else {
		ocultar(btnID);
		for (i=0; i<campsC.length; i++){
			document.formElsVostres[campsC[i]].disabled = true;
		}
	}
}
// enviar formulari opinions
function validarFormOpinions(){
	var resultat;
	resultat = 0;
	var textAlerta;
	textAlerta = "";
	//
	camps = new Array();
	camps[0] = "nom";
	camps[1] = "poblacio";
	//camps[2] = "correue";
	camps[2] = "opinio";
	camps[3] = "checkbox";
	////////////////////////////////////
	for (i=0; i<camps.length; i++){
		if ( document.formOpinions[camps[i]].value == "" || document.formOpinions[camps[i]].value == "undefined" ){
			//
			textAlerta += "&middot; El camp <span class=\"titular\">" + document.formOpinions[camps[i]].name +  "</span> es obligat <br>";
			document.formOpinions[camps[i]].className = "inputError";
			resultat += 1;
		} else {
			document.formOpinions[camps[i]].className = "input";
		}
	} 
	/*
	if (document.formOpinions.correue.value != ""){
		if( isEmailAddress(document.formOpinions.correue, document.formOpinions.correue) == false ){
			textAlerta += "ˇ El <span class=\"titular\">" + document.formOpinions.correue.name +  "</span> ha de ser vŕlid. <br><br>";
			document.formOpinions.correue.className = "inputError";
			resultat += 1;
		};
	}
	*/
	////////////////////////////////////
	if (resultat != 0 ){
		document.getElementById('fonsProcess').style.display = 'block';
		document.getElementById('mssgProcess').innerHTML = textAlerta;
		//
	} else {
		var valors;
		valors = "";
		for (i=0; i<camps.length; i++){
			if (i==0){
				valors += document.formOpinions[camps[i]].id +"_opi="+ document.formOpinions[camps[i]].value+"&";
			} else if (i==(camps.length-1)){
				valors += document.formOpinions[camps[i]].id +"_opi="+ document.formOpinions[camps[i]].value;
			} else {
				valors += document.formOpinions[camps[i]].id +"_opi="+document.formOpinions[camps[i]].value+"&";
			}
		}
		enviarOpinio(valors);
	}
}
function validarFormElsVostres(){
	var resultat;
	resultat = 0;
	var textAlerta;
	textAlerta = "";
	//
	camps = new Array();
	camps[0] = "autor_clicks";
	camps[1] = "fotografia_clicks";
	camps[2] = "titol_clicks";
	camps[3] = "comentari_clicks";
	////////////////////////////////////
	for (i=0; i<camps.length; i++){
		if ( document.formElsVostres[camps[i]].value == "" || document.formElsVostres[camps[i]].value == "undefined" ){
			//
			if ( i == 0 ){
				textAlerta += "ˇ El camp <span class=\"titular\"> Autor </span> es obligat <br>";
			} else if (i == 1){
				textAlerta += "ˇ El camp <span class=\"titular\"> Fotografia </span> es obligat <br>";
			} else if (i == 2){
				textAlerta += "ˇ El camp <span class=\"titular\"> Títol </span> es obligat <br>";
			} else if (i == 3){
				textAlerta += "ˇ El camp <span class=\"titular\"> Comentari </span> es obligat <br>";
			}
			document.formElsVostres[camps[i]].className = "inputError";
			resultat += 1;
		} else {
			document.formElsVostres[camps[i]].className = "input";
		}
	} 
	////////////////////////////////////
	if (resultat != 0 ){
		document.getElementById('fonsProcessImg').style.display = 'block';
		document.getElementById('mssgProcessImg').innerHTML = textAlerta;
		//
	} else {
		document.getElementById('fonsProcessImg').style.display = 'block';
		document.getElementById('ocultarTitErrorImg').style.display = 'block';
		document.getElementById('mssgProcessImg').innerHTML = "Enviant dades...";
		document.formElsVostres.submit();
	}
}
function recarregarFormClicks(){
	//
	//document.getElementById('imgOK').style.display = 'none';
	ocultar('imgOk');
	//
	camps = new Array();
	camps[0] = "autor_clicks";
	camps[1] = "fotografia_clicks";
	camps[2] = "titol_clicks";
	camps[3] = "comentari_clicks";
	camps[4] = "fotografia_clicks";
	//
	for (i=0; i<camps.length; i++){
		document.formElsVostres[camps[i]].value = "";
	}
	//
	capa = window.DIVinputFile;
	varHTML = '';
	capa.innerHTML = varHTML;
	varHTML += '<input type="file" name="fotografia_clicks" id="fotografia_clicks" style="width:205px;">';
	capa.innerHTML = varHTML;
}
function formNetOpi(){
	//
	//document.getElementById('imgOK').style.display = 'none';
	ocultar('imgOk');
	//
	camps = new Array();
	camps[0] = "nom";
	camps[1] = "poblacio";
	camps[2] = "correue";
	camps[2] = "opinio";
	//
	for (i=0; i<camps.length; i++){
		document.formOpinions[camps[i]].value = "";
	}
	document.formOpinions.correue.value = 'camp no obligatori';
	//
}
//////////////////////////////////////////////////////////////////
function estatus(texto){
 	window.status = texto;
}
function ImgRollover(target,camp){
	document.images[target].src = "rcs/"+camp;
	document.getElementById(target).className = "cursorHand";
}
function autoIframe(frameId){
	try {
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = innerDoc.body.scrollHeight + 10;
		objToResize.width = innerDoc.body.scrollWidth + 10;
	}
	catch(err){
	window.status = err.message;
	}
}
function subsImatge(target,camp){
	if (document.form1[camp].value == 'No'){
		document.images[target].src = "rcs/form/chekboxs_on.gif";
		document.form1[camp].value = 'Sí';
	} else {
		document.images[target].src = "rcs/form/chekboxs_off.gif";
		document.form1[camp].value = 'No';
	}
}
function subsImatgeRadio(target,camp){
	if (document.form1[camp].value == 'No'){
		document.images[target].src = "rcs/form/radiobutton_on.gif";
		document.form1[camp].value = 'Sí';
	} else {
		document.images[target].src = "rcs/form/radiobutton_off.gif";
		document.form1[camp].value = 'No';
	}
}

function visImatge(imatge){
	document.imatge1.src = imatge;
}
function activar_obj_form(origen, desti){
	if ( origen != "" ){
		document.form1[desti].disabled=false;
	} else {
		document.form1[desti].disabled=true;
	}
}
function isEmailAddress(theElement, nombre_del_elemento ){
var s = theElement.value;
var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
   if (filter.test(s))
      return true;
   else
     //alert("Entre una direccion de corre valida");
return false;
}