﻿// JScript 文件
function $(o){if(typeof(o)=='object')return o;return document.getElementById(o);};
function $$(o,tag){if($(o))return $(o).getElementsByTagName(tag);else return null;};
//获取网页主体
function getTrueBody(){if(navigator.appVersion.toLowerCase().indexOf('chrome')>0)return document.body;return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;}
//IE判断
var isIE = navigator.appName == 'Microsoft Internet Explorer';
var ie6=navigator.appVersion.indexOf('MSIE 6.0')>0?true:false;
//获取Cookie中某个值
function getCookie(c_name){if (document.cookie.length>0){c_start=document.cookie.indexOf(c_name + '=');if (c_start!=-1){c_start=c_start + c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if (c_end==-1) c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));};};return '';}
//图片缩放
function zoomPic(o,w,h,f){if(!o)return;if(!f||o.width>w||o.height>h){if(o.width/w>o.height/h){o.height=w/o.width*o.height;o.width=w;}else{o.width=h/o.height*o.width;o.height=h;};};if(o.offsetWidth<=w||o.offsetHeight<=h)o.style.padding=(h-o.height)/2+'px '+(w-o.width)/2+'px';}
function zoomPicNoPad(o,w,h){if(!o)return;if(o.width>w||o.height>h){if(o.width/w>o.height/h){o.height=w/o.width*o.height;o.width=w;}else{o.width=h/o.height*o.width;o.height=h;};};}
//下拉框选择
function SetSelectValue(o,v){if(!o)return;if(o.length==0)return;for(var i=0;i<o.length;i++){if(o.options[i].value==v)o.options[i].selected=true;return;};o.options[0].selected=true;};
//ajax
var ajax=function(url,method,send){
	var xmlhttp;
	if(!method||method.toUpperCase()!='POST')method='GET';
	if(url.indexOf('?')>-1)url+='&'+Math.random();else url+='?'+Math.random();
	if(window.ActiveXObject){try{xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}}}else if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();if(xmlhttp.overrideMimeType) {xmlhttp.overrideMimeType('text/xml');}}
	xmlhttp.open(method,url,true);
	if(method=='POST')
	{
		xmlhttp.setRequestHeader('Content-length',send.length);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	};
	xmlhttp.setRequestHeader('Content-Type','text/xml;charset=utf-8');
	xmlhttp.send(send);
	return xmlhttp;
};

//图片载入
var imgLoaderInterval;
var imgLoaderImg;
function LoadImage(image,url)
{
	var obj=image;
	if(typeof(obj)=='string')obj=document.getElementById(image);
	if(!obj){return;};
	if(obj.src.toLowerCase().indexOf(url.toLowerCase())>-1)return;
	if(imgLoaderInterval)clearInterval(imgLoaderInterval);
	var appname = navigator.appName.toLowerCase();
	if(imgLoaderImg){if (appname.indexOf("netscape") == -1)imgLoaderImg.onreadystatechange=null;else imgLoaderImg.onload=null;};
	imgLoaderImg=null;
	obj.style.filter='alpha(opacity=100)';
	obj.style.opacity=1;
	obj.src='images/blank.gif?'+Math.random();
	obj.style.background='url("images/loadMovie.gif") center no-repeat';
	obj.width=1;
	obj.height=1;
	obj.style.padding='0';
	imgLoaderImg= new Image();
	imgLoaderImg.src=url+'?'+Math.random();
	if (appname.indexOf("netscape") == -1)
	{
		imgLoaderImg.onreadystatechange = function ()
		{
			if(imgLoaderImg==null)return;
			if (imgLoaderImg.readyState == "complete")
			{
				loaded();
			}
		};
	}
	else
	{
		imgLoaderImg.onload = function ()
		{
			if(imgLoaderImg==null)return;
			if (imgLoaderImg.complete == true)
			{
				loaded();
				imgLoaderImg=null;
			};
		};
	};
	var bAl=0;
	function setAlpha()
	{
		obj.style.filter='alpha(opacity='+bAl+')';
		obj.style.opacity=bAl/100;
		if(bAl>100||imgLoaderInterval==null){clearInterval(imgLoaderInterval);bAl=0;}else{bAl+=11;};
	}
	function loaded()
	{
		obj.style.background='none';
		obj.style.filter='alpha(opacity=0)';
		obj.style.opacity=0;
		obj.src=imgLoaderImg.src;
		obj.width=imgLoaderImg.width;
		obj.height=imgLoaderImg.height;
		imgLoaderInterval=setInterval(setAlpha,10);
	}
};


