$(function(){ //so
	$('form input[type=button]').click(function(){	
		var $sobox=$(this).prev();
		var querystring = $sobox.val();
		if(querystring==''||querystring==$sobox.get(0).defaultValue){
			alert('请输入要查询的关键字！');
			return false;
		}
		$(this).parent().submit();
		});
		
	$('form input[type=text]').focus(function(){
		if($(this).attr('value')==this.defaultValue) 
			$(this).val('');
	});
	$('form input[type=text]').blur(function(){
		if($(this).attr('value')=='') 
			$(this).val(this.defaultValue);
	});
});	


$(function(){ //#mmcenter,#topNav
	$('#mmcenter,#topNav,#tMgr,#tNav').hover(function(){
		$(this).addClass('on');
		$(this).children('ul').removeClass('fly');
	},function(){
		$(this).children('ul').addClass('fly');
		$(this).removeClass('on');
	});
});

function doZoom(size){
	var artiC = document.getElementById('artiC');
	if(!artiC){ return; }
	var artiChild = artiC.childNodes;
	artiC.style.fontSize = size + 'px';
	for(var i = 0; i < artiChild.length; i++){
		if(artiChild[i].nodeType == 1){
			artiChild[i].style.fontSize = size + 'px';
		}
	}
}

$(function(){ //navOn
	var urlPn=window.location.pathname;
	var pnSub=urlPn.substring(0,urlPn.indexOf('/',2));
	if(pnSub=='') return;
	var $aaaa=$('#nav li.on').children('a').text();
	$('#nav li.on').removeClass().children('a').html($aaaa);
	$('#nav').children('li').each(function(){		
		if($(this).children('a').attr('href').indexOf(pnSub)>=0){
				$(this).attr('class','on').children('a').wrapInner('<span></span>');	
		}
	});	
});

$(function(){//projector
	var $dt=$("#proj dt");
	projector($dt);
});

function projector(dt){
	var len=dt.length;
	var index=0;
	var adTimer;
	dt.mouseover(function(){
		index = dt.index(this);
		project(index,dt);
	}).eq(0).mouseover();

	dt.parent().hover(function(){
		clearInterval(adTimer);
	},function(){
		adTimer=setInterval(function(){
			project(index,dt);
			index++;
			if(index==len){index=0;}
		},3000);
		}).trigger('mouseleave');
}

function project(index,dt){
	var dd=dt.next("dd");
	var showH=dd.height();
	dd.stop(true,false).animate({top:-showH*index},0);
	dt.removeClass('on')
		.eq(index).addClass('on');
}
	

function moveup(li){
	var len=li.length;
	var heig=li.height();
	var pheig=li.parent().height();
  var n=Math.ceil(pheig/heig);
	var index=0;
	var adTimer;
	li.parent().hover(function(){
		clearInterval(adTimer);
	},function(){
		adTimer=setInterval(function(){
			li.stop(true,false).animate({top:-heig*index},100)
			index++;
			if(index==len-n){index=0;}
		},2000);
		}).trigger('mouseleave');
};	


function faqCkst(val,val1){//faqCheckstate
	if(val1=="answer"){
		var cust_id=document.getElementById("cust_id").value;
		if(cust_id==""||cust_id==null){
			if(confirm('你想登陆后再进行回答吗？')){
				window.location.href="/member/index.html";
			}else{
				window.location.href="/edu/faq/aiwen_answer.jsp?question_id="+val;
			}
		}else{
				window.location.href="/edu/faq/aiwen_answer.jsp?question_id="+val;
		}
	}
	if(val1=="view"){
		window.location.href="/edu/faq/aiwen_answer.jsp?state1=getanswerall&state=after&question_id="+val;
	}
}


String.prototype.Trim  = function() { return  this.replace(/(^\s*)|(\s*$)/g,  ""); } 
String.prototype.LTrim = function() { return  this.replace(/(^\s*)/g,  ""); }  //删除字符串左端的空格
String.prototype.RTrim = function() { return  this.replace(/(\s*$)/g,  ""); } //删除字符串右端的空格

$(function(){//ajaxKeyword
	var date = Math.random();
	var html = $.ajax({
	  url: "/templates/default/jsp/ajaxKeyword.jsp?limit=7&iStart=0&date="+date,
	  async: false
	}).responseText;//发送同步ajax请求
	/*document.getElementById("keywordproduct").innerHTML=html;	 
	document.body.oncopy = function () { 
	setTimeout( function () { 
		var text = getClipboard();
		if (text) { 
		text = text + "\r\n<a href='"+document.location.href+"'>"+document.title+"</a>"; 
		copy2Clipboard(text);
	} 
		}, 1000 ) 
		}*/
});

function getAD(adv,ad_id,type,width,height){ //广告位(对应div那个id)，ad_id:广告id,type:广告类型,width:图片宽，height：图片高
  var adv_content = $.ajax({
		  url: "/templates/default/jsp/getAd.jsp?ad_id="+ad_id+"&ad_type="+type+"&width="+width+"&height="+height+"&"+Math.random(),
		  async: false
		 }).responseText;
  //document.getElementById(adv).innerHTML=adv_content;
}

function loadUrl(){location.href='/member/leaveWordsMgr/addLeavewords.jsp';}

