/////////////
//TRACK PHP FORM SEND - GA EVENT TRACKING
/////////////
function chrisFormTrack(stuff) {
  // _gaq.push(['_trackEvent', 'Form', 'Sent', 'Normal']);
  _gaq.push(['_trackEvent', 'Form', 'Sent', 'Normal', 10]); //value needed for ga segmentation!
    setHidden(stuff);
  }


////////////////
//FORMULARIO DE CONTACTO - GA HIDDEN FIELDS
///////////////
function _uGC(l,n,s) {
   // used to obtain a value form a string of key=value pairs
   if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
   var i,i2,i3,c="-";
   i=l.indexOf(n);
   i3=n.indexOf("=")+1;
   if (i > -1) {
      i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
      c=l.substring((i+i3),i2);
   }
   return c;
}
 
function setHidden(f) {
var z = _uGC(document.cookie, "utmz=",";");
f.web_source.value  = _uGC(z, "utmcsr=", "|");
f.web_medium.value   = _uGC(z, "utmcmd=", "|");
f.web_term.value = _uGC(z, "utmctr=", "|");
f.web_content.value = _uGC(z, "utmcct=", "|");
f.web_campaign.value = _uGC(z, "utmccn=", "|");
var gclid = _uGC(z, "utmgclid=", "|");
//
// The gclid is ONLY present when auto tagging has been enabled.
//
if (gclid !="-") {
      f.web_source.value = "google";
      f.web_medium.value = "cpc";
// not sure why these are out? - not poss to ge this data from gclid- not for Adwords
//f.web_term.value      = " ";
//f.web_content.value  = " ";
//f.web_campaign.value  = " ";
}
}

//

// see http://www.webcheatsheet.com/javascript/form_validation.php for more

function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.nombre);
  reason += validateEmpty(theForm.apellidos);
  reason += validateEmpty(theForm.email);
      
  if (reason != "") {
    alert("Algunos campos tiene errores:\n" + reason);
    return false;
  }

  return true;
}


function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "El campo está vacio.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}



	// not used now
	
function validarContacto(obj, lang){

	if(document.contacto.nombre.value != ""){  //open if 1
                  alert ('cb');
		if(document.contacto.apellidos.value != ""){ //open if 2
		            alert ('cb2');
			if(document.contacto.email.value != ""){    //open if 3

   	                        // chrisFormTrack(obj);  // obj=formulario
				alert ('ok');
                                return true;


				} //close if 3				
				
			else{
			
			error(3,lang);
			document.contacto.email.focus();
			alert ('3');
			return false;	
			
			}			
			
		} //close if 2
                else{
		
		error(2,lang);
		document.contacto.apellidos.focus();
		alert ('2');
		return false;	
		
		}	
		
	}//close if 1
        else{
	
	error(1,lang);
	document.contacto.nombre.focus();
	alert ('1');
	return false;	
	
	}
		
	}  //close functio
	

	

