//
document.domain="lebootcamp.com";
//
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

//
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
//
function setColorPalette() {
	// Alex - No more random color - defaults to 2
	// var colorPalette = new Array ("1","2","3");
	// var theColor = colorPalette[Math.round(Math.random() * 2)];
	var theColor='1';
	createCookie('color',theColor,365);
	return  theColor;
}
//
function checkEntry(theField,theRow,theDefault, nullAcceptable){
	var theHelpID = "help"+theRow;
	if (isNotEmpty(theField.value)){
		if (theRow>0) {
	  		document.getElementById(theHelpID).innerHTML = theDefault;
	  	}
	   theField.style.borderWidth = '1px';
	   clearError();
	   return true;
	} else {
		if (nullAcceptable) {
			return true;
		} else {
		if (theRow>0) {
		   setError(errors['no_value']);
		 
		  }
		   theField.style.borderWidth = '2px';
		   return false;
	   }
	}
}
//
function setError(theError){

	document.getElementById('context1').style.backgroundImage = 'url(/minceur/images/shared/forms/caution.gif)';
	document.getElementById('whiteboard').innerHTML = " <span class='error'>&nbsp;&nbsp; "+theError+"</span>";
}
//
function clearError(){
	
	document.getElementById('context1').style.backgroundImage = 'url(/minceur/images/shared/forms/balloon.gif)';
// DS	document.getElementById('whiteboard').innerHTML = originalNote1;

}
//
function checkNumber(theField,theRow,theDefault, nullAcceptable){
	var theHelpID = "help"+theRow;
	if (isNumber(theField.value, nullAcceptable)){
	
	  document.getElementById(theHelpID).innerHTML = theDefault;
	   theField.style.borderWidth = '1px';
	   clearError();

	   return true;
	} else {
		//theField.style.borderColor = '#0000FF';
		setError(errors['no_number']);
	   return false;
	}
}
//
function checkAddress(theField,theRow,theDefault){
	var theHelpID = "help"+theRow;
	if (isAddress(theField.value)){
	   clearError();
		return true;
	} else {
		setError(errors['no_address']);
		return false;
	}
}

function isAddress(theValue){
	if (theValue != ''){
		var addressPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		if (!(addressPattern.test(theValue))) { 
		  return false;
		} else {
			var illegalChars = /[\(\)\<\>\,\;\:\\\/\[\]]/;
			if (theValue.match(illegalChars)) {
				return false;
			} else {
				return true;
			}
		} 
	} else {
		return false;
	}
}

