// JavaScript Document
///2009-08-24 debug 需要jquer1.3支持
///Created by IMT.
/// Last modified by IMT. 2010-08-12
//
///图片预读
///ImgUrlList 为img 路径列表
///
function ImgAdvancePreloader(ImgUrlList)
{
//图片预读
var cc = ImgUrlList, cci = 0, url;
function ImgPreloader() {
url = cc.eq(cci).attr("href");
if (url && url.length < 1) {
for (; cci < cc.length; cci++) {
url = cc.eq(cci).attr("href");
if (url.length > 0) {
break;
}
}
}
if (!url) return;
imagePreloader = new Image; imagePreloader.src = url;
if (imagePreloader.complete) {
cci++;
ImgPreloader();
} else {
$(imagePreloader).unbind().bind('load', function() {
cci++;
ImgPreloader();
});
}
}
$(window).load(function() {
setTimeout(ImgPreloader, 1000);
});
}
//eCss: 播放的div组的css 统一css 并且页面中唯一使用;pId:点击向前的id;nId:点击向后的id;sNum:显示个数(默认是3);
//sstime:播放时间(毫秒);autoStart:true 为自动播放(默认),false禁止自动播放;playTime:自动播放时间(毫秒);方向:‘left’ 或者‘right’
function slideShowFn(eCss,pId,nId,sNum,sstime,autoStart,playTime,direction){
if(typeof eCss !="string" || (typeof pId !="string" && typeof nId !="string")) return false;
if(typeof $ =="function")
{
$(function(){
var ssctliste = $("."+eCss),ssctlist=[],ssi=0,tempsse,bdir= true;
if(typeof sstime != "number") sstime = 600; // defalut parameters set value
if(typeof sNum != "number")sNum = 2; else sNum --;
if(typeof autoStart != "boolean" )
{
autoStart = true;
}
else if(autoStart)
{
if(typeof playTime != "number") playTime = 1000;
if(direction == "right" ) bdir= false; else bdir= true ;
}
ssctliste.each(function(i){
tempsse = $(this);
ssctlist.push(tempsse);
tempsse.hover(function(){if(autoNextTimer)clearInterval(autoNextTimer);},function(){ssOutPlayControl()});
if(i > sNum)
{
tempsse.hide();
}
}
);
if(ssctlist.length > 0)
{
var pssbusy=false,nssbusy=false,sscount =ssctlist.length -1, autoNextTimer ;
if(typeof pId == "string")
{
$("#"+pId).css("cursor","pointer").click(function(){
pssbusy = true;
if(!nssbusy)
{
var te,ee,se, m_ssi =ssi;
if( ssi > 0 )
{
ssi-=1;
}
else
{
ssi = sscount;
}
if(m_ssi==0)
{
te = sscount;
}
else
{
te= m_ssi-1;
}
ee = ((m_ssi+sNum) > sscount) ? m_ssi- sscount+sNum -1 :m_ssi+sNum;
$(ssctlist[m_ssi]).before(ssctlist[te]);
ssctlist[te].show(sstime); //
ssctlist[ee].hide(sstime,function(){pssbusy=false});
}
}).hover(function(){if(autoNextTimer)clearInterval(autoNextTimer);},function(){ssOutPlayControl()});
}
if(typeof nId == "string")
{
$("#"+nId).css("cursor","pointer").click(function(){
nssbusy= true;
if(!pssbusy)
{
var te,ee,se, m_ssi =ssi;
if( ssi < sscount )
{
ssi+=1;
}
else
{
ssi= 0;
}
if(m_ssi==0)
{
ee = sscount;
}
else
{
ee= m_ssi-1;
}
te = ((m_ssi+sNum+1) > sscount) ? m_ssi- sscount+sNum:m_ssi+sNum+1;
ssctlist[m_ssi].hide(sstime,function(){ssctlist[ee].after(ssctlist[m_ssi]);nssbusy=false;} ); //
ssctlist[te].show(sstime);
}
}).hover(function(){if(autoNextTimer)clearInterval(autoNextTimer);},function(){ssOutPlayControl()});;
}
function ssOutPlayControl()
{
if(autoStart)
{
if(bdir&& typeof nId == "string")
{
autoNextTimer = setInterval(function(){ $("#"+nId).trigger("click");},playTime);
}
else if(typeof pId == "string")
{
autoNextTimer = setInterval(function(){ $("#"+pId).trigger("click")},playTime);
}
}
}
ssOutPlayControl();
}
});
}
}
///
///设置cookie
///
function setCookie(c_name,value,expiredays,domian,pth)
{
var exdate=new Date(),ckstr;
exdate.setDate(exdate.getDate() + expiredays);
ckstr = c_name+ "=" +escape(value)+";";
if(typeof expiredays != "undefined" )ckstr+="expires="+exdate.toGMTString()+";";
if(typeof domian== "string")ckstr+="domain="+ domian+";";
if(typeof pth == "string")
{
ckstr+="patch="+ pth+";";
}
else
{
ckstr += "patch=//;";
}
document.cookie = ckstr;
};
///
///获取cookie
///
function getCookie(c_name,domian)
{
var tcookie = document.cookie,reg = "/"+c_name+"=([^;]*)/"; //(\\d+)
if(tcookie.length <1)return false;
result = tcookie.match(eval(reg));
if(result)
{
if(result.length > 1)
{
return unescape(result[1]);
}
}
return false;
};
///
///js获取值
///
function AjGetData(u,qE,cB)
{
busy = true;
$.ajax({
type: "post",
dataType: "text",
processData: false,
url: u,
data: qE ,
success: function(msg){
busy = false;
if (typeof msg == "string")
{
if(msg.length >1)
{
cB(msg);
}
}
}
,
error: function(Request){
busy = false;
//Request.readyState
}
});
};
///绑定获取数据
///sE:输入框对象,dFName 获取数据文件名称 包括路径,hE:隐藏域id
function BindSelEGetData(sE,gFName,sN,hE,qE,sP,sP2)
{
$(function(){
if(typeof sE !="string"||sE=="") return false;
if(typeof gFName !="string"||gFName=="") return false;
if(typeof sN !="number") sN =3;
if(typeof qE !="string"||qE=="")qE = "rValue";
if(typeof sP !="string"||sP=="")sP = "|_";
if(typeof sP2 !="string"||sP2=="")sP2 = "#_";
var jsE = $("#"+sE),d =[],hD,str,tempA,eL,dE,jhE,Vsign=false,jseV,busy=false;
GAJData();
function GAJData()
{
jsE.unbind("keydown");
jsE.keydown(function(){setTimeout(function(){
var v = jsE.val();
if(jsE.val().length >= sN)
{
//
AjGetData(gFName,qE+"="+v,OpenRelDiv) ;
}
} ,200);
});
};
///
///添加数据到层
//
function AddDivLi(eData)
{
d.length = 0;
if(eData.indexOf(sP) > 0)
{
tempA = eData.split(sP);
if(eData.indexOf(sP2) > 0)
{
var _tempA;
hD=[];
hD.lenght =0;
for(ai = 0 ; ai < tempA.length;ai++)
{
_tempA = tempA[ai].split(sP2);
d.push(_tempA[0]);
hD.push(_tempA[_tempA.length-1]);
}
}
else
{
for(ai = 0 ; ai < tempA.length;ai++)
{
d.push(tempA[ai]);
}
}
}
else
{
d.push(eData);
}
if(d.length <1)return;
//a = ["Usa","Japan","China"];
str = "
";//- USA
- Japan
str += handleData(d);
str +="
";
if(typeof dE !="undefined")
{
dE.empty();
dE.html(str);
dE.show();
}
else
{
ShowSelDiv(sE,str,"bottom","left","no");
}
eL =$("#select_List li");
//点击事件
if( typeof hD =="undefined" || hD.constructor != Array )
{
//d=null;
eL.click(function(){
jsE.val($(this).text());
jhE.val($(this).text());
dE.slideUp("fast");
});
}
else
{
eL.each(function(i){
$(this).click(function(){
jsE.val($(this).text());
jhE.val((hD[i]));
dE.slideUp("fast");
});
});//.click(function(){alert($(this).text())});
}
Vsign = false;
};
///
///在关联弹出层
///
///OpenRelDiv()
/// sE 弹出对象id ,eData:处理的数据,hE:隐藏值id
function OpenRelDiv(eData)
{
// if(typeof sE !="string") return false;
// if(typeof eData !="string") return false;
jhE = $("#"+hE);
jsE.unbind("keydown");
AddDivLi(eData);
dE = $("#"+sE+"seldiv");//.hover(function(){$(this).show();},function(){$(this).hide();});
//eL =$("#select_List li");
// jsE = $("#"+sE);
jsE.keydown(function(){
setTimeout(function(){
jseV = jsE.val();
if( jseV.length < sN)
{
dE.hide();
dE.empty();
if(!Vsign )Vsign = true;
return;
}
dE.slideDown("normal");
if( Vsign && jseV.length >= sN&& !busy)//重新搜索
{
//清除对象
//dE.replaceWith();
dE.hide();
dE.empty();
AjGetData(gFName,qE+"="+jseV,AddDivLi);
// return;
}
if( eL.text().indexOf(jseV)>=0)
{
eL.each(function(){
if( $(this).html().indexOf("= 0 || $(this).html().indexOf("=0 )
{
$(this).find("a").html($(this).text().replace( jseV ,""+ jseV +""));
}
else
{
$(this).html($(this).text().replace( jseV ,""+ jseV +""));
}
});
}
else
{
dE.hide();
dE.empty();
Vsign = true;
}
} ,200);});
}
});
};//end-----BindSelEGetData
///处理数据 返回html
function handleData(d)
{
if( typeof d =="undefined" || d.constructor != Array )return "";
var lstr="";
for(i = 0 ;i< d.length;i++)
{
lstr+=""+ d[i] +"";
}
return lstr;
}
///
///显示选择层
///
///e :弹出位置对象,str:弹出内容,eP:弹出相对对象位置偏移x,ePy:相对偏移y,eD:消隐方式 (blur 离开焦点消除【默认】,click,点击消除等,或no 不处理),dcss:弹出层样式
function ShowSelDiv(e,str,ePx,ePy,eD,dcss)
{
if(typeof e != "string") return;
var eofs,ele;
ele = $("#"+e);
eofs = ele.offset();
if(typeof ePx =="string")
{
if(ePx == "top")
ePx = ele.innerHeight()+2;
if(ePx == "bottom")
ePx = -( ele.innerHeight()+2);
}
else if(typeof ePx != "number")
{
ePx = 20;
}
if(typeof ePy == "string")
{
if(ePy == "left")
ePy = 0;
if(ePy == "right")
ePy = -ele.innerWidth();
}
else if(typeof ePy !="number")
{
ePy = 0 ;
}
if(typeof dcss != "string" )
{
dcss = "arrowDownTest";
}
appDivCke(eofs.top-ePx ,eofs.left-ePy ,e+"seldiv",str,dcss);
if(typeof eD=="undefined")//层事件
{
ele.one("blur",function(){$("#"+e+"seldiv").replaceWith()});//replaceWithempty();
}
else if(eD!="no")
{
ele.one(eD,function(){$("#"+e+"seldiv").replaceWith()});
}
};
///
///正则检测为空函数
///
///ckNullorEmpty(sE[,eStr,reg][,fc])
///检测对象id
///提示错误输出语句
///正则语句
///默认值句
///错误输出容器对象id 如果不存在则弹出提示
///是否出错焦点
function RegCkElement(sE,eStr,reg,dfStr,oE,fc)
{
var ele = document.getElementById(sE);
if(!ele) return false;
if(typeof dfstr != "string")dfstr="";
if(typeof fc !="boolean") fc= true;
if(typeof ele.value == "string"&& ele.value.replace(/\s*/g, "") !="" && ele.value !=dfstr)
{
if(typeof reg == "string")
{
try{
var pattern = eval(reg);
} catch(e){
var pattern= new RegExp(reg);
}
}else if(typeof reg == 'object'){
var pattern = reg;
} else {
var pattern= new RegExp;
}
var flag=pattern.test(ele.value);
if(!flag){
if(typeof eStr =="string")
{
ShowE(sE,eStr,oE);
}
if(fc)FocusE(ele);
return false;
}
return true;
}
if(typeof eStr =="string")
{
ShowE(sE,eStr,oE);
}
if(fc)FocusE(ele);
return false;
};
///
///检测数字
///
///sE 检测对象,eStr:错误提示信息,oE:单独定义显示错误的对象容器 ,fc 错误后是否聚焦 默认true
function IsEmptyOrNotNum(sE,eStr,dfStr,oE,fc)
{
var ele = document.getElementById(sE);
if(!ele) return false;
if(typeof dfstr != "string")dfstr="";
if(typeof fc !="boolean") fc= true;
if(typeof ele.value == "string"&& ele.value.replace(/\s*/g, "") !=""&&ele.value !=dfStr)
{
if(isNaN(ele.value))
{
if(typeof eStr =="string")
{
ShowE(sE,eStr,oE);
}
if(fc)FocusE(ele);
return false;
}
return true;
}
if(typeof eStr =="string")
{
ShowE(sE,eStr,oE);
}
if(fc)FocusE(ele);
return false;
}
///
///检测字符串
///
///sE 检测对象,eStr:错误提示信息,oE:单独定义显示错误的对象容器 ,fc 错误后是否聚焦 默认true
function StrIsNullOrEmpty(sE,eStr,dfStr,oE,fc)
{
var ele = document.getElementById(sE);
if(!ele) return false;
if(typeof dfstr != "string")dfstr="";
if(typeof fc !="boolean") fc= true;
if(typeof ele.value == "string" && ele.value.replace(/\s*/g, "") !=""&&ele.value!=dfStr)
{
return true;
}
if(typeof eStr =="string")
{
ShowE(sE,eStr,oE);
}
if(fc)FocusE(ele);
return false;
}
///
///设置对象焦点
///
function FocusE(e)
{
if(e)
{
if(e.getAttribute("visible")=="true"||e.style.display !="none")
{
e.focus();
}
}
};
///
///显示错误提示
///
function ShowE(sE,str,oE)
{
var ele;
// str = str.fontcolor("red");
// str = str.bold();
ele = document.getElementById(oE);
if(ele)
{
ele.style.display = "";
ele.innerHTML = str;
}
else{
str= AddArrowhtml(str);
OpenMsg(sE,str);
}
};
///信息提示框箭头html
function AddArrowhtml(s)
{
return s+"";
}
///
///弹出提示层
///
///e :弹出位置对象,str:弹出
function OpenMsg(e,str)
{
if(typeof e != "string") return;
var eofs,ele;
ele = $("#"+e);
eofs = ele.offset();
appDivCke(eofs.top-24,eofs.left ,e+"ediv",str,"arrowDownTest");
ele.one("blur",function(){$("#"+e+"ediv").replaceWith()});//replaceWithempty();
};
///
///添加漂浮提示框 必须jq加载完才可以调用
///
function appDivCke(t,l,n,estr,dcss)
{
$("body").prepend(""+ estr +"
");
}
//切换板式 eId: 对象id; cls:hover 样式; hType: 样式对象; hEName:隐藏对象 name; hI: 第几个hover; hOc: hover 或点击;
function TrunMenu(eId,cls,hType,hEName,hI,hOc)
{
if(arguments.length < 1 )
{
eId = "Trun_Menu";
}
if(typeof eId !="string" || eId.length < 1 ) eId = "Trun_Menu";
if(typeof cls !="string")cls = "active";
if(typeof hType !="string")hType = "li";
if(isNaN(hI))hI = 1;
if(typeof hOc != "boolean") hOc = false;
$().ready(function(){
var Tdiv =[],Ediv;
if(typeof hEName =="string")
{
Ediv = $("[name='"+hEName+"']");
}
$("#"+ eId +" li").each(function(i){
var Te,Oe,Hf,Odid;
Te = $(this);
Te.attr("TrunNum",i);
Oe = Te.text();
if(typeof Ediv != "object")
{
Odid = $("#"+Oe.replace(/\s*/g, "")).show();
}
else
{
Odid = Ediv.eq(i);
}
if(i == hI-1)
{
Odid.show();
if(hType == "li")
{
Te.addClass(cls);
}
else
{
Te.find("a").addClass(cls);
}
}
else
{
Odid.hide();
if(hType == "li")
{
Te.removeClass(cls);
}
else
{
Te.find("a").removeClass(cls);
}
}
Hf = Te.find("a").attr("href");
if(typeof Hf !="string" || Hf =="#" || Hf =="###" )
{
Hf="javascript:;";
}
Tdiv.push({CTe:Te,COe:Oe,Href:Hf,Did:Odid});
if(hType == "li")
{
if(hOc)
{
Te.hover(function(){
for(i=0;i"+Tdiv[i].COe+"");
Tdiv[i].CTe.removeClass(cls);
}
Te = $(this);
//Oe = Te.text(); //removeAttr
//$("#"+Oe.replace(/\s*/g, "")).show();
Tdiv[parseInt(Te.attr("TrunNum"))].Did.show();
Te.addClass(cls).html(Oe);
});
}
else
{
Te.click(function(){
for(i=0;i"+Tdiv[i].COe+"");
Tdiv[i].CTe.removeClass(cls);
}
Te = $(this);
//Oe = Te.text(); //removeAttr
//$("#"+Oe.replace(/\s*/g, "")).show();
Tdiv[parseInt(Te.attr("TrunNum"))].Did.show();
Te.addClass(cls).html(Oe);
});
}
}
else
{
if(hOc)
{
Te.hover(function(){
for(i=0;i"+Tdiv[i].COe+"");
}
Te = $(this);
// Oe = Te.text();
Tdiv[parseInt(Te.attr("TrunNum"))].Did.show();
// $("#"+Oe.replace(/\s*/g, "")).show();
Te.find("a").addClass(cls);
});
}
else
{
Te.click(function(){
for(i=0;i"+Tdiv[i].COe+"");
}
Te = $(this);
//Oe = Te.text();
Tdiv[parseInt(Te.attr("TrunNum"))].Did.show();
// $("#"+Oe.replace(/\s*/g, "")).show();
Te.find("a").addClass(cls);
});
}
}
});
});
};
// for CH header phone and language slide box
$(function(){
$(".currentFlag").click(function(){
$(".slideBox").show();
});
$(".languageSwitch .slideBox .closeBox").click(function(){
$(".slideBox").hide();
});
});
$(function(){
$(".currentNo").click(function(){
$(".freePhone").show();
});
$(".tollfree .freePhone .closeBlock").click(function(){
$(".freePhone").hide();
});
});