// JavaScript Document
	function timeline(e,url) {

		var div = document.getElementById('timeline');
		var elms = div.getElementsByTagName("*");
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];
			if (elm.id != "") {
				//alert(elm.id+':'+elm.style.backgroundColor);
				elm.style.backgroundColor = "#b3e6ea";
			}			
		}
		
		e.style.backgroundColor = "#027382";
		var img = document.getElementById('timeline_img');
		
		img.src = url;
		
	}
	
	function Changetimeline(e, _div) {
		
		var div = document.getElementById('timeline');
		var elms = div.getElementsByTagName("*");
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];
			if (elm.id != "") {
				//alert(elm.id+':'+elm.style.backgroundColor);
				elm.style.backgroundColor = "#b3e6ea";
			}			
		}
		
		var div = document.getElementById('timeline_img');
		var elms = div.getElementsByTagName("div");
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];
			elm.style.display ="none";
		}		
		_div = document.getElementById(_div);
		_div.style.display ="block";
		e.style.backgroundColor = "#027382";
		
	}
	
	function over(e, id) {
		var div = document.getElementById(id);
		var elms = div.getElementsByTagName('a');
		
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];		
			var color = elm.style.backgroundColor;			
			if (color != "#027382") {
				if (color != "rgb(2, 115, 130)") {
					if ( (elm.id != "") && (elm.id != e) ) {				
						elm.style.backgroundColor = "#b3e6ea";				
					}			
				}
			}
		}
		
		e = document.getElementById(e);	
		var _color = e.style.backgroundColor;
		//alert(e.style.backgroundColor);
		if ( (_color == "#027381") || (_color == "rgb(2, 115, 129)") ) {
			e.style.backgroundColor = "#b3e6ea";
		} else if ((_color == "#b3e6ea") || (_color == "rgb(179, 230, 234)")) {
			e.style.backgroundColor = "#027381";
		}
		
	}	
	
	function out(id) {		
		var div = document.getElementById(id);
		var elms = div.getElementsByTagName('a');
		
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];		
			var color = elm.style.backgroundColor;			
			if (color != "#027382") {
				if (color != "rgb(2, 115, 130)") {
					if ( (elm.id != "") ) {				
						elm.style.backgroundColor = "#b3e6ea";				
					}			
				}
			}
		}
	}	
	
	function over2(e, id) {

		var div = document.getElementById(id);
		var elms = div.getElementsByTagName('div');
		
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];		
			var color = elm.style.backgroundColor;			
			
			if (color != "#027382") {
				if (color != "rgb(2, 115, 130)") {
					if ( (elm.id != "") && (elm.id != e) ) {				
					
						elm.style.backgroundColor = "#f9efc9";		
						elm.style.color ="#7e7862";
					}			
				}
			}
		}
		
		e = document.getElementById(e);	
		var _color = e.style.backgroundColor;
		//alert(e.style.backgroundColor);
		if ( (_color == "#f9efc9") || (_color == "rgb(249, 239, 201)") ) {
			e.style.backgroundColor = "#06737e";
			e.style.color ="#FFFFFF";
		} else if ((_color == "#06737e") || (_color == "rgb(6, 115, 126)")) {
			e.style.backgroundColor = "#f9efc9";
			e.style.color ="#7e7862";
		}
		
	}	
	
	function out2(id) {		
		
		var div = document.getElementById(id);
		var elms = div.getElementsByTagName('div');
		
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];		
			var color = elm.style.backgroundColor;			
			if (color != "#027382") {
				if (color != "rgb(2, 115, 130)") {
					if ( (elm.id != "") ) {				
						elm.style.backgroundColor = "#f9efc9";		
						elm.style.color ="#7e7862";		
					}			
				}
			}
		}
		
	}	