//
function isNotEmpty(theValue){
	if (theValue != ''){
			return true;
	} else {
			return false;
	}
}
//
function isNumber(theValue, nullOK){
	if (theValue != ''){
		var illegalChars = /\D/; // only numbers
		if (illegalChars.test(theValue)) {
			return false;
		} else {
			return true;
		}
	} else {
		if (nullOK) {
			return true;
		} else {
			return false;
		}
	}

}
//
function checkJoinForm(theForm,thePage){
	var nullNotOK = false;
	var nullOK = true;
	
	if (thePage=='1'){
		var errors = 0;
		if (!(checkEntry(theForm.MC_first_name,'1','',nullNotOK))) { return false; } 

		if (!(checkEntry(theForm.MC_last_name,'2','',nullNotOK))) { return false; }

		if (!(checkEntry(theForm.MC_street,'3','',nullNotOK))) { return false; }

		if (!(checkEntry(theForm.MC_city,'4','',nullNotOK))) { return false; }

		if (!(checkEntry(theForm.postcode,'5','',nullNotOK))) { return false; }

		if (!(checkAddress(theForm.email,'8',''))) { return false; }
	
		changePages('page1','page2','MC_start_weight');
		return true;
		
	}
return true;

}
//
function checkLogin(theForm){
	var nullNotOK = false;
	var nullOK = true;
	if (checkEntry(theForm.user,'0','',nullNotOK)){
		if (checkEntry(theForm.pswd,'0','',nullNotOK)){
			theForm.submit();
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}

return true;
}
//
function checkPrefs(theForm){
	var nullNotOK = false;
	var nullOK = true;
	if (isNotEmpty(theForm.email)){
		if (isNotEmpty(theForm.password)){
			theForm.submit();
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}

return true;
}
//


//

//
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
//
function changePages(theOldID,theNewID,theFocus){
	document.getElementById(theNewID).style.display = 'block';
	opacity(theOldID, 100, 0, 1250);
	opacity(theNewID, 0, 100, 1250)
	document.getElementById(theOldID).style.display = 'none';
	if (theFocus != ''){
	document.getElementById(theFocus).focus();
	}
}
//
function selectRow(which){
	var object=document.getElementById("row"+which);
	if (object.className == 'formRow') object.className = 'formRowFocused';

}

function deselectRow(which){
	var object=document.getElementById("row"+which);
	if (object.className == 'formRowFocused') object.className = 'formRow';


}
//
function configureWP(){
		var first=document.getElementById("MC_first_name").value;
		var last=document.getElementById("MC_last_name").value;
		document.getElementById("name").value = first + ' ' + last;
		var street=document.getElementById("MC_street").value;
		var suite=document.getElementById("MC_suite").value;
		var city=document.getElementById("MC_city").value;
		if (city != ''){
			if (suite != ''){
				document.getElementById("address").value = street + '&#10;' + suite + '&#10;' + city;
			} else {
				document.getElementById("address").value = street + '&#10;' + city;
			}
		} else {
			if (suite != ''){
				document.getElementById("address").value = street + '&#10;' + suite;
			} else {
				document.getElementById("address").value = street;
			}
		}
}
//
function setPaymentParams(theValue){
	if (theValue == "1"){
	// monthly selected (default)
	 document.getElementById('intervalMult').value = "1";
	 document.getElementById('initialAmount').value = "28.00";
	 document.getElementById('normalAmount').value = "18.00";
	 document.getElementById('amount').value = "28.00";
	}  else {
	// yearly selected
	 document.getElementById('intervalMult').value = "12";
	 document.getElementById('initialAmount').value = "172.00";
	 document.getElementById('normalAmount').value = "172.00";
	 document.getElementById('amount').value = "172.00";
	}
}
//
function checkDate(fld,theRow) {
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var errorMessage = "Le format de la date n'est pas correct, merci de rentrer une date sous le format : jj-mm-aaaa";
    if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
       //alert('Date is OK'); 
       	   clearError();
       	   return true;

    } else {
        setError(errorMessage);
     return false;
    } 
}
//
function getHelp(theTopic,theTop,theLeft){
	// yearly selected
	 document.getElementById('help').style.display = "block";
	 document.getElementById('chalkboard').style.display = "block";
	 document.getElementById('backboard').style.display = "block";
	 document.getElementById('chalkboard').style.top = theTop;
	 document.getElementById('chalkboard').style.left = theLeft;
	 document.getElementById('backboard').style.top = theTop;
	 document.getElementById('backboard').style.left = theLeft;
	document.getElementById('chalkboard_msg').innerHTML = helps[theTopic];
}
//
function closeHelp(){
	// yearly selected
	 document.getElementById('help').style.display = "none";
	 document.getElementById('chalkboard').style.display = "none";
	 document.getElementById('backboard').style.display = "none";
}
//
function showRecipe(which){
location.href='program.php?action=recipe&ds='+which;
}

// add by Del

function addEvent(elm, evType, fn, useCapture)
{
if(elm.addEventListener)
  {
  elm.addEventListener(evType, fn, useCapture);
  return true;
  }
else if (elm.attachEvent)
  {
  var r = elm.attachEvent('on' + evType, fn);
  return r;
  }
else
  {
  elm['on' + evType] = fn;
  }
}

// removes the square border that IE
// insists on adding to checkboxes and radio
function removeCheckBoxBorders()
{
var el = document.getElementsByTagName("input");
for (i=0;i<el.length;i++)
  {
  var type = el[i].getAttribute("type");
  if((type=="checkbox")||(type=="radio"))
    {
   el[i].style.border = "none";
    }
  }
}

addEvent(window, 'load', removeCheckBoxBorders, false);

// add by Del June 2nd,2007