function showErrorMessage(){alert("您好！请登录后留言！");} //显示留言提示函数

function showLogin(val){ //显示登录提示函数
	alert("您好！请您先登录！");
	location.href="/member/index.html?comeurl="+val;
}
function clearInput(obj){	obj.value="";}

function strProc(str,len,tof){ //截取字符串 str字符串　len字符串长度  tof　1追加点　0不追加
	str=str.replace(/<[^<|^>]+>/g,"");
	if(str.length>len)
		if(tof=="1")
			document.write(str.substring(0,len)+"..");
		else
			document.write(str.substring(0,len));
	else
			document.write(str);
}

function isLogin(){ //是否登录
	if(document.getElementById("se_cust_id")==null||document.getElementById("se_cust_id").value=="")
		return false;
	else
		return true;
}

function leaveWords(cust_id,user_id,word_type){ //留言
	if(isLogin()){
		if(cust_id==document.getElementById("se_cust_id").value)
		{alert("不可以给自己留言！");return ;}
		openUrlProc("/member/leaveWordsMgr/addLeavewords.jsp?cust_id="+cust_id+"&user_id="+user_id+"&word_type="+word_type);
		//var strurl="/member/leaveWordsMgr/addLeavewords.jsp?cust_id="+cust_id+"&user_id="+user_id+"&word_type="+word_type;
		//window.open(strurl);
	}else
		alert("请您登录后留言！");
}

function isAdmin(){ //管理员
	if(document.getElementById("se_cust_type")!=null && document.getElementById("se_cust_type").value=="0")
		return true;
	else
		return false;
}

function isMember(){ //企业会员
	if(isLogin() && document.getElementById("se_cust_type").value=="1" )
		return true;
	else
		return false;
}

function isUser(){ //个人会员
	if(isLogin() && document.getElementById("se_cust_type").value=="2" )
		return true;
	else
		return false;
}

function openUrlProc(url){ //进入管理员或会员后台
	if(isAdmin() && url.indexOf('member')!=-1){
		alert("您是管理员!");
		return ;
	}
	if( !isAdmin() && url.indexOf('admin')!=-1){
		alert("您不是管理员!");
		return ;
	}
	var admin = "/admin/mainMenu/default.jsp?comeurl="
	var memeber ="/member/mainMenu/default.jsp?comeurl=";
	if(isAdmin()){
		location.href=admin+url;
	}else if( isMember() || isUser() ){
		location.href=memeber+url;
	}else{	
		var url=window.location.pathname;
		showLogin(url);
	}
	return ;
}

function openUrl(url){	//打开窗口
	window.open(url);
}

function AddFavorite(sURL, sTitle){ //添加到收藏夹
    try{
       window.external.addFavorite(sURL, sTitle);
    }catch (e){
      try{
          window.sidebar.addPanel(sTitle, sURL, "");
      }
      catch (e){
          alert("加入收藏失败，请使用Ctrl+D进行添加");
      }
    }
}

function SetHome(obj,vrl){ //设置首页
  try{
      obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
  }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',vrl);
      }
  }
}


function setSearchType(val)
{
	if(val==1){
		document.getElementById("querystring").value="请输入产品名称";
		document.getElementById("xype").value=1;
	}if(val==2){
		document.getElementById("querystring").value="请输入公司名称";
		document.getElementById("xype").value=2;
	}if(val==3){
		document.getElementById("querystring").value="请输入供应名称";
		document.getElementById("xype").value=3;
	}if(val==4){
		document.getElementById("querystring").value="请输入求购名称";
		document.getElementById("xype").value=4;
	}if(val==5){
		document.getElementById("querystring").value="请输入资讯名称";
		document.getElementById("xype").value=5;
	}if(val==6){
		document.getElementById("querystring").value="请输入品牌名称";
		document.getElementById("xype").value=6;
	}

}
function Search(){
		var type=document.getElementById("xype").value;
		var value=document.getElementById("querystring").value.Trim();
		if(value.indexOf("请输入产品名称")>-1){value=value.replace("请输入产品名称","");}
		else if(value.indexOf("请输入公司名称")>-1){value=value.replace("请输入公司名称","");}
		else if(value.indexOf("请输入供应名称")>-1){value=value.replace("请输入供应名称","");}
		else if(value.indexOf("请输入求购名称")>-1){value=value.replace("请输入求购名称","");}
		else if(value.indexOf("请输入资讯名称")>-1){value=value.replace("请输入资讯名称","");}
		else if(value.indexOf("请输入品牌名称")>-1){value=value.replace("请输入品牌名称","");}
		if(value==""||value==null)
		{	if(type=="")alert("请选择分类进行查询");
			else if(type==1)alert("请输入产品名称");
			else if(type==2)alert("请输入公司名称");
			else if(type==3)alert("请输入供应名称");
			else if(type==4)alert("请输入求购名称");
			else if(type==5)alert("请输入资讯名称");
			else if(type==6)alert("请输入品牌名称");
			document.getElementById("querystring").focus();
			return false;
		}else if(type==""){
			alert("请选择分类进行查询");
			return false;
		}
	document.search_form.submit();
}

function clearKey(){
	document.getElementById("querystring").value="";
}