function grayscale(image, bPlaceImage)
{
  var myCanvas=document.createElement("canvas");
  var myCanvasContext=myCanvas.getContext("2d");

  var imgWidth=image.width;
  var imgHeight=image.height;
  // You'll get some string error if you fail to specify the dimensions
  myCanvas.width= imgWidth;
  myCanvas.height=imgHeight;
//  alert(imgWidth);
  myCanvasContext.drawImage(image,0,0);
  // this function cannot be called if the image is not rom the same domain.  You'll get security error
  var imageData=myCanvasContext.getImageData(0,0, imgWidth, imgHeight);
  for (i=0; i<imageData.height; i++)
  {
    for (j=0; j<imageData.width; j++)
    {
      var index=(i*4)*imageData.width+(j*4);
      var red=imageData.data[index];      
      var green=imageData.data[index+1];
      var blue=imageData.data[index+2];      
      var alpha=imageData.data[index+3];     
      var average=(red+green+blue)/3;       
         imageData.data[index]=average;      
         imageData.data[index+1]=average;
         imageData.data[index+2]=average;
         imageData.data[index+3]=alpha;            
    }
  }
  myCanvasContext.putImageData(imageData,0,0,0,0, imageData.width, imageData.height);
 // myCanvasContext.drawIMage(imageData,0,0);//,0,0, imageData.width, imageData.height);  
  
  if (bPlaceImage)
  {  
      var myDiv=document.createElement("div");  
      myDiv.appendChild(myCanvas);
      image.parentNode.appendChild(myCanvas);//, image);
  }
  return myCanvas.toDataURL();
}

	
	function prepareMouseOverImage(image, originalURL, effect)
	{
		image.mouseOverImage=originalURL;
		image.normalImage=grayscale(image, false);
		image.onload=function(){return true;};
		image.onmouseover=function()
		{			
			 this.src=this.mouseOverImage;
			 image.style.borderColor = "#06737e";
			 EffectsShowHide(1, effect);
		}
		
		image.onmouseout=function()
		{
			this.src=this.normalImage;
	 		image.style.borderColor = "#e4e4e4";
	 		EffectsShowHide(0, effect);
		}
		
		image.src=image.normalImage;	
		
	}
	
	function tips_out(e) {
		e.style.filter='progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
		e.style.borderColor = "#e4e4e4";
	}
	
	function tips_over(e) {

		e.style.filter='';
		e.style.borderColor = "#06737e";
	}
	
	
	
	function gallery_animate(type, e, effect) {		
		if (type == 0 ) { //type 0 : out
			e.style.filter='progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';
			e.style.borderColor = "#e4e4e4";
			EffectsShowHide(0, effect);
		} else if (type == 1 ) { //type 1 : over
			e.style.filter='';
			e.style.borderColor = "#06737e";
			EffectsShowHide(1, effect);
		}		
	}
	
	function showdiv(title, content) {
		var tbl = document.getElementById('tbl_tips');
		var elms = tbl.getElementsByTagName('div');
		
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];		
			var id = elm.id;
			if (id != "") {
				if (id.indexOf("tips_")!=-1) {
					elm.style.display = "none";
				}
				
				if (id.indexOf("tips_title")!=-1) {
					elm.style.display = "block";
				}
			}
		}
		
		var _title = document.getElementById(title);
		_title.style.display = "none";
		
		var _content = document.getElementById(content);
		_content.style.display = "block";
	}
	
	function GoTo(url){
		window.location=url;
	
	}	
	
	function runEffect(title, effect){
		var tbl = document.getElementById('tbl_tips');
		var elms = tbl.getElementsByTagName('div');		
		for(var i = 0, maxI = elms.length; i < maxI; ++i) {			
			var elm = elms[i];		
			var id = elm.id;
			if (id != "") {
				if (id.indexOf("tips_")!=-1) {
					var x = "#"+id;
					$(""+x+"").hide(selectedEffect,options,400);				
				}
				
				if (id.indexOf("tips_title")!=-1) {
					var x = "#"+id;
					$(""+x+"").show(selectedEffect,options,400);				
				}
				
				
			}
		}
		
		//get effect type from 
		var selectedEffect = "blind";
		var options="";
		//run the effect		
		$(""+title+"").toggle(selectedEffect,options,400);
		$(""+effect+"").toggle(selectedEffect,options,400);
	}
	
	function EffectsShowHide(type,effect){
		var selectedEffect = "blind";
		var options="";
		$(""+effect+"").toggle(selectedEffect,options,400);
	}
	
	function ChangePicture(action,image,upload,hidden) {
	var _image = document.getElementById(image);	
	var _upload = document.getElementById(upload);	
	var _hidden = document.getElementById(hidden);	

	if (action == 1) {
		_image.style.visibility='hidden';
		_image.style.display='none';
		
		_upload.style.visibility='visible';
		_upload.style.display='block';
		_hidden.value = 1;
	} else {		
		_image.style.visibility='visible';
		_image.style.display='block';
		
		_upload.style.visibility='visible';
		_upload.style.display='none';
		
		_hidden.value = 0;	
	}	
}

function actionTime(frm, act,id) {
	var _url = frm.action;
	_url = _url +"bakery";			
	var retval = false;
	
	if (act == 0 ) {
		if ( confirm('Are you sure want to delete this Year ?') ) {
			_url += "/deleteTime/"+ id;			
			retval = true;
		} 
	} else if (act == 1 ) {
		_url += "/AddTime/";			
		retval = true;
	}
	
	if (retval) {
		frm.action = _url;		
		frm.submit();
	} 			
}

function actionMenu(frm, act,id) {
	var _url = frm.action;
	_url = _url +"bakery";
	
	var e = document.getElementById('hd_type').value;
				
	var retval = false;
	
	if (act == 0 ) {
		if ( confirm('Are you sure want to delete this Menu ?') ) {
			_url += "/deleteMenu/"+ id + "/" + e;			
			retval = true;
		} 
	} else if (act == 1 ) {
		_url += "/AddMenu/";			
		retval = true;
	}
	
	if (retval) {
		frm.action = _url;		
		frm.submit();
	} 			
}


function actionGal(frm, act,id) {
	var _url = frm.action;
	_url = _url +"bakery";
	
	var e = document.getElementById('hd_type').value;				
	var retval = false;
	
	if (act == 0 ) {
		if ( confirm('Are you sure want to delete this item Gallery ?') ) {
			_url += "/deleteGallery/"+ id + "/" + e;			
			retval = true;
		} 
	} else if (act == 1 ) {
		_url += "/AddGallery/";			
		retval = true;
	}
	
	if (retval) {
		frm.action = _url;		
		frm.submit();
	} 			
}

function showDiv(div) {
	var e = document.getElementById(div);

	if (e.style.display == "none")
		e.style.display = "block";
	else 
		e.style.display = "none";
		
}

function actionArticle(frm, act,id) {
	var _url = frm.action;
	var ctg_id = document.getElementById('txt_ctg_id');
	_url = _url +"bakery";			
	var retval = false;
	
	if (act == 0 ) {
		if ( confirm('Are you sure want to delete this Article ?') ) {
			_url += "/deleteArt/"+ id+"/"+ctg_id.value;			
			retval = true;
		} 
	} else if (act == 1 ) {
		_url += "/AddNewArticle/"+ctg_id.value;			
		retval = true;
	} else if (act == 2 ) {
		_url += "/ListArticle/"+ctg_id.value;			
		retval = true;
	} else if (act == 3 ) {
		_url += "/ArticleDetail/"+id;			
		retval = true;
	} else if (act == 4 ) {
		_url += "/updateart/"+id;			
		retval = true;
	} 
	
	
	if (retval) {
		frm.action = _url;		
		frm.submit();
	} 			
}
