function CheckBox(layer,imgName,trueValue,falseValue,onLoadState,food_cat_id,food_subcat_id,flyer_id,price) {
	this.layer = layer
	this.imgName = imgName
	this.trueValue = trueValue
	this.falseValue = falseValue
	this.state = (onLoadState) ? 1 : 0
	this.value = (this.state) ? this.trueValue : this.falseValue
	this.change = CheckBoxChange	

	this.food_cat_id = food_cat_id
	this.food_subcat_id = food_subcat_id
	this.flyer_id = flyer_id
	this.price = price
}

function CheckBoxChange(color) {
	this.state = (this.state) ? 0 : 1
	
	if (color == "white")
		color = "-white";
	else
		color = "";

	
	this.value = (this.state) ? this.trueValue : this.falseValue
	changeImage(this.layer,this.imgName,'addtolist'+color + this.state)
}

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function changeImage(layer,imgName,imgObj) {
	if (document.images) {
		if (document.layers && layer!=null)
		
		eval('document.'+layer+'.document.images["'+imgName+'"].src = '+  '../common/_images/addtolist' + imgObj+'.gif')
		else 
		{
		
		document.images[imgName].src = '../common/_images/' + imgObj+".gif"
		
		
		}
	}
}

function openWin(flyer_id,nam,food_cat_id,food_subcat_id,price){
	// called as: openWin(0, "Mother's Day Cake,90,497,25.99)
	var myBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,hotkeys=no';
  	var myOptions = 'scrollbars=no,width=1,height=1,resizeable=no,screenX=1400,screenY=1400,top=2500,left=1400';
    	// for testing, use this visible window:
// 	var myOptions = 'scrollbars=yes,width=800,height=800,screenX=10,screenY=10,resizeable=no';
	var myFeatures = myBars + ',' + myOptions;
//	var myFeatures = "";

	var newWin = open('', 'newWin', myFeatures);
	//newWin.blur();
	newWin.document.writeln("<html><head></head><body>");
	newWin.document.writeln('<form action = "../common/additem.php" name="newForm" method="post">');

	newWin.document.writeln('<input type="hidden" name="flyer_id" value="', flyer_id,  '">');
	newWin.document.writeln('<input type="hidden" name="name" value="' , nam , '">');
	newWin.document.writeln('<input type="hidden" name="food_cat_id" value="' , food_cat_id, '">');
	newWin.document.writeln('<input type="hidden" name="food_subcat_id" value="', food_subcat_id, '">');
	newWin.document.writeln('<input type="hidden" name="price" value="' , price, '">');

	newWin.document.writeln('</form>');
	newWin.document.writeln("</body></html>");
	
	// for testing, comment out this line and access View Source in child window:
	newWin.document.forms.newForm.submit();
 	newWin.document.close();  

}


function addItem(flyer_id,nam,food_cat_id,food_subcat_id,price){

	var params = "";
	
	
	params += "flyer_id=" + flyer_id;
	params += "&name=" + escape(nam);
	params += "&food_cat_id=" + food_cat_id;
	params += "&food_subcat_id=" + food_subcat_id;
	params += "&price=" + escape(price);

	
	CallAjax("../common/additem_handler.php", params, false, null);

	
	// for testing, comment out this line and access View Source in child window:
	 

}






function CallAjax(url, params, isAsync, oFunction)
{
   var xmlhttp=null;
   
   
	    try
	    {
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		    if (typeof(xmlhttp) != 'object' )
		    {	 	
		       // If IE7, Mozilla, Safari, etc: Use native object
		       xmlhttp = new XMLHttpRequest();
		    }
	    }
	    catch (e) 
	    {
		    // fallback: use native object 
		    xmlhttp = new XMLHttpRequest();
	    }

	    if (xmlhttp!=null)
	    {
	    
	    

			xmlhttp.open("POST", url,isAsync);    
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    
		    
		    if (isAsync == true)
		    {
		         xmlhttp.onreadystatechange  = oFunction ;
                 xmlhttp.send(params);  
                 
            
		    }
		    else
		    {
		         xmlhttp.send(params);
				     
                return xmlhttp.responseText;
                
		    }
          
	    }	
}


