// Image Preloader

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function jump(menu){
  var loc = menu[menu.selectedIndex].value.split("|");
  if(loc.length == 2)
    window.open(loc[1], loc[0]);
}

function toggleLayer(whichLayer,id){
	if (document.getElementById){
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}else if (document.all){
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}else if (document.layers){
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	
	if(id == 0){
		selectAll();
		checkAll('lec_');
	}else{
		status(id);
		uncheckAll('lec_');
	}
}

function checkAll(field){
	for (i = 11; i < 12; i++){
		document.getElementById(field+i).innerHTML = '<input type="image" name="'+field+i+'" src="/i/icons/checked.png" value="1" onclick="updateLS(\''+field+i+'\',1);" /><input type="hidden" name="'+field+i+'" value="'+field+i+'" />';
	}
}

function uncheckAll(field){
	for (i = 11; i < 12; i++)
		document.getElementById(field+i).innerHTML = '<input type="image" name="'+field+i+'" src="/i/icons/unchecked.png" value="0" onclick="updateLS(\''+field+i+'\',0);" />';
}

function status(id){ 
	AjaxRequest.get(
		{
			'url':'/inc/internal_request.php?action=status'
			,'parameters':{ 'id':id }
			,'onSuccess':function(req){ 
				var response = req.responseText;
				document.getElementById('status').innerHTML = response;
			}
			,'onError':function(req){
					alert('We have detected that you are using a browser which is not supported by our online ordering system.\nPlease contact us directly at 303-368-9990 or via email at info@prchefs.com');
					report_Error(id,status);
			}
		}
	); // end AjaxRequest
}

function selectAll(){ 
	new Ajax.Request('/inc/internal_request.php?action=selectAll',
		{
			method:'get',
			onSuccess:function(req){
				var response = req.responseText;
				document.getElementById('status').innerHTML = response;
			}
		});
}

function updateLS(id,status){ //updateLS('id',checked or unchecked)
	var url = '/inc/internal_request.php?action=update';
	var params = 'status=' + status + '&id=' + id;

	new Ajax.Request('/inc/internal_request.php?action=update',
		{
			method:'get',
			onLoading: function(){document.getElementById(id).innerHTML = '<input type="image" name="'+id+'" src="/i/icons/loader.gif" value="" />';},
			onSuccess: function(req){
				var response = req.responseText;
				if(status == true)
					document.getElementById(id).innerHTML = '<input type="image" name="'+id+'" src="/i/icons/unchecked.png" value="0" onclick="updateLS(\''+id+'\',0);" />';
				else
					document.getElementById(id).innerHTML = '<input type="image" name="'+id+'" src="/i/icons/checked.png" value="1" onclick="updateLS(\''+id+'\',1);" /><input type="hidden" name="'+id+'" value="'+id+'" />';
	
				document.getElementById('status').innerHTML = response;
			},
		});
}

function report_Error(id,status){
	new Ajax.Request('/inc/internal_request.php?action=error',
		{
			method:'get',
			parameters:{'status':status,'id':id},
		});
}