window.onload = function(){
	var Img_Name = document.getElementsByName("More");
	if (Img_Name.length > 0 ){
		for(i=0;i < Img_Name.length;i++){
				Img_Name[i].onmouseover = function(){
					this.src='../Images/More_On.gif';
				}
				Img_Name[i].onmouseout = function(){
					this.src='../Images/More_Off.gif';
				}
		}
	}
	
	if(document.getElementById("Product_Button") != null){
		var Li_Button = document.getElementById("Product_Button").getElementsByTagName("li");
		for ( i = 0 ; i < Li_Button.length ; i++ ){
			Li_Button[i].n = i;
			Li_Button[i].onclick=function(){
				for ( s = 0 ; s < Li_Button.length ; s++ ){
					Li_Button[s].className = '';
					document.getElementById("P_Down_" + s).style.display = 'none';
				}
				this.className = 'On_P_Button';
				document.getElementById("P_Down_" + this.n).style.display = 'block';
			}
		}
	}
	
	if(document.getElementById("Join") != null){
		var Join_Id = document.getElementById("Join").getElementsByTagName("Input");
		var Join_Textarea = document.getElementById("Join").getElementsByTagName("textarea");
		if (Join_Id.length > 0 ){
			for(i=0;i < Join_Id.length;i++){
				if (Join_Id[i].type == 'text'){
					Join_Id[i].onfocus=function (){
						this.style.border = '#f00 1px solid';
						this.style.color = '#f00';
					}
					Join_Id[i].onblur=function (){
						this.style.border = '#e3e4e6 1px solid';
						this.style.color = '#666';
					}
				}
			}
		}
		if (Join_Textarea.length > 0 ){
			for(i=0;i < Join_Textarea.length;i++){
				Join_Textarea[i].onfocus=function (){
					this.style.border = '#f00 1px solid';
					this.style.color = '#f00';
				}
				Join_Textarea[i].onblur=function (){
					this.style.border = '#ccc 1px solid';
					this.style.color = '#666';
				}
			}
		}
	}
	/*
	if(document.getElementById("RongYu") != null){
		var RongYu_Pic = document.getElementById("RongYu").getElementsByTagName("Td");
		if (RongYu_Pic.length > 0 ){
			for(i=0;i < RongYu_Pic.length;i++){
				if (RongYu_Pic[i].height == 255){
					RongYu_Pic[i].onmouseover = function(){
						this.className='On_Border';
					}
					RongYu_Pic[i].onmouseout = function(){
						this.className='Off_Border';
					}
				}
			}
		}	
	}
	*/
	if(document.getElementById("Guest_Form") != null){
		var Guest_Input = document.getElementById("Guest_Form").getElementsByTagName("input");
		if (Guest_Input.length > 0 ){
			for(i=0;i < Guest_Input.length;i++){
				Guest_Input[i].onfocus = function(){
					this.style.border = '#f00 1px solid';
					this.style.color = '#f00';
				}
				Guest_Input[i].onblur = function(){
					this.style.border = '#ccc 1px solid';
					this.style.color = '#666';
				}
			}
		}
		var Guest_Textarea = document.getElementById("Guest_Form").getElementsByTagName("textarea");
		if (Guest_Textarea.length > 0 ){
			for(i=0;i < Guest_Textarea.length;i++){
				Guest_Textarea[i].onfocus = function(){
					this.style.border = '#f00 1px solid';
					this.style.color = '#f00';
				}
				Guest_Textarea[i].onblur = function(){
					this.style.border = '#ccc 1px solid';
					this.style.color = '#666';
				}
			}
		}
	}
	
	if(document.getElementById("Left_Menu") != null){
		var Left_Menu = document.getElementById("Left_Menu").getElementsByTagName("ul");
		if (Left_Menu.length > 0 ){
			for(i=0;i < Left_Menu.length;i++){
				if (Left_Menu[i].getElementsByTagName("li").length > 0 ){
					Left_Menu[i].onclick = function(){
						//alert(this.getElementsByTagName("li").length);
						//this.src='../Images/More_On.gif';
						for (s=0; s < Left_Menu.length ; s++){
							for(n=0; n < Left_Menu[s].getElementsByTagName("li").length; n++){
								Left_Menu[s].getElementsByTagName("li")[n].style.display="none";
							}
						}
						for(n=0; n < this.getElementsByTagName("li").length; n++){
							this.getElementsByTagName("li")[n].style.display="block";
						}
					}
				}
			}
		}
	}
	if(document.getElementById("Pic_List") != null){
		fImageAuto('Pic_List',160,120);
	}
	
	/*
	if(document.getElementById("RongYu") != null){
		fImageAuto('RongYu',150,225);
	}
	*/

	if(document.getElementById("News_Content") != null){
		fImageAuto('News_Content',760,525);
	}
	if(document.getElementById("Content") != null){
		fImageAuto('Content',760,1040);
	}
	if(document.getElementById("News_Work") != null){
		fImageAuto('News_Work',220,165);
	}
	if(document.getElementById("Search_Key_Word") != null){
		Key_Word = document.getElementById("Search_Key_Word");
		Key_Word.onfocus=function (){
			this.className = 'Search_input_On';
			if (Key_Word.value == "请输入关键字..."){
				Key_Word.value = "";	
			}
		}
		Key_Word.onblur=function (){
			this.className = 'Search_input_Off';
			if (Key_Word.value.length == 0){
				Key_Word.value = "请输入关键字...";	
			}
		}	
	}
	
	if(document.getElementById("Jobs_List") != null){
		Div_List = document.getElementById("Jobs_List").getElementsByTagName("div");
		for(i=0;i < Div_List.length;i++){
			Div_List[i].onmouseover=function (){
				this.style.background='#5cc7f3';
			}
			Div_List[i].onmouseout=function (){
				if(this.className=='Double_List'){
					this.style.background='#f6f6f6';
				}else{
					this.style.background='#fff';
				}
			}
		}
	}
	
	if(document.getElementById("News_Pic") != null){
		fImageAuto('News_Pic',680,380);
	}
}

function fImageAuto(nID,nMaxWidth,nMaxHeight) {
	var objParentID = document.getElementById(nID); 
	var objImg = objParentID.getElementsByTagName("img"); 
	var nImgNewRate = 0; 
	var nImgOldRate = nMaxWidth/nMaxHeight; 
	for (i=0;i<objImg.length;i++) { 
		nImgNewRate = objImg[i].offsetWidth/objImg[i].offsetHeight;
		if(objImg[i].offsetWidth > nMaxWidth || objImg[i].offsetHeight > nMaxHeight){
			if (nImgNewRate >= nImgOldRate) { 
				objImg[i].style.height = nMaxWidth/nImgNewRate +"px"; 
				objImg[i].style.width = nMaxWidth +"px"; 
				//objImg[i].style.marginTop = Math.round((nMaxHeight-nMaxWidth/nImgNewRate)/2) + "px"; 
			}else{
				objImg[i].style.width = nMaxHeight*nImgNewRate + "px"; 
				objImg[i].style.height = nMaxHeight + "px"; 
				//objImg[i].style.marginLeft = (nMaxWidth-nMaxHeight*nImgNewRate)/2 + "px";
			}
		}
	}
}

function setImg(img,width,height){ 

	var scale_w=img.width/width; 
	
	var scale_h=img.height/height; 
	
	var scale=scale_w>scale_h?scale_w:scale_h; 
	
	img.width=img.width/scale; 
	
	return false; 

}

function DrawImage(ImgD,iwidth,iheight){    
    //参数(图片,允许的宽度,允许的高度)    
    var image=new Image();    
    image.src=ImgD.src;    
    if(image.width>0 && image.height>0){    
      if(image.width/image.height>= iwidth/iheight){    
          if(image.width>iwidth){      
              ImgD.width=iwidth;    
              ImgD.height=(image.height*iwidth)/image.width;    
          }else{    
              ImgD.width=image.width;      
              ImgD.height=image.height;    
          }    
      }else{    
          if(image.height>iheight){      
              ImgD.height=iheight;    
              ImgD.width=(image.width*iheight)/image.height;            
          }else{    
              ImgD.width=image.width;      
              ImgD.height=image.height;    
          }    
      }    
    }    
}


function Set_News(Id){
	for(i=0;i<2;i++){
		document.getElementById("Title_" + i).className = 'Off_Title';
		document.getElementById("News_List_" + i).style.display = 'none';
		document.getElementById("News_Title_" + i).style.color = '#616161';
	}
		document.getElementById("Title_" + Id).className = 'On_Title';
		document.getElementById("News_List_" + Id).style.display = 'block';
		document.getElementById("News_Title_" + Id).style.color = '#f00';
		if(Id == 0){
			document.getElementById("More_Link").href = "News.Asp?Class_Id=353";
		}else{
			document.getElementById("More_Link").href = "News.Asp?Class_Id=352";
		}
}

function CheckForm(){
	if(document.getElementById("Search_Key_Word").value == "请输入关键字..." || document.getElementById("Search_Key_Word").value.length == 0){
		alert(document.getElementById("Search_Key_Word").value);
	}else{
		document.getElementById("Search_Form").submit();
	}
}
function Join(){
	var Obj = document.Jobs_Form;
	var Input_Chinese=/^[\u4E00-\u9FA5\uF900-\uFA2D]+$/;
	var Input_Yddh=/^(13|14|15|18)[0-9]{9}$/;
	var Input_Zzdh=/^[0-9]{3,4}(-)[0-9]{7,8}$/;
	if (!Input_Chinese.exec(Obj.Join_Name.value) || Obj.Join_Name.value.length < 2){
		alert("姓名不能为空且至少是两位汉字！");
		Obj.Join_Name.focus();

	}else if (Obj.Join_Mz.value.length == 0) {
		
		alert("名族不能为空！");
		Obj.Join_Mz.focus();

	}else if (Obj.Join_Sr.value.length == 0) {
		
		alert("出生年月不能为空！");
		Obj.Join_Sr.focus();

	}else if (Obj.Join_Xl.value.length == 0) {
		
		alert("学历不能为空！");
		Obj.Join_Xl.focus();

	}else if (Obj.Join_Zy.value.length == 0) {
		
		alert("所学专业不能为空！");
		Obj.Join_Zy.focus();

	}else if (Obj.Join_Grzc.value.length == 0) {
		
		alert("个人专长不能为空！");
		Obj.Join_Grzc.focus();

	}else if (Obj.Join_Grzz.value.length == 0) {
		
		alert("个人自传不能为空！");
		Obj.Join_Grzz.focus();
		
	}else if (Obj.Join_Gzjl.value.length == 0) {
		
		alert("工作经历不能为空！");
		Obj.Join_Gzjl.focus();

	}else if (Obj.Join_X_Gzgw.value.length == 0) {
		
		alert("希望工作岗位不能为空！");
		Obj.Join_X_Gzgw.focus();
		
	}else if (!Input_Yddh.exec(Obj.Join_Yddh.value) && !Input_Zzdh.exec(Obj.Join_Zzdh.value)){
		
		alert("移动电话与住宅电话至少要填写一项！\n格式：0991-0000000\n      13100000000！");
		Obj.Join_Yddh.focus();
		
	}else if (Obj.Join_QQ.value.length == 0) {
		
		alert("QQ号码不能为空！");
		Obj.Join_QQ.focus();
		
	}else if (Obj.Join_Hkdz.value.length == 0) {
		
		alert("户口所在地不能为空！");
		Obj.Join_Hkdz.focus();
		
	}else if (Obj.Join_Xzz.value.length == 0) {
		
		alert("现住址不能为空！");
		Obj.Join_Xzz.focus();
		
	}else{
		
		document.Jobs_Form.submit();
		
	}
}
function Guest_Action(Action){
	var Obj = document.Guest_Add;
if (Action == "On"){
	if (Obj.Guest_Name.value.length == 0) {
		alert("姓名不能为空！");
		Obj.Guest_Name.focus();
	}else if (Obj.Guest_Telephone.value.length == 0) {
		alert("联系电话不能为空！");
		Obj.Guest_Telephone.focus();
	}else if (Obj.Guest_Gsmc.value.length == 0) {
		alert("公司名称不能为空！");
		Obj.Guest_Gsmc.focus();
	}else if (Obj.Guest_Mail.value.length == 0) {
		alert("电子邮箱不能为空！");
		Obj.Guest_Mail.focus();
	}else if (Obj.Guest_Content.value.length == 0) {
		alert("留言内容不能为空！");
		Obj.Guest_Content.focus();
	}else{
		document.Guest_Add.submit();
	}
}else{
	Obj.Guest_Name.value = "";
	Obj.Guest_Telephone.value = "";
	Obj.Guest_Gsmc.value = "";
	Obj.Guest_Addres.value = "";
	Obj.Guest_Mail.value = "";
	Obj.Guest_HomePage.value = "";
	Obj.Guest_Content.value = "";
}
}

function setMaps(Id){
	var url = '/Xml/Class_List.asp?City=' + Id
	document.getElementById("Loading").style.display='block';
	document.getElementById("Loading").style.height=document.body.scrollHeight;
	var xmlHttp = new XMLHttpRequest();
	try{
		xmlHttp.onreadystatechange = function(){//当http状态改变，执行的动作
			if(xmlHttp.readyState == 4){ //由于我们使用的是同步模式，只有readyState为4才表示数据返回完毕
				if (xmlHttp.status == 200 || xmlHttp.status == 0){ //只有http状态返回200代码的时候才是正常的数据
					var xmlDoc = xmlHttp.responseXML; // 取得XML的DOM对象
					var root = xmlDoc.documentElement; // 取得XML文档的根
					if(xmlHttp.responseText != "Error"){
						var Show_List = root.getElementsByTagName("Show_List");
							var Li = "<Div Id='TLst'><li>省/市</li><li class='AddRes'>服务店地址</li><li class='Work_Time'>工作时间</li><li class='Time'>&nbsp;&nbsp;联系电话</li></Div>"
						for(var i=0;i<Show_List.length;i++){
							var News_Title = Show_List[i].getElementsByTagName("News_Title")[0].firstChild.data
							var City = Show_List[i].getElementsByTagName("City")[0].firstChild.data
							var Addres = Show_List[i].getElementsByTagName("Addres")[0].firstChild.data
							var Time_Work = Show_List[i].getElementsByTagName("Time_Work")[0].firstChild.data
							var Telephone = Show_List[i].getElementsByTagName("Telephone")[0].firstChild.data
							Li = Li + "<Div><li id='Left_TList'>&nbsp;" + City + "</li>"
							Li = Li + "<li class='AddRes'>" + Addres + "</li>"
							Li = Li + "<li class='Work_Time'>" + Time_Work + "</li>"
							Li = Li + "<li class='Time'>&nbsp;&nbsp;" + Telephone + "</li></Div>"
						}
						document.getElementById('Net_Work').innerHTML = Li;
						document.getElementById("Loading").style.display='none';
					}else{
						alert("暂未添加！");
						document.getElementById("Loading").style.display='none';
					}
					
				}
			}
		}; 
		xmlHttp.open("GET", url, true); 
		xmlHttp.send(null); 
	}catch(e){
		alert('XML error:\n\n'+e.message);
	}
}

function AddFavorite(sURL)
{
    try
    {
        window.external.addFavorite('http://www.kltyre.com', sURL);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sURL, 'http://www.kltyre.com', "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function errpic(thepic){
	thepic.src="../Images/NoPic.gif" 
}
