// JavaScript Document
jQuery(document).ready(function(){
	$("#menu2,#menu3,#menu7").mousemove(function(){
		$("#"+this.id+"_div").show();
	});
	$("#menu2,#menu3,#menu7").mouseout(function(){
		$("#"+this.id+"_div").hide();
	});
	$("#menu2_div,#menu3_div,#menu7_div").mousemove(function(){
		$(this).show();
	});
	
});

function show_tr(id)
{
	jQuery(".pro_"+id).toggle();
}

function show_type(id,num)
{
	for(i=1;i<=num;i++)
	{
		if(i!=id)
		{
			jQuery(".pro_"+i).hide();
		}
	}
	jQuery(".pro_"+id).toggle();
}

function check_buy()
{	//姓名
	var name = document.forms[0].elements["name"];
	if (document.getElementById("name").value.length==0)
	{
		alert("没有填写姓名！");
		document.getElementById("name").focus();
		return false;
	}
	else if (name.value != name.value.replace(/[^\u4E00-\u9FA5]/g,''))
	{
		alert("请填写中文！");
		document.getElementById("name").value = '';
		return false;
	}
	
	//手机号码
	if (document.getElementById("cell").value.length==0)
	{
		alert("没有填写手机号码！");
		document.getElementById("cell").focus();
		return false;			
	}
	else if(document.getElementById("cell").value.length!=11 || isNaN(document.getElementById("cell").value))
	{
		alert("手机号码不规范！");
		document.getElementById("cell").focus();
		return false;			
	}

    //地址
	if (document.getElementById("address").value.length<8)
	{
		alert("联系地址不能少于8个字符！");
		document.getElementById("address").focus(); 
		return false;
	}

	return true
}

function ischarsinbag (s, bag) 
{ 
	var i,c; 
	for (i = 0; i < s.length; i++) 
	{ 
		c = s.charat(i);//字符串s中的字符 
		if (bag.indexof(c) > -1) 
		return c; 
	} 
	return ""; 
} 

function ischinese(s) 
{ 
	var errorchar; 
	var badchar = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789><,[]{}?/+=|\\\":;~!#$%()`"; 
	errorchar = ischarsinbag(s, badchar) 
	if (errorchar != "" ) 
	{
		return false; 
	}
	return true; 
} 



//检测电子邮箱
function check_email(email)
{
	var test_email = /^[a-zA-Z]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/;
	if (!test_email.test("qq"+email))
	{
		return false;
	}
	else
	{
		return true;
	}
}

//设为首页
function setHomepage()
{
	var url = window.location.href; 
	if (document.all)
    {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}
	else if (window.sidebar)
	{
		if(window.netscape)
		{
			try
			{ 
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
			} 
			catch (e) 
			{ 
				alert( "设为首页操作被浏览器拒绝，如果想启用设为首页功能，请选择信任此代码" ); 
			}
		}
		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; 
	var tname=document.title
	if(document.all)
	{
		window.external.addFavorite(url,tname);
	}
	else if(window.sidebar)
	{
		alert("请使用Ctrl+D键收藏本页");
	}
}

//图片控制
function DrawImage(ImgD,FitWidth,FitHeight)
{
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{
		if(image.width/image.height>= FitWidth/FitHeight)
		{
			if(image.width>FitWidth)
			{
				ImgD.width=FitWidth;
				ImgD.height=(image.height*FitWidth)/image.width;
			}
			else
			{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		else
		{
			if(image.height>FitHeight)
			{
				ImgD.height=FitHeight;
				ImgD.width=(image.width*FitHeight)/image.height;
			}
			else
			{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
}