var alanDropMenu=function()
{
	var dropMenu=$('alanDropMenuMain');
	var menuConts=$$('alanDropMenuMain','ul');
	var menus=$$('mainMenu','li');
	var secMenu=$('alanDropMenuSecond');
	var mainPosFlag=0;
	var secondMenuFlag;
	var tInt;
	
	function STH()
	{
		if(dropMenu.style.display.toLowerCase()=='none'&&tInt)clearInterval(tInt);
		if(dropMenu.scrollHeight>dropMenu.offsetHeight+10)
		{
			dropMenu.style.height=dropMenu.offsetHeight+10+'px';
			$$(dropMenu,'div')[0].style.height=dropMenu.offsetHeight-1+'px';
			$$(dropMenu,'div')[0].style.width=dropMenu.offsetWidth-2+'px';
		}
		else
		{
			dropMenu.style.height=dropMenu.scrollHeight+'px';
			$$(dropMenu,'div')[0].style.height=dropMenu.offsetHeight-1+'px';
			$$(dropMenu,'div')[0].style.width=dropMenu.offsetWidth-2+'px';
			clearInterval(tInt);
		}
	}

	
	for(var i=0;i<menus.length;i++)
	{
		menus[i].onmouseover=function()
		{
			if(tInt)clearInterval(tInt);
			for(var j=0;j<menus.length;j++){if(this==menus[j]){mainPosFlag=j;break;};};
			menus[mainPosFlag].className='hover';
			if(menuConts[mainPosFlag]==null)return;
			if(menuConts[mainPosFlag].className.toLowerCase()=='hide')return;
			
			for(var j=0;j<menus.length;j++){menuConts[j].style.display='none';};
			menuConts[mainPosFlag].style.display='block';
			var tem=menus[mainPosFlag];
			var x=tem.offsetLeft;
			var y=tem.offsetHeight+tem.offsetTop;
			
			if(isIE&&!ie6)x--;//处理兼容
			
			while(tem.offsetParent){tem=tem.offsetParent;x+=tem.offsetLeft;y+=tem.offsetTop;};
			dropMenu.style.top =y+'px';
			dropMenu.style.left=x+'px';
			dropMenu.style.width=this.offsetWidth-2+'px';
			dropMenu.style.height='10px';
			dropMenu.style.display='block';
			
			tInt=setInterval(STH,10);
		}
		menus[i].onmouseout=function(){if(tInt)clearInterval(tInt);this.className='';dropMenu.style.display='none';};
	};
	dropMenu.onmouseover=function(){tInt=setInterval(STH,10);this.style.display='block';menus[mainPosFlag].className='hover';};
	dropMenu.onmouseout =function(){if(tInt)clearInterval(tInt);this.style.display='none';menus[mainPosFlag].className='';};
	//set the second menu
	//add function to every li
	var lis=$$('alanDropMenuMain','li');
	secMenu.style.width='140px';
	for(var i=0;i<lis.length;i++)
	{
		lis[i].onmouseover=function()
		{
			this.className='hover';
			if(!this.getAttribute('aim'))return;
			//setSecondMenu(this,'menuUl-'+this.title);
			
			dropMenu.style.display='block';
			
			var tem=secondMenuFlag=this;
			var x=tem.offsetWidth+tem.offsetLeft;
			var y=tem.offsetTop;
			while(tem.offsetParent){tem=tem.offsetParent;x+=tem.offsetLeft;y+=tem.offsetTop;};
			y=y-3;
			x++;
			
			secMenu.style.top=dropMenu.offsetTop+'px';
			secMenu.style.left=x+'px';
			//secMenu.style.width=menus[mainPosFlag].offsetWidth+'px';
			secMenu.style.display='block';
			var allUl=$$('alanDropMenuSecond','ul');
			for(var i=0;i<allUl.length;i++)allUl[i].style.display='none';
			$('menuUl-'+this.getAttribute('aim')).style.display='block';
			secMenu.style.height='auto';
			if(secMenu.offsetHeight<dropMenu.offsetHeight)secMenu.style.height=dropMenu.offsetHeight-1+'px';
			$$(secMenu,'div')[0].style.height=secMenu.offsetHeight-1+'px';
			$$(secMenu,'div')[0].style.width=secMenu.offsetWidth-2+'px';
		};
		lis[i].onmouseout =function(){this.className='';secMenu.style.display='none';};
	}

	secMenu.onmouseover=function(){secondMenuFlag.className='hover';dropMenu.style.display='block';this.style.display='block';menus[mainPosFlag].className='hover';};
	secMenu.onmouseout =function(){secondMenuFlag.className='';dropMenu.style.display='none';this.style.display='none';menus[mainPosFlag].className='';};
};
function setLanguage(o)
{
	var obj=$('languageDIV');
	obj.style.width=o.offsetWidth;
	obj.style.left=(getTrueBody().offsetWidth+1000)/2-o.offsetWidth-18+'px';
	obj.style.display='block';
};
$('languageDIV').onmouseover=function(){this.style.display='block';};
$('languageDIV').onmouseout =function(){this.style.display='none';};

function setOrderMail(v)
{
	v=v.replace(/ /,'');
	if(v=='')
	{
		alert('Please input your email !');
		return;
	}
	var re=/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(!re.test(v))
	{
		alert('Wrong Email ! Please input your email !');
		return;
	}
	
	var a=new ajax('xml/setOrderMail.ashx?v='+escape(v));
	a.onreadystatechange=function()
	{
		if(a.readyState==4){
			if(a.status==200){
				var xml=a.responseText;
				alert(xml);
			};
		};
	};
}
