﻿jQuery.noConflict();
	function openSubMenu(id) {
		var x = document.getElementById("left_menu").insertCell(0);
		x.innerHTML = 'test';
	}
	
	function setSubTitle(title) {
		//document.getElementById("sub_title").innerHTML = title;
	}
	
	function setSubTitleSrc(subtitle_id) {
		// old method
		//document.getElementById("sub_title_gif").src = document.getElementById("subtitle_prefix").value + src + ".gif";
		// GD method
		document.getElementById("sub_title_gif").src = "users2/app/webroot/../../index.php/graph/subtitle_b/" + subtitle_id;
	}
	
	function Show_Loc_Map(map_num,locationmap_id){
		document.getElementById(locationmap_id).src = document.getElementById("locationmap_prefix").value + map_num + ".png";
	}
	
	function setContent(content) {
		document.getElementById("content").innerHTML = content;
	}
	
	function getOrderPrice() {
        var url = "<?=$html->url('/bunny/get_order_price')?>"
                    + "/" + document.getElementById("order_item").value;
        new Ajax.Request(url, {
            method: 'get',
            encoding: 'UTF-8',
            onSuccess: function(transport) {
                document.getElementById("price").innerHTML = transport.responseText.replace(/<!--(.)*-->/, "");
            }
        });

	}
	
	function cleanResponse(str) {
		return str.substring(str.indexOf("start:") + 6).replace(/<!--(.)*-->/, "");
	}
	
	function updateSelectBoxItem(url, from, to) {
        url = url + "/" + document.getElementById(from).value;
        new Ajax.Request(url, {
            method:'get',
            encoding: 'UTF-8',
            onSuccess: function(transport){
                var subject = document.getElementById(to);                
                var res = cleanResponse(transport.responseText).evalJSON(true);
                
                subject.length = res.length;
                if (subject.length > 0) {
                    subject.length++;
                    subject.options[0].text = "";
                    subject.options[0].value = "";
                    for (i = 1; i < subject.length; i++) {
                        subject.options[i].text = res[i - 1].text;
                        subject.options[i].value = res[i - 1].value;
                    }
                }
            },
            onFailure: function(){
            }
        });
    }

	function filter(page, limit) {
        new Ajax.Updater('itemDiv', 'wealth/shopping_items' + "/" + document.getElementById("price_filter").value + "/" + page + "/" + limit,
            {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'itemDiv']});
	}
    
    
	function getSubject() {
        var url = "<?=$html->url('/bunny/get_online_help_subject')?>"
                    + "/" + document.getElementById("type").value;
        new Ajax.Request(url, {
            method:'get',
            encoding: 'UTF-8',
            onSuccess: function(transport){
                var res = cleanResponse(transport.responseText).evalJSON(true);
                var subject = document.getElementById("subject");
                subject.length = res.length;
                if (subject.length > 0) {
                    subject.length++;
                    subject.options[0].text = "";
                    subject.options[0].value = "";
                    for (i = 1; i < subject.length; i++) {
                        subject.options[i].text = res[i - 1].text;
                        subject.options[i].value = res[i - 1].value;
                    }
                }
            },
            onFailure: function(){
            }
        });
    }
    
    function getDescription() {
        var url = "<?=$html->url('/bunny/get_online_help_description')?>"
                  + "/" + document.getElementById("subject").value;
        new Ajax.Request(url, {
            method: 'get',
            encoding: 'UTF-8',
            onSuccess: function(transport) {
                document.getElementById("description").value = cleanResponse(transport.responseText);
            }
        });
    }
    
    
    function show_more(){
    	var obj1 = document.getElementById("more");
    	obj1.style.display = 'none';
    	var obj2 = document.getElementById("more_1");
    	obj2.style.display = '';
    
    	var content = document.getElementById("inner_content");
    	var content1 = document.getElementById("inner_content_1");
    
    	content.style.display = 'none';
    	content1.style.display = '';
    }
  
    function hide_more(){
    	var obj1 = document.getElementById("more");
    	obj1.style.display = '';
    	var obj2 = document.getElementById("more_1");
    	obj2.style.display = 'none';
    
    	var content = document.getElementById("inner_content");
    	var content1 = document.getElementById("inner_content_1");
    
    	content.style.display = '';
    	content1.style.display = 'none';
    }

    
    function spantree(string){
    	
    	// 先將所有的子節點都標示為hidden
    	var all_child = $$('div.child');
    	
    	for(i=0; i<all_child.size(); ++i){		
    			$(all_child[i]).style.visibility = "hidden";
    	}
    	
    	
    
    	var children = string.evalJSON();
    	// 再將該節點的所有子點都標記成visible, 以玆識別
    	for(i=0; i<children.size();++i){
    			$(children[i]).style.visibility = "visible";
    	}
    
    
    	// 首先將所有不為該節點子點(hidden)的都設定為display = none
    	for(i=0; i<all_child.size(); ++i){
    		if(all_child[i].style.visibility == 'hidden'){
    			$(all_child[i]).style.display = "none";
    		}
    	}
    	
    	// 為該節點子節點的再進一步處理
    	if($(children[0]).style.display == "block"){
    		for(i=0; i<children.size();++i){
    			$(children[i]).style.display = "none";
    		}
    	}
    	else{
    		for(i=0; i<children.size();++i){
    			$(children[i]).style.display = "block";
    		}
    	}
    	
    	for(i=0; i<all_child.size(); ++i){
    		$(all_child[i]).style.visibility = "visible";
    	}
    	
    	
    }
    
    function hidechild(Obj_id){
    	//var all_child = $(Obj_id).getElementsByClassName('child');
    	var all_child = $$('div.child');
    	for(i=0; i<all_child.size(); ++i){ 
    			$(all_child[i]).style.display = "none";
    	}
    }
    
    function fontzoomin(Obj){
    	Obj.style.fontSize = "10pt"; 
    }
    
    function fontzoomout(Obj){ 
    	Obj.style.fontSize = "9pt"; 
    }

    function swap_pic(imgObj, imgSrc){
	imgObj.src= imgSrc;
    }

    function resetMarquee(){
	document.getElementById("itemDiv").scrollLeft = 0;
    }
	
	function show_help_detail(Obj) {
		var ans = jQuery(".help_ans");
		for(var i=0,ans;a=ans[i];i++)
			jQuery(a).attr("style","display:none;");
		var x = '#'+Obj;
		jQuery(x).attr("style","");
	}
	
	function CloseCurrentWin(strmsg){
		if (confirm(strmsg)) { 
			if(navigator.appName=="Microsoft Internet Explorer") {
				window.parent.window.opener=null;
				window.parent.window.close();
			} else if(navigator.appName=="Netscape") {
				top.window.opener = top;
				top.window.open('','_parent','');
				top.window.close();
				alert("由於您使用Firefox, 系統無法幫您關閉視窗, 請自行關閉你的視窗!謝謝!");
			}
		}
    }
	
	function Openurl(strurl, strtype){
		if (strtype==0) { 
			window.location = strurl;
		}
		if (strtype==1) { 
			window.open(strurl,'mywin');
		}
    }
	
	function ClearDiv(strDivName) {
		if (strDivName == '') {}
		else {
			var targetdivName = "#" + strDivName;
			var targetdiv = jQuery(targetdivName)
			targetdiv[0].innerHTML = "";
		}
	}

	function spantree1(obj){
    	
    	// 先將所有的子節點都標示為hidden
		jQuery(".menuchild").hide();
        var findid = obj.parentNode.id;
		var x = jQuery(".menuchild");
		click1 = false;
		for (i = 0; i < x.length;i++) {
			if (jQuery(x[i]).attr("id") == findid) {
				jQuery(x[i]).show();
			    if (!click1) {
					var y = jQuery(jQuery(x[i]).find('a')[0]).attr("href");
					new Ajax.Updater('content', y
            , {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'content']});
					click1 = true;
				}
			}
		}
    }

	function contentresize()
	{
//scrollHeight	
	

		//alert(jQuery('#content').width());
		//jQuery('#content').height(document.getElementById('content').scrollHeight);
		//jQuery('#outer_content').height(document.getElementById('content').scrollHeight);		
	}

   jQuery('#content').ready(function()
            {           
            
               // alert('測試用');                    
                //header 102
                //footer 37
                //
              //alert( jQuery(window).height());
              //alert(jQuery('#top').height());
               //alert(jQuery('#down').height());

		       //jQuery('#content').height(document.getElementById('content').scrollHeight);
  		       //jQuery('#outer_content').height(document.getElementById('content').scrollHeight);		
               //jQuery('#left_menu').height(document.getElementById('content').scrollHeight);
//               left_menu
               
            resize();
            });

function resize()
{

    var wh = jQuery(window).height() + 0 ;
    var th = jQuery('#top').height();
    var dh = jQuery('#down').height();
	var height = jQuery('#content').height() + 6;
	if (wh - th - dh > height)
		height = wh - th - dh;
    jQuery('#left_menu').height(height);
    jQuery('#outer_content').height(height);
    jQuery('#down').css('position','absolute');
    jQuery('#down').css('top', height+6);
    jQuery('#down').css('left',0);
    if (jQuery('#MWIframe').length != 0 )
          jQuery('#MWIframe').height( wh - th  - dh  -5 );

/*
    var ha = jQuery('#left_menu').height();

    var hb = jQuery('#content').height();
    
    var hc = jQuery('#top').height();
    if (ha > hb)
       hc = hc + ha;
    else 
       hc = hc + hb;

    jQuery('#down').css('top',hc - 10);
*/
} 

function jblockUI(idd){
	/*if(idd){
	   jQuery(idd).block({ message: '<div style="width:200px;height:50px;background:url(/users/app/webroot/img/bg-pleasewait.png)"><img src="/users/app/webroot/img/loading.gif" style="position:relative;top:15px;left:-55px"/></div>', css: { 
								            border: 'none', 
											padding: '15px', 
											backgroundColor: 'transparent', 
											opacity: '1', 
											color: '#fff' 
								} });		
	}else{
	   jQuery.blockUI({ message: '<div style="width:200px;height:50px;background:url(/users/app/webroot/img/bg-pleasewait.png)"><img src="/users/app/webroot/img/loading.gif" style="position:relative;top:15px;left:-55px"/></div>', css: { 
								            border: 'none', 
											padding: '15px', 
											backgroundColor: 'transparent', 
											opacity: '1', 
											color: '#fff' 
								} });		
	}*/
}

function junblockUI(idd){
	if(idd){
		jQuery(idd).unblock()	
	}else{
		jQuery.unblockUI()		
	}
}

function jblockUI_with_content(content,wwidth,hheight){
  de = document.documentElement;
  w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
 
  lleft=(w-wwidth)/2
  ttop=(h-hheight)/2
 
       jQuery.blockUI({ message: content, css: {
                                            width: wwidth+'px',
                                            border: 'none',
                                            padding: '0px',
                                            top: ttop+'px',
                                            left:lleft+'px', 
                                            backgroundColor: 'transparent',
                                            opacity: '1',
                                            color: '#fff',
                                            cursor: 'default'
                                } });       
}
function junblockUI_with_content(){
    jQuery.unblockUI()   
}



//用Javascript設定cookies   (cookies_name:cookies的名稱,value:cookies的值,expiredays:過期天數)
function JSsetCookie(cookies_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=cookies_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

//用Javascript取得cookies
function JSgetCookie(cookies_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(cookies_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + cookies_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 "";
}



function MM_showHideLayers1() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers1.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) 
	if (getElementById && ((obj=getElementById(args[i]))!=null)) { 
		obj1 = jQuery(obj);
		v=args[i+2];
		if (v=='show') {
			obj1.show();
		} 
		else {
			obj1.hide();
		}
	}
}

jQuery(window).resize(function()
            {
                resize();
            });

jQuery(document).ready(function(){
	if (!window.XMLHttpRequest) {
		jQuery('.menu_depth2').css('letter-spacing','0px');
		jQuery('.menu_depth2').css('text-indent','0px');
		}


});

function fixPng(png) {
   //alert("fixPng")
   var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if (badBrowser) {   	
	   var blank = new Image();
	
	   blank.src = '/users2/app/webroot/img/blank.gif';
	
	   var src = png.src;
	   //if (!png.style.width) { png.style.width = png.offsetWidth; }
	   //if (!png.style.height) { png.style.height = png.offsetHeight; }
	   if (!png.style.width) { png.style.width = png.w;; }
	   if (!png.style.height) { png.style.height = png.h; }	   
	   png.onload = function() { };
	   png.src = blank.src;
	   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
   }
}	

function say_hello(){
	alert("hello, I am in outside");
}

function redirect_when_logout(pre_url){
	window.location = '/users2/index.php/users/user_login' + pre_url;
}
            

