// Common Javascript

var	ie = (document.all) ? true : false;
function zoomImg()
{
	var	o;
	o =	event.srcElement;
	if (o.tagName!='IMG') return true;
	if (event.altKey ==	true)
	{
		var	zoom = parseInt(o.style.zoom, 10) || 100;
		zoom +=	event.wheelDelta / 12;
		if (zoom > 0)
			o.style.zoom = zoom	+ '%';
		return false;
	}
	else
		return true;
}

function renderInput()
{
	if (!document.getElementsByTagName)	return;
	
	var	inputs = document.getElementsByTagName("input");
	for	(var i = 0;	i <	inputs.length; i++)
	{
		var	input =	inputs[i];
		if((input.type == 'text' || input.type == 'password') && input.className == 'IsRequired')
			input.title	= '黄色区域为必填项';
	}
	
	var	textareas = document.getElementsByTagName("textarea");
	for	(var i = 0;	i <	textareas.length; i++)
	{
		var	textarea =	textareas[i];
		if(textarea.className == 'IsRequired')
			textarea.title	= '黄色区域为必填项';
	}

	var	frms = document.getElementsByTagName("form");
	for	(var i = 0;	i <	frms.length; i++)
		if(!frms[i].onsubmit)
			frms[i].onsubmit = submitForm;
}

function submitForm()
{
	var o = event.srcElement;
	if(o.Submit && o.Submit.type == 'submit')
	{
		o.Submit.value = '正在处理…';
		o.Submit.disabled = true;
	}
	
	if(o.Cancel && o.Cancel.type == 'button')
		o.Cancel.disabled = true;

	if(o.Button && o.Button.type == 'button')
		o.Button.disabled = true;
	
	if(o.Reset && o.Reset.type == 'reset')
		o.Reset.disabled = true;

	return true;
}

function regInput(obj, reg, inputStr)
{
		var docSel	= document.selection.createRange();
		if (docSel.parentElement().tagName != "INPUT")	return false;
		oSel = docSel.duplicate();
		oSel.text = "";
		var srcRange	= obj.createTextRange();
		oSel.setEndPoint("StartToStart", srcRange);
		var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);
		return reg.test(str);
}

function img_show(linkimgid){
	if(document.all.jumpTo)
		document.all.jumpTo.style.visibility = 'hidden';
	cells = document.getElementsByName(linkimgid);
	for(j = 0; j < cells.length; j++){
		cells[j].style.display = '';
		cells[j].style.borderWidth = '1px';
		cells[j].style.borderColor = '#000066';
		cells[j].style.borderStyle = 'solid';
	}
}

function img_hidden(linkimgid){
	if(document.all.jumpTo)
		document.all.jumpTo.style.visibility = 'visible';
	cells = document.getElementsByName(linkimgid);
	for(j = 0; j < cells.length; j++)
		cells[j].style.display = 'none';
}

var oImg 
function fiximgwin(url,w,h){ 
	if(arguments.length == 1){       //如果图像大小未定义 
		oImg = new Image();           //创建图像对象 
		oImg.src = url;               //设置图像源 
		Size(url);                 //调用Size函数获取图像尺寸 
	}
	else window.open(url,"","width="+w+",height="+h); //如果已取得图像尺寸，打开固定大小的窗口 
}

function Size(url){ 
	if(oImg.width && oImg.height)       //如果已取得图像尺寸 
		//将图像尺寸加上一定尺寸后返回给fiximgwin()函数， 
		//其中18和25的表现见下图右下角所示 
		fiximgwin(url,oImg.width+18,oImg.height+25);   
	else setTimeout("Size(url)",10); 
}

function displayStatusMsg(msgStr) {
  status=msgStr;
  document.MM_returnValue = true;
}

function OverChangeBorder(o,w,c){
	o.style.borderWidth = w;
	o.style.borderColor = c;
}

function OutChangeBorder(o,w,bw,c){
	o.style.borderWidth = w;
	o.style.borderColor = c;
	o.style.borderBottomWidth = bw;
}

document.onmousewheel=zoomImg;

function checkLength(obj,maxlength){
	if(obj.value.length > maxlength){
		obj.value = obj.value.substring(0,maxlength);
	}
}

function menu(){
	if($("#menu-home img").attr("src") != "../images/home-over.jpg"){
		$("#menu-home img").hover(
			function(){
				$(this).attr("src", "../images/home-over.jpg");
			},
			function(){
				$(this).attr("src", "../images/home.jpg");
			});
	}

	if($("#menu-team img").attr("src") != "../images/team-over.jpg"){
		$("#menu-team img").hover(
			function(){
				$(this).attr("src", "../images/team-over.jpg");
			},
			function(){
				$(this).attr("src", "../images/team.jpg");
			});
	}

	if($("#menu-works img").attr("src") != "../images/work-over.jpg"){
		$("#menu-works img").hover(
			function(){
				$(this).attr("src", "../images/work-over.jpg");
			},
			function(){
				$(this).attr("src", "../images/work.jpg");
			});
	}
	
	$("#search input").focus(function(){
			if($(this).val() == "输入内容按回车键搜索") $(this).val("");
	})

	$("#search input").blur(function(){
			if($(this).val() == "") $(this).val("输入内容按回车键搜索");
	});
}

function reloadCode(){
	var d = new Date();
	$("#codeImg").attr("src","Include/checkcode.asp?d="+ d.getTime().toString());
}

function searchCheck(){
	var text = $("#search input").val();

	if(text == "" || text == "输入内容按回车键搜索"){
		alert("请输入要搜索的内容");
		return false;
	}
}


$(document).ready(function(){
	var firstLoad = true;
	$(window).scroll(function(){
		if(firstLoad) $(window).scrollTop(0);

		if($(window).scrollTop() > parseInt($(document).height()/3)){
			$("#pageTop").show();
		}else{
			$("#pageTop").hide();
		}

		firstLoad = false;
	});

	$("#pageTop").click(function(){
		$.scrollTo($('#banner'), { duration: 500 });
	});
});

