// JavaScript Document
function slideFolio(col){
	var x = ((col-1)*-300)
	var folioChange = new Fx.Tween('folio', {duration:600});
	folioChange.start('left',x);
	var cur = "trigger"+col;
		$(cur).addClass('current');
	
		for (i=1;i<=8;i++){
			var loopLI = "trigger"+i;
			if (cur==loopLI){}else{
				$(loopLI).removeClass('current');
			}
		}
}


//create a new function
var tweenerFunction  = function() {
        //now select the element you want to tween
        //then tack on .tween
        //finally declare the style property and value you want to tween to
	  var increment			= 870;
	  var maxSize			= -2800;
	  var totalBlocks		= $$('DIV.promotion_block').length;
	  var maxSize			= increment*(-4);
	  maxSize	= increment*(-totalBlocks)/3;
	  var difference = 0;
	  var current = $('folio').getStyle('margin-left').toInt();
	difference = current + increment;
	increment = current - increment <= maxSize ? current : increment;
	//alert(current+' Naxsize '+maxSize+' Increment'+increment);
	$('folio').tween('margin-left', [current, current - increment]);

}
var tweenerGoBack  = function() {
        //now select the element you want to tween
        //then tack on .tween
        //finally declare the style property and value you want to tween to
	  var increment			= 870;
	  var maxSize			= -1400;
	  var maxRightIncrement	= increment*(-3);
	  var difference = 0
	var current = $('folio').getStyle('margin-left').toInt();
	//$('folio').tween('margin-left', [current, current + increment]);
	difference = current + increment;
	increment = difference > 0 ? -current : increment;
	//alert('Current:'+current +' Increment:'+ increment+' Difference= '+difference+' Increment='+ increment );
	if(current < 0){
		$('folio').tween('margin-left', [current, current + increment]);
	}

}

 
window.addEvent('domready', function() {
        //here we add an event to a button to initiate the tween on click
        //and we call our tween function
        $('next').addEvent('click', tweenerFunction);
        $('previous').addEvent('click', tweenerGoBack);
});

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_callJS(jsStr) { //v2.0
 return eval(jsStr)
}
//Valida un email mediante expresiones regulares
function valEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
		return true;
	} else {
		return false;
	}
}
//Validates Spanish Telephone Numbers
function is_phone_ES(valor){
	if (/^(9|8|6)\d{8}$/.test(valor)){
		return true;
	} else {
		return false;
	}
}
//Validates Portuguese Telephone Numbers
function is_phone_PT(valor){
	if (/^(9|2)\d{8}$/.test(valor)){
		return true;
	} else {
		return false;
	}
}
function valCheckBox(){
	// No radio button is selected Select atleast one
	if (!document.frm.checkbox[0].checked && !document.frm.checkbox[1].checked) {
		document.frm.checkbox[1].checked = 1;
	}
}
function valRadioChecked(radioName){//Ej. valRadioChecked(frm.propvvda[0])
	// If radio button[index] is true
	if(radioName.checked == true){	
		
		return true;
	} else {
		return false;
	}
}		
function valCheckBoxCondition(checkbox, message){
	var msg = message;
	if (checkbox.checked == false){
		alert (msg);
		return false;
	} else {
		return true;
	}
}

function valCheckSelect(selectName){
	  if (selectName.selectedIndex == 0) {
		  return false;
	  } else {
		  return true;
	  }
}
//Compare select values
function compareSelect(selectName, compareValue){
	var intSelected = selectName.selectedIndex;
	var selectValue = selectName.options[intSelected].value;
	var objRegex = new RegExp('^'+selectValue+'');
	if (!objRegex.test(compareValue)){
		  return false;
	  } else {
		  return true;
	  }
}
function styleContent(tag, content, simple){
	var taggedContent;
	if(simple == 1){
		taggedContent = '<'+ tag +'/>';
	} else {
		taggedContent = '<'+ tag +'>' + content +'</'+ tag +'>';
	}
	return taggedContent;
}
function StyleBackgrColor(objectName, color){
	return objectName.style.backgroundColor = color;
}

/* CHECK FORM */
function initFields(frm){
	frm.fullname.style.backgroundColor="#FFFFFF";
	frm.telephone.style.backgroundColor="#FFFFFF";
	frm.telephone2.style.backgroundColor="#FFFFFF";
	frm.email.style.backgroundColor="#FFFFFF";
}

	function valForm(frm){
		var error=false;
		var strError="";
		initFields(frm);

		if (frm.fullname.value.length == 0){
			error=true;
			strError += styleContent('dd',"- Nombre.\n");
			frm.fullname.focus();
			StyleBackgrColor(frm.fullname, "#FFFFCC");
		}
		
		if (frm.telephone.value.length == 0 || !is_phone_ES(frm.telephone.value)){
			error=true;
			strError += (frm.telephone.value.length == 0 ? styleContent('dd', "- Teléfono obligatorio.\n") : styleContent('dd',"- Teléfono: Formato incorrecto \n") );
			frm.telephone.focus();
			StyleBackgrColor(frm.telephone, "#FFFFCC");
		}
		if (frm.telephone2.value.length > 0 && !is_phone_ES(frm.telephone2.value))	{
			error=true;
			strError += styleContent('dd', "- El telefono2 admite solo numeros y 9 digitos.\n");
			frm.telephone2.focus();
			StyleBackgrColor(frm.telephone2, "#FFFFCC");
		}
		if (frm.email.value.length == 0 || !valEmail(frm.email.value)){
			error=true;
			strError += (frm.email.value.length == 0 ? styleContent('dd', "- E-mail.\n") : styleContent('dd',"- Email: Formato incorrecto \n") );
			frm.email.focus();
			StyleBackgrColor(frm.email, "#FFFFCC");
		}
		
				
		if (!frm.terms.checked) {
		error=true;
		strError+= styleContent('dd','- Has de aceptar las Condiciones\n');
		}

		if (error){
		var Container = document.getElementById("errorMessage");
		var errorMessage = 'Por favor, rellene correctamente los siguientes campos obligatorios:';
		Container.innerHTML = '<dl>'+styleContent('dt', errorMessage, 0)+strError+'</dl>';
		Container.style.border = '2px dashed #ff0000';
			return false;
		} else {
			//document.frm.action = '../../signup.asp';
			return true;
		}
}
//-->