// JavaScript Document

//菜单切换
function menut(id)
{
	$('.top_menu_main_son').hide();
	document.getElementById('crcf').style.backgroundImage='';
	document.getElementById('dzcy').style.backgroundImage='';
	document.getElementById('xrsp').style.backgroundImage='';
	document.getElementById(id).style.background='url(/images/top_menu_main_top_a_hover.jpg) bottom no-repeat';
	document.getElementById(id+'_son').style.display='';
}




//设为首页
function SetHome(obj){
        var url=window.location.href;
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        }
                        catch (e) {
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',url);
                 }
        }
}
//添加到收藏夹
function AddFavorite()
{
    var url=window.location.href;
    try
    {
        window.external.addFavorite(url, document.title);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(document.title, url, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

var NowId001="";
function ChnageLeftBornd1(id)
{
	if(NowId001!=id)
	{
		$('.step4_text').css("fontWeight","lighter");
		$('#'+id+'_text').css("fontWeight","bold");
		
		$('.step4_Maxpic').css("display","none");
		$('#'+id+'_Maxpic').fadeIn("200");
		
		$('.CFSetp4').css('borderRight','1px solid #6bb171');
		$('#'+id).css('borderRight','none');
		NowId001=id;
	}
}

/*弹出菜谱*/
function DoPopCaiPu(E_char,pageno)
{
	$('#PopCaiPu').html("<ul><li style='color:#ccc'><img src='/images/loading2.gif' align='absmiddle' />&nbsp;查询数据中...</li></ul>");
	$('#PopCaiPu').slideDown('slow',function(){
										$('#PopCaiPu').load('/inc/DoFunction.php?action=SearchCaiByFirstPY&pinying='+E_char+'&pageno='+pageno);
										});
}

/*复制到剪切板*/
function copyToClipboard(txt) {   
     if(window.clipboardData) {   
       window.clipboardData.clearData();   
       window.clipboardData.setData("Text", txt); 
	  alert("已经复制好了! ^_^"); 
     } else if(navigator.userAgent.indexOf("Opera") != -1) {   
      window.location = txt;   
     } else if (window.netscape) {   
      try {   
       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
      } catch (e) {   
       alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");   
      }   
      var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
      if (!clip)   
       return;   
      var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
      if (!trans)   
       return;   
      trans.addDataFlavor('text/unicode');   
      var str = new Object();   
      var len = new Object();   
      var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
      var copytext = txt;   
      str.data = copytext;   
      trans.setTransferData("text/unicode",str,copytext.length*2);   
      var clipid = Components.interfaces.nsIClipboard;   
      if (!clip)   
       return false;   
      clip.setData(trans,null,clipid.kGlobalClipboard);   
      alert("已经复制好了! ^_^");   
     }   
    }
	
/*提交菜的评论*/
function PostCriticism(Xid)
{
	if(Xid!="")
	{
		$('#AjaxReturnBox').html("&nbsp;<img src='/images/loading2.gif' align='absmiddle' />...");
		//$('#AjaxReturnBox').load("../inc/DoFunction.php?action=PostCriticism","checkcode="+escape($('#checkcode').val())+"&content="+escape($('#content').val())+"&GuestQQ="+escape($('#GuestQQ').val())+"&GuestName="+escape($('#GuestName').val())+"&Xid="+Xid);
		
		
			$.ajax({
				 type: "POST",
				 url: "/inc/DoFunction.php?action=PostCriticism",
				 data:"checkcode="+encodeURIComponent($('#checkcode').val())+"&content="+encodeURIComponent($('#content').val())+"&GuestQQ="+encodeURIComponent($('#GuestQQ').val())+"&GuestName="+encodeURIComponent($('#GuestName').val())+"&Xid="+Xid,
				 cache:false,
				 error:function(e){alert(e+"Try Again!");},
				 success: function(result)
				 {
					$('#AjaxReturnBox').html(result);
				 }
				}).responseHtml;
	}
	
}
function RefurbishRndCai()
{
	$('#RndCai2').load("/inc/RndCaiName.php?action=xxx");
}

function DoVistHistory(url,tit) //浏览记录
{
	
	if($.cookie('VisitHistoryCookie')==null)
	{
		document.getElementById('VisitHistoryBox').innerHTML="<li>·<a href=\"javascript:\">无最近浏览记录</a></li>";
	}
	else
	{
		var aa=$.cookie('VisitHistoryCookie');
		var bb=aa.split(";");
		var cc="";
		var len=10;
		if(bb.length<len)len=bb.length-1;
		for(var i=0;i<len;i++)
		{
			if(bb[i]!="")
			{
				cc+="<li>·<a href=\""+bb[i].split(',')[0]+"\" title=\""+bb[i].split(',')[1]+"\">"+bb[i].split(',')[1]+"</a></li>";
			}
		}

		document.getElementById('VisitHistoryBox').innerHTML=cc;
	}
	//if($.cookie('VisitHistoryCookie').indexOf(url)<0)
	if(tit!='')
	{
		$.cookie('VisitHistoryCookie',url+','+tit+';'+$.cookie('VisitHistoryCookie'),{ expires: 7});	
	}
}
function CleanVistHistory()
{
	$.cookie('VisitHistoryCookie',null);
}

//搜索转换
function dosearch()
{
	var searchKeyword=document.forms['search'].searchKeyword.value;
	searchKeyword=searchKeyword.replace("_","");
	var searchList=document.forms['search'].searchList.value;
	searchList=searchList.replace("_","");
	if(searchKeyword.replace(" ","")!="")
	{
		document.location.href='http://www.dazhongcai.com/search_'+encodeURI(searchKeyword)+'_'+encodeURI(searchList)+".htm";
	}
	else
	{
		alert('输入点搜索关键词吧!');
	}
}
//搜索转换结束

//在光标处插入文字
//<textarea onselect="setCaret(this);" onclick="setCaret(this);"     onkeyup="setCaret(this);" >例子例子例子例子例子</textarea>
//<input   type="button"   value="插入"  onclick="insertAtCaret(this.form.tarea,this.form.textfield.value);"/>
function setCaret (textObj)
{   
	if   (textObj.createTextRange)   {   
	textObj.caretPos   =   document.selection.createRange().duplicate();   
	}   
}   
function insertAtCaret(textObj,textFeildValue)   
{   
	if(document.all){     
	if(document.getElementById(textObj).createTextRange   &&   document.getElementById(textObj).caretPos)   {   
		var   caretPos   =   document.getElementById(textObj).caretPos;   
		caretPos.text   =   caretPos.text.charAt(caretPos.text.length   -   1)   ==   '   '   ?textFeildValue   +   '   '   :   textFeildValue;   
	}else{   
		document.getElementById(textObj).value   =   textFeildValue;   
	}   
	}else{   
	if(document.getElementById(textObj).setSelectionRange){   
	var   rangeStart   =   document.getElementById(textObj).selectionStart;   
	var   rangeEnd   =   document.getElementById(textObj).selectionEnd;   
	var   tempStr1   =   document.getElementById(textObj).value.substring(0,rangeStart);   
	var   tempStr2   =   document.getElementById(textObj).value.substring(rangeEnd);   
	document.getElementById(textObj).value   =   tempStr1   +   textFeildValue   +   tempStr2;   
	}else{   
	alert("This   version   of   Mozilla   based   browser   does   not   support   setSelectionRange");   
	}   
	}
	document.getElementById(textObj).focus();
} 
//在光标处插入文字_结束

//留言添加表情
function addface(code)
{
	//#content 留言框的ID
	//alert(code);
	code="[D-"+code+"]";
	
	insertAtCaret("content",code);
}
//留言添加表情_结束


//创建和存储 cookie
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())
}
//检查是否已设置 cookie
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 ""
}