function showVideo(which1,which2){

	document.getElementById(which1).style.display = "block";
	document.getElementById(which2).style.display = "none";
}


function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


	function changeTips(which1,which2){

		document.getElementById('page1on').style.display = "none";
		document.getElementById('page2on').style.display = "none";
		document.getElementById('page1').style.display = "none";
		document.getElementById('page2').style.display = "none";
		
		document.getElementById(which1).style.display = "block";
		document.getElementById(which2).style.display = "block";
	}
	
	function checkSignUp(){
			
		temp=document.getElementById('sign-up').value;
		if(temp=="Signup for our E-newsletter"){
			
			document.getElementById('sign-up').value="";
		}
	}
	function checkEmail(){
			
		temp=document.getElementById('sign-up').value;
		if(temp=="" || temp=="Signup for our E-newsletter"){
			alert("You must include a valid email address.");
			return false;	
		}
		
		if (temp.indexOf("@")==-1 || temp.indexOf(".")==-1){
			alert("You must include a valid email address.");
			return false;	
		}
		return true;
	}
	function showTips(which){
	
		document.getElementById('blenders').style.display = "none";
		document.getElementById('juicers').style.display = "none";
		document.getElementById('handblenders').style.display = "none";
		document.getElementById('mixers').style.display = "none";
		document.getElementById('roasterovens').style.display = "none";
		document.getElementById('slowcookers').style.display = "none";
		document.getElementById('standmixers').style.display = "none";
		document.getElementById('panini').style.display = "none";
		document.getElementById(which).style.display = "block";
		
		
		
	}

	function setFriendlyURL(myform){
		var fName = "recipe-";
		rName = document.getElementById('name').value;
				
		var no=document.getElementById("mealType");
		var option=no.options[no.selectedIndex].text;
		rName = rName + "-" + option;
		
		for (var c = 0; c < myform.elements.length; c++){
	   		if (myform.elements[c].type == 'checkbox'){
	   			var str=myform.elements[c].checked;
	   			var stridID=myform.elements[c].id;
	   			if(str){
		   			if (stridID.indexOf("easonal")==1){
			   			var no=document.getElementById(stridID).id;
			   			myNo = no.split(",");
						rName = rName + "-" + myNo[1];
  					}
  					if (stridID.indexOf("ppliance")==1){
			   			var no=document.getElementById(stridID).id;
			   			myNo = no.split(",");
						rName = rName + "-" + myNo[1];
  					}
  				}
  			}
  		}
		rName = rName.replace(/ /g , "-");
		rName = rName.replace(/\&/g , "-and-");
		rName = rName.replace(/\//g , "-");
		rName = rName.replace(/\\/g , "-");
		rName = rName.replace(/\./g , "");
		val = fName+rName+".php";
		val = val.toLowerCase();
		document.getElementById('friendlyURL').value =val ;
		
	}



	function showCategories(){
		userType = document.getElementById('Main').userType.value;
		
		if (userType==0 && !userType==""){
			document.getElementById('categories').style.display = "block";
		}else{
			document.getElementById('categories').style.display = "none";
		}
	}
	
	function showDesc(){
		isOn = document.getElementById('Main').isFeatured.checked;
		
		if (isOn==true){
			document.getElementById('desc').style.display = "block";
		}else{
			document.getElementById('desc').style.display = "none";
		}
	}
	
	

	function mycheckBoxes (myform, check,fLeft,fRight) {
	   for (var c = 0; c < myform.elements.length; c++){
	   if (myform.elements[c].type == 'checkbox')
	   		var str=myform.elements[c].id;
	   		if(str){
	  			leftRight=str.split("-");
	  			if(leftRight[0]>=fLeft && leftRight[1]<=fRight){
	  				myform.elements[c].checked = check;
  				}
  			}
	  		
  		}
	}


	function popWindow(url, height, width, xpos, ypos, title) {
		winOptions = 'toolbar=0,location=1,directories=0,screenx=' +  xpos + ',screeny='+ ypos + ',top='+ ypos +',left=' + xpos + ',status=1,menubar=0,scrollbars=1,resizable=1,width=' + width + ',height=' + height;
		var temp = window.open(url, title, winOptions);
		temp.focus();
	}
	function popWindowRedirect(url) {
		winOptions = 'toolbar=1,location=1,directories=1,screenx=100,screeny=100+ ,top=100,left=100,status=1,menubar=1,scrollbars=1,resizable=1,width=900,height=600';
		var temp = window.open(url, "NewWindow", winOptions);
		temp.focus();
	}
	/* begin homepage flash intro functions ---------------------------------------------------*/
	function closeIntro(){
		//document.getElementById('homePanel_1').style.display = "block";
	 	//document.getElementById('introFlash').style.display = "none";		
	}
	function flash(banner, theWidth, theHeight) {
	output = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + theWidth + "\" height=\"" + theHeight + "\" id=\"video2\" align=\"middle\">  ";
	output += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />  ";
	output += "<param name=\"movie\" value=\"" + banner + ".swf\" />  ";
	output += "<param name=\"quality\" value=\"high\" />  ";
	output += "<param name=\"wmode\" value=\"transparent\">  ";
	output += "<embed src=\"" + banner + ".swf\" quality=\"high\" wmode=\"transparent\" width=\"" + theWidth + "\" height=\"" + theHeight + "\" name=\"TFSLogo\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />  ";
	output += "</object>  ";
	document.write(output);
}
	function checkCookie(){
		username=getCookie('username');
		 
		if (username!=null && username!="") {
		// document.getElementById('homePanel_1').style.display = "block";
		 // document.getElementById('introFlash').style.display = "none";
		 }else  {
			//document.getElementById('introFlash').style.display = "block";
			//document.getElementById('homePanel_1').style.display = "none";
			setCookie('username','introPlayed',1);
		   
		   
		  }
		  
	}
	function setCookie(c_name,value,expiredays)
		{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
		}
	function getCookie(c_name){
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
		    { 
		    c_start=c_start + c_name.length+1 ;
		    c_end=document.cookie.indexOf(";",c_start);
		    if (c_end==-1) c_end=document.cookie.length
		    return unescape(document.cookie.substring(c_start,c_end));
		    } 
		  }
		return ""
		}
		
		/* end homepage flash intro functions -------------------------------------------------------*/	
	function Set_Cookie(name,value,expires,path,domain,secure) {
	    document.cookie = name + "=" +escape(value) +
	        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
	        ( (path) ? ";path=" + path : "") + 
	        ( (domain) ? ";domain=" + domain : "") +
	        ( (secure) ? ";secure" : "");
		}

	selectedRow='';
	
	function hl(theRow, hiLite){
		if (theRow.id != selectedRow) {
			if (hiLite) {
				theRow.className="rowHiLite";
			} else {
				theRow.className="";
			}
		}
	}

	function selectRow(theRow){
		if (theRow.id != selectedRow) {
			for (i=0; i < theRow.parentElement.childNodes.length; i++) {
				if (theRow.parentElement.childNodes[i].className == "rowSelect") {
					theRow.parentElement.childNodes[i].className = "";
				}
			}
			theRow.className="rowSelect";
			selectedRow = theRow.id;
		} else {
			theRow.className="";
			selectedRow = ""
		}
	}
	
	function sortBy(field){
		document.getElementById('Main').showResults.value = "y";
		document.getElementById('Main').sortBy4.value = document.getElementById('Main').sortBy3.value;
		document.getElementById('Main').sortBy3.value = document.getElementById('Main').sortBy2.value;
		document.getElementById('Main').sortBy2.value = document.getElementById('Main').sortBy1.value;
		document.getElementById('Main').sortBy1.value = field;
		document.getElementById('Main').submit();
	}
	
	
	
	function select(id){
		document.getElementById('Main').action.value = "select";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
	
	function view(status){
		document.getElementById('Main').action.value = "list";
		document.getElementById('Main').status.value = status;
		document.getElementById('Main').submit();
	}
	
	function add(){
		document.getElementById('Main').action.value = "add";
		document.getElementById('Main').submit();
	}
	
	function save(id){
		document.getElementById('Main').action.value = "save";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
	function reorderMealType(id,oldOrder){
		document.getElementById('Main').action.value = "reorder";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').oldOrder.value = oldOrder;
		document.getElementById('Main').submit();
	}
	
	function reorderPressType(id,oldOrder){
		document.getElementById('Main').action.value = "reorder";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').oldOrder.value = oldOrder;
		document.getElementById('Main').submit();
	}
	
	function reorderSeasonal(id,oldOrder){
		document.getElementById('Main').action.value = "reorder";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').oldOrder.value = oldOrder;
		document.getElementById('Main').submit();
	}
	
	function reorderApplianceType(id,oldOrder){
		document.getElementById('Main').action.value = "reorder";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').oldOrder.value = oldOrder;
		document.getElementById('Main').submit();
	}	
		
	function edit(id){
		document.getElementById('Main').action.value = "edit";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
	
	function upload(id){
		document.getElementById('Main').action.value = "upload";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
	
	function del(id){
		if (confirm("Are you sure you want to delete this record?  This action cannot be undone!")) {
			document.getElementById('Main').action.value = "delete";
			document.getElementById('Main').id.value = id;
			document.getElementById('Main').submit();
		}else{
			document.getElementById('Main').action.value = "list";
		}
	}
	
	function post(id){
		if (confirm("Are you sure you want to post this record?")) {
			document.getElementById('Main').action.value = "post";
			document.getElementById('Main').id.value = id;
			document.getElementById('Main').submit();
		}
	}
	
	function unpost(id){
		if (confirm("Are you sure you want to unpost this record?")) {
			document.getElementById('Main').action.value = "unpost";
			document.getElementById('Main').id.value = id;
			document.getElementById('Main').submit();
		}
	}
	
	function activate(id, activateFlag){
		if (activateFlag) {
			document.getElementById('Main').action.value = "activate";
		} else {
			document.getElementById('Main').action.value = "inactivate";
		}
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
	
	function changeDate(){
		document.getElementById('Main').action.value = "date";
		document.getElementById('Main').editFlag.value = "y";
		document.getElementById('Main').submit();
	}
	
	function changeProject(){
		document.getElementById('Main').action.value = "project";
		document.getElementById('Main').editFlag.value = "y";
		document.getElementById('Main').submit();
	}
	
	function createReport(){
		document.getElementById('Main').showResults.value = "y";
		document.getElementById('Main').submit();
	}
	
	function doTime(theTime){
		document.getElementById('Main').action.value = "time";
		document.getElementById('Main').editFlag.value = "";
		document.getElementById('Main').theTime.value = theTime;
		document.getElementById('Main').submit();
	}
	
	function doUpload(){
		document.getElementById('upload').action.value = "upload";
		document.getElementById('upload').submit();
	}
	
	function popDialog(url, queryString, height, width){

		var l = (screen.availWidth - width) / 2;
		var t = (screen.availHeight - height) / 2;
		var cfg  = "width=" + width;
        cfg += ",height=" + height;
        cfg += ",top=" + t;
        cfg += ",left=" + l;

		winOptions = 'status=0,toolbar=0,location=0,directories=0,' + cfg;
		winName = "dialogBox";
		var temp = window.open(url + "?" + queryString, winName, winOptions);
		temp.focus();
	}
	
	function printDetail(invoiceID){
		winOptions = 'toolbar=1,location=1,directories=1';
		//var temp = window.open(url, title, winOptions);
		url = "/pdf/printDetail.php?invoiceID="+invoiceID;
		title = "printwindow";
		var temp = window.open(url, title, winOptions);
		temp.focus();
	}
	
	function printBatch(invoiceBatchID){
		winOptions = 'toolbar=1,location=1,directories=1';
		//var temp = window.open(url, title, winOptions);
		url = "/pdf/printInvoice.php?invoiceBatchID="+invoiceBatchID;
		title = "printwindow";
		var temp = window.open(url, title, winOptions);
		temp.focus();
	}
	
	function doSubmit(){
		document.getElementById('Main').submit();
	}
	
	function doAction(theAction){
		document.getElementById('Main').action.value = theAction;
		document.getElementById('Main').submit();
	}

	function fillIn(requestedRange){
		
		switch (requestedRange){
			
			case "all":
				doAll();
				break;
			
			case "today":
				doToday();
				break;
			
			case "yesterday":
				doYesterday();
				break;
			
			case "this_week" :
				thisWeek();
				break;
			
			case "last_week":
				lastWeek();
				break;
			
			case "this_month":
				thisMonth();
				break;
				
			case "last_month":
				lastMonth();
				break;
		}
		document.getElementById('Main').submit();
	}

	function doAll() {
		document.getElementById('Main').startDate.value = "";
		document.getElementById('Main').endDate.value =  "";
	}

	function doToday() {
		startDate = new Date();
		document.getElementById('Main').startDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
		document.getElementById('Main').endDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
	}

	function doYesterday() {
		startDate = new Date();
		startDate.setDate(startDate.getDate() - 1);
		document.getElementById('Main').startDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
		document.getElementById('Main').endDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
	}

	function thisWeek() {
		endDate = new Date();
		endDate.setDate(endDate.getDate() + (7 - endDate.getDay()));
		startDate = new Date(endDate);
		startDate.setDate(startDate.getDate() - 6);
		document.getElementById('Main').startDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
		document.getElementById('Main').endDate.value = (endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getYear();
	}

	function lastWeek() {
		endDate = new Date();
		endDate.setDate(endDate.getDate() + (7 - endDate.getDay()));
		endDate.setDate(endDate.getDate() - 7);
		startDate = new Date(endDate);
		startDate.setDate(startDate.getDate() - 6);
		document.getElementById('Main').startDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
		document.getElementById('Main').endDate.value = (endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getYear();
	}

	function thisMonth() {
		today = new Date();
		startDate = new Date(today.getYear(), today.getMonth(), 1);
		endDate = new Date(startDate.getYear(), startDate.getMonth() + 1, 1);
		endDate.setDate(endDate.getDate() - 1);
		document.getElementById('Main').startDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
		document.getElementById('Main').endDate.value = (endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getYear();
	}

	function lastMonth() {
		today = new Date();
		startDate = new Date(today.getYear(), today.getMonth(), 1);
		startDate.setMonth(startDate.getMonth() - 1);
		endDate = new Date(startDate.getYear(), startDate.getMonth() + 1, 1);
		endDate.setDate(endDate.getDate() - 1);
		document.getElementById('Main').startDate.value = (startDate.getMonth() + 1) + "/" + startDate.getDate() + "/" + startDate.getYear();
		document.getElementById('Main').endDate.value = (endDate.getMonth() + 1) + "/" + endDate.getDate() + "/" + endDate.getYear();
	}
	
	function upIndex(id) {
		document.getElementById('Main').action.value = "up";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
	
	function downIndex(id) {
		document.getElementById('Main').action.value = "down";
		document.getElementById('Main').id.value = id;
		document.getElementById('Main').submit();
	}
		
