//JAVASCRIPT FUNCTIONS FOR ADMIN SECTION
/*
jsfunctions.js
Author : Rudra S. Shrestha
*/
	var xmlHttp
	
	var enableCache = false;
	var jsCache = new Array();
	var AjaxObjects = new Array();
	
	function ShowContent(divId,ajaxIndex,url){
		document.getElementById(divId).innerHTML = AjaxObjects[ajaxIndex].response;
		if(enableCache){
			jsCache[url] = 	AjaxObjects[ajaxIndex].response;
		}
		AjaxObjects[ajaxIndex] = false;
	}
	
	function Ajax_StatusChanged(){		
		document.getElementById('container').innerHTML = '<img src=images/ajax-loader-pink.gif>';
	}
	
	function GetXmlHttpObject(){ 
		var objXMLHttp=null
		if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject){
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		return objXMLHttp
	}
	
	function displayImage(imagePath,title,description){
		var enlargerObj = new DHTMLSuite.imageEnlarger();
		enlargerObj.setIsDragable(true);
		enlargerObj.setIsModal(false);		
		DHTMLSuite.commonObj.setCssCacheStatus(false);
		enlargerObj.displayImage(imagePath,title,description);
			
	}
	function SearchChargeProjects(){
		frm = document.frmChargeSheet;	
		//date range
		if(frm.choose_type.value == 1){	
			//from date selection
			frm_year = frm.txtFromYear_Charge.value;
			frm_month = frm.txtFromMonth_Charge.value;
			frm_day = frm.txtFromDate_Charge.value;
			fromDate = frm_year + "-" + frm_month + "-" + frm_day;
			//to date selection
			to_year = frm.txtToYear_Charge.value;
			to_month = frm.txtToMonth_Charge.value;
			to_day = frm.txtToDate_Charge.value;
			toDate = to_year + "-" + to_month + "-" + to_day;
			document.location = "index.php?task=business&option=searchchargeprojects&choose=1&fromDate="+fromDate+"&toDate="+toDate;
		}
		//month view
		if(frm.choose_type.value == 2){		
			month = frm.txtFromMonthOnly_Charge.value;
			document.location = "index.php?task=business&option=searchchargeprojects&choose=2&month="+month;
		}
		//day view	
		if(frm.choose_type.value == 3){		
			fyear = frm.txtFromYearDay.value;
			fmonth = frm.txtFromMonthDay.value;
			fday = frm.txtFromDateDay.value;
			fDate = fyear + "-" + fmonth + "-" + fday;
			document.location = "index.php?task=business&option=searchchargeprojects&choose=3&fdate="+fDate;
		}
	}
	function ChangeChooseType(val){
		frm = document.frmChargeSheet;
		frm.choose_type.value = val.value;
	}
	function AcceptMode(mode){
		if(mode=="modeDrink"){
			document.frmDrinks.modeDrink.value = "accept";
			document.frmDrinks.submit();
		}
		if(mode=="modeForum"){
			document.frmForum.modeForum.value = "accept";
			document.frmForum.submit();
		}
		if(mode=="modeGlass"){
			document.frmGlass.modeGlass.value = "accept";
			document.frmGlass.submit();
		}
		if(mode=="modeLiquorBrands"){
			document.frmLiquorBrands.modeLiquorBrands.value = "accept";
			document.frmLiquorBrands.submit();
		}
		if(mode=="modeLiquor"){
			document.frmListLiquor.modeLiquor.value = "accept";
			document.frmListLiquor.submit();
		}
		if(mode=="modeDrinkCategory"){
			document.frmDrinkCategory.modeDrinkCategory.value = "accept";
			document.frmDrinkCategory.submit();
		}
		if(mode=="modeForumPost"){
			document.frmPosts.modeForumPost.value = "accept";
			document.frmPosts.submit();
		}
		//added suman
		if(mode=="modeBeerBrands")
		{
			document.frmBeerBrands.modeBeerBrands.value="accept";
			document.frmBeerBrands.submit();
		}
	}
	function DenyMode(mode){
		if(mode=="modeDrink"){
			document.frmDrinks.modeDrink.value = "deny";
			document.frmDrinks.submit();
		}
		if(mode=="modeForum"){
			document.frmForum.modeForum.value = "deny";
			document.frmForum.submit();
		}
		if(mode=="modeGlass"){
			document.frmGlass.modeGlass.value = "deny";
			document.frmGlass.submit();
		}
		if(mode=="modeLiquorBrands"){
			document.frmLiquorBrands.modeLiquorBrands.value = "deny";
			document.frmLiquorBrands.submit();
		}
		if(mode=="modeLiquor"){
			document.frmListLiquor.modeLiquor.value = "deny";
			document.frmListLiquor.submit();
		}
		if(mode=="modeDrinkCategory"){
			document.frmDrinkCategory.modeDrinkCategory.value = "deny";
			document.frmDrinkCategory.submit();
		}
		if(mode=="modeForumPost"){
			document.frmPosts.modeForumPost.value = "deny";
			document.frmPosts.submit();
		}
		//new added-suman
		if(mode=="modeBeerBrands")
		{
			document.frmBeerBrands.modeBeerBrands.value="deny";
			document.frmBeerBrands.submit();
		}
	}
	function mysubmit(){
		var Flash;
		if(document.embeds && document.embeds.length>=1)
			Flash = document.getElementById("EmbedFlashFilesUpload");
		else
			Flash = document.getElementById("FlashFilesUpload");
		var FormObj = document.getElementById("myform");
		document.myform.submitbtn.disabled = true;
		var FormValues = '';
		for (var i = 0; i<FormObj.elements.length; i++)
			FormValues += FormObj.elements[i].name + '=' + FormObj.elements[i].value + ((i!=(FormObj.elements.length-1))?'&':'');
		Flash.SetVariable("SubmitFlash", FormValues); 
		return false;
	}
	function removeEvent(divNum){
		var d = document.getElementById('myDiv');
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
	}
	function removeNewIngredient(divNum){
		var d = document.getElementById('myDiv');
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
	}
	function Glass_Multiplier(){
		val = '<select name="glass_multiplier" id="glass_multiplier">'+
				  '<option value="1" selected="selected">1</option>'+
				  '<option value="1.5">1.5</option>'+
				  '<option value="2">2</option>'+
				  '<option value="2.5">2.5</option>'+
				  '</select>'+
				' Multiplier';
		if((document.getElementById('shot_glass').checked) == true){
			document.getElementById('shot_glass_multiplier').innerHTML = val;	
		}else{
			document.getElementById('shot_glass_multiplier').innerHTML = "";		
		}
	}
	function Edit_Glass_Multiplier(){
		val = '<select name="glass_multiplier" id="glass_multiplier">'+
				  '<option value="1" selected="selected">1</option>'+
				  '<option value="1.5">1.5</option>'+
				  '<option value="2">2</option>'+
				  '<option value="2.5">2.5</option>'+
				  '</select>'+
				' Multiplier';
		if((document.getElementById('shot_glass').checked) == true){
			document.getElementById('edit_shot_glass_multiplier').innerHTML = val;	
		}else{
			document.getElementById('edit_shot_glass_multiplier').innerHTML = "";		
		}
	}
	function ViewTemplate(imgname){
			myWindow = window.open("","win_name", 'width=1,height=1,top=0,left=0,toolbar=no,scrollbars=no')
			myWindow.document.write("<html><head><meta http-equiv='imagetoolbar' content='no'><title>Preview Image</title></head>")
			myWindow.document.write("<body  onContextMenu='return false' leftmargin=2 topmargin=2 marginwidth=2 marginheight=2 onload=' window.resizeTo(img.width+40,img.height+80)'>")
			myWindow.document.write("<div align=center><img  src='"+imgname+"' id='img'></body></html>")
			myWindow.document.close()
			myWindow.focus();
	}
	function popupWindow(url,height,width){
		  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=150')
	}
	function CloseMe(){
		opener.location.reload(true);
		self.close();
	}
	function popup(imgname){
			var w=2600;
			var h=2400;
			var toolbar="0";
			var location="0";
			var directories="0";
			var status="0";
			var menubar="0";
			var scrollbars="0";
			var resizable="0";
			var myWin; 
			var winl = (screen.width - w) / 2;
			var wint = (screen.height - h) / 2;
			myWindow = window.open(imgname,"win_name", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,top='+wint+',left='+winl+'resizable=0')	
	}
	function SureDelete(id,task,option){
		if(confirm("Are you sure to delete this record?")){
			document.location='index.php?task='+task+'&option='+option+'&id='+id+'&action=delete';
		}else{
			return false;
		}
	}
	function SureDeleteRecord(id,task,option){
		if(confirm("Are you sure to delete this record?")){
			document.location='index.php?task='+task+'&option='+option+'&id='+id+'&action=delete';
		}
	}
	function DeleteRecord(id,task,option){
		if(confirm("Are you sure to delete this record?")){
			document.location='index.php?task='+task+'&option='+option+'&id='+id+'&action=deletenext';
		}
	}
	function SplashDelete(){
		if(confirm("Are you sure to delete this record?")){
			return true;	
		}else{
			return false;
		}
	}
	function ValidateMetroArea(){
		frm = document.frmNewMetroArea;
		if(frm.metro_area_name.value ==""){
			alert("Please, enter metro area name.");
			return false;
		}
		else{
			return true;
		}
	}
	function ValidateLiquorContainer(){
		frm = document.frmAddLiquorContainer;
		if(frm.container_name.value==""){
			alert("Please, enter container name.");
			return false;
		}
		if(frm.quantity.value==""){
			alert("Please, enter quantity.");
			return false;
		}	
		else{
			return true;	
		}
	}
	
	function ValidateNewBrand(){
		frm = document.frmNewBrand;
		if(frm.name.value==""){
			alert("Please, enter brand name.");
			return false;
		}
		else{
			return true	
		}
	}
	
	function EditShippingRule(){
		frm = document.frmEditShippingRule;
		if(frm.price_from.value == ""){
			alert("Please, enter price from.");
			return false;
		}
		if(frm.price_to.value == ""){
			alert("Please, enter price to.");
			return false;
		}
		if(frm.shipping_price.value == ""){
			alert("Please, enter shipping price.");
			return false;
		}
		else{
			return true;
		}
	}
	function AccTopic(){
		frm = document.frmTopicLists;
		frm.modeTopic.value = "accept";
		frm.submit();
	}
	function DenyTopic(){
		frm = document.frmTopicLists;
		frm.modeTopic.value = "deny";
		frm.submit();
	}
	
	function AccLiquor(){
		frm = document.frmListLiquor;
		frm.modeLiquor.value = "accept";
		frm.submit();
	}
	function DenyLiquor(){
		frm = document.frmListLiquor;
		frm.modeLiquor.value = "deny";
		frm.submit();
	}


