var IMGPATH		= '/';
var form='';
var php_bgPicture   = "orangebg.gif";   
var php_arrow       = "orangearrow.gif";
var php_bgColor     = "#FF831F";
var objX = 0;
var objY = 0;
var bodyScrollWidth=0;
var bodyScrollHeight=0;
var screenAvailWidth=window.screen.availWidth;
var screenAvailHeight=window.screen.availHeight;

var bdMvEvt;
var bdUpEvt;

function recoverBodyEvent() {
    document.body.onmousemove = bdMvEvt;
    document.body.onmouseup = bdUpEvt;
}

if(navigator.appName.indexOf("Explorer") > -1){//ie
	var exp=1;
} 
else{//for ff
	var exp=2;
}
var layer=new Array();
var dragObj;
var dragObjId;

reCalBodySize();

function reCalBodySize(){
	bodyScrollWidth=document.documentElement.scrollWidth;
	bodyScrollHeight=document.documentElement.scrollHeight;
}
function checkAndResetStyleTop (obj) {
	var clientHeight=obj.firstChild.clientHeight;
	var styleTop=parseInt(obj.style.top.substring(0,obj.style.top.length-2));
	if ( clientHeight+styleTop>bodyScrollHeight ) {
		obj.style.top=(bodyScrollHeight- clientHeight)+'px';
	}
}


function set_div_style(obj,id,top,left,width,height,position,border,cursor,background) {
        var obj = obj;
        obj.id = id?id:null;
        obj.style.top = top?top:'0px';
        obj.style.left = left?left:'0px';
        obj.style.width = width?width:'0px';
        obj.style.height = height?height:'0px';
        obj.style.position = position?position:"static";
        obj.style.border = border?border:"1px solid #FF831F";
        obj.style.cursor = cursor?cursor:"default";
        obj.style.background = background?background:"";
        return obj
}

function drag_mouse_down(event,obj){
	var obj_left = obj.style.left;
	var obj_top = obj.style.top;
	var obj_left = obj_left.replace(/p|x/g,"");
	var obj_top = obj_top.replace(/p|x/g,"");
	if ( event == null ) {//IE必须
		event=window.event;
	}
	var clientX = String(event.clientX).replace(/p|x/g,"");
	var clientY = String(event.clientY).replace(/p|x/g,"");
	objX = clientX - obj_left;
	objY = clientY - obj_top;
}

function drag(event,obj){
	if( objX != 0 && objY != 0 ) {
		if ( event == null ) {//IE必须
			event=window.event;
		}
		if ( event.button == 1 ||  event.button == 0 ){
			var objWidth=obj.firstChild.clientWidth;
			var objHeight=obj.firstChild.clientHeight;
			reCalBodySize();

			var leftPo= event.clientX-objX;
			if ( leftPo < 0 ) {
				leftPo=0;
			}
			if ( leftPo > bodyScrollWidth-objWidth ) {
				leftPo=bodyScrollWidth-objWidth;
			}

			var topPo=event.clientY-objY;
			if ( topPo < 0 ) {
				topPo=0;
			}
			if ( topPo > bodyScrollHeight-objHeight ) {
				topPo=bodyScrollHeight-objHeight;
			}
			obj.style.left=leftPo+'px';
			obj.style.top=topPo+'px';
		}
	}
}

function GetLength(strTemp){
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++){
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255)) 
			sum = sum + 1;
		else 
			sum=sum + 2;
	}
	return sum;
}

function subStringPro(str, length){
	var stri = '';
	for(i=0,j=0; j<length;){
		if ((str.charCodeAt(i)>=0) && (str.charCodeAt(i)<=255)) {
			stri += str.charAt(i);
			j++;
		} else {
			stri += str.charAt(i);
			j += 2;
		}
		i++;
	}
	return stri;
}

//*********************
//隐藏元素
function HideElement(strElementTagName){
	try{
		for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
			var objTemp = window.document.all.tags(strElementTagName)[i];
			objTemp.style.visibility = "hidden";
		}
	}catch(e){
		alert(e.message);
	}
}

//显示元素
function ShowElement(strElementTagName){
	try{
		for(i=0;i<window.document.all.tags(strElementTagName).length; i++){
			var objTemp = window.document.all.tags(strElementTagName)[i];
			objTemp.style.visibility = "visible";
		}
	}catch(e){
		alert(e.message);
	}
}

function hideElementAll(){
	HideElement("SELECT");
	HideElement("OBJECT");
	HideElement("IFRAME");
}

function showElementAll(){
	ShowElement("SELECT");
	ShowElement("OBJECT");
	ShowElement("IFRAME");
}
//滤镜效果
function hide() {
	synSizeByBody("globalDiv");
	document.getElementById("globalDiv").style.display = "block";
	if ( 1 == exp ) {
		hideElementAll();
	}
}

function cancel() {
	document.getElementById("globalDiv").style.display = "none";
	if ( 1 == exp ) {
		showElementAll();
	}
	
	recoverBodyEvent();
}
function buildGlobalDiv(){
		var globalDiv=document.createElement('div');
		globalDiv.id='globalDiv';
		globalDiv.style.display='none';
		globalDiv.style.zIndex='98';
		globalDiv = set_div_style(globalDiv,'globalDiv','0px','0px',bodyScrollWidth+'px',bodyScrollHeight+'px',"absolute"," #333333 0px solid","default","darkgray");
		
		if ( 1 == exp ) {
			globalDiv.style.filter="alpha(opacity=50)";
		}
		else {
			globalDiv.style.opacity=30/100;
		}
		document.body.appendChild(globalDiv);
}
function synSizeByBody() {
	reCalBodySize();
	var argArr=synSizeByBody.arguments;
	for ( var i=0;i<argArr.length;i++ ) {
		if ( document.getElementById(argArr[i]) != null ) {
			document.getElementById(argArr[i]).style.width = (bodyScrollWidth)+'px';
			document.getElementById(argArr[i]).style.height = (bodyScrollHeight)+'px';
		}
	}
}

function GetCenterXY_ForLayer(objdiv){
	objdiv.style.display='block';
	var styleWidth=objdiv.style.width.substring(0,objdiv.style.width.length-2);
	var clientHeight=objdiv.clientHeight;
	var objLeft = parseInt(document.documentElement.scrollLeft+(document.documentElement.clientWidth - styleWidth)/2)+'px';
	var relTop=(document.documentElement.clientHeight-clientHeight)/2 > 0 ? (document.documentElement.clientHeight-clientHeight)/2:0;
	//var objTop = parseInt(document.documentElement.scrollTop+relTop)+'px';
	var objTop = parseInt(document.documentElement.scrollTop+relTop-80)+'px';
	objdiv.style.top = objTop;
	objdiv.style.left = objLeft;
	checkAndResetStyleTop(objdiv);
}
//************************************************************


function buildDiv(myLayerID){

		dragObjId=document.getElementById(myLayerID);
		dragObjId.style.visibility='hidden';
		dragObjId.style.zIndex='999';

		var styleWidth=dragObjId.clientWidth+'px';
		var styleHeight=dragObjId.clientHeight+'px';
		var layerId = myLayerID;

		dragObjId = set_div_style(dragObjId,layerId,'0px','0px',styleWidth,'0px',"absolute","","default","#fff");
		dragObj=dragObjId.firstChild.firstChild;
		dragObj.style.cursor='move';
		dragObj.onmousedown = function(event){drag_mouse_down(event,this.parentNode.parentNode)};

		dragObjId.onselectstart=function(){return false};

		if ( 1 == exp ) {
			dragObjId.firstChild.onresize=function(){checkAndResetStyleTop(this.parentNode)};
		}
		else {
			dragObjId.firstChild.onclick=function(){checkAndResetStyleTop(this.parentNode)};
		}
}

function hiddenLayerOther(layerID){
	for( var i=0;i<dragObjId.length;i++ ){
		if ( dragObjId[i] != layerID && document.getElementById(dragObjId[i]) != null ) {
			hiddenLayer(dragObjId[i]);
		}
	}
}

function displayLayer(layerID){
	buildDiv(layerID);
	if ( document.getElementById(layerID) != null){
		var dv = document.getElementById(layerID);
		//hiddenLayerOther(layerID);
		if ( dv.style.visibility == "hidden" ) {
			GetCenterXY_ForLayer(dv);
			dv.style.visibility = "visible";
		}
		document.body.onmousemove = function (event){drag(event,dv)};
		document.body.onmouseup = function(){objX = 0;objY=0};
	}
	return false;
}

function hiddenLayer(){
	var argArr = hiddenLayer.arguments;
	for(var i=0;i<argArr.length;i++){
		if ( document.getElementById(argArr[i])!=null ) {
			if ( argArr[i] == 'popupArea' ) {
				//document.getElementById('sub_'+argArr[i]).innerHTML='';
				//document.getElementById('tr_sub_'+argArr[i]).style.display='none';
			}

			document.getElementById(argArr[i]).style.visibility = "hidden";
		}
	}
}




//function $(id){
	//return document.getElementById(id);	
//}


function $(id){    
    if (typeof(id)=="object")   
        return id;   
    if (typeof(id)=="string"){   
        var obj = document.getElementById(id);   
        if(obj != null)   
            return obj;   
        obj = document.getElementsByName(id);   
        if(obj != null && obj.length > 0)   
            return obj[0];   
    }   
    return null;   
} 



function GetHTML(obj,html){
	$(obj).innerHTML=html;
}


function createxmlhttp()
{
	var xmlhttp=false;
	try	{
  		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} 
	catch (e) {
  		try {
   			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} 
		catch (e) {
   			xmlhttp = false;
 		}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  		xmlhttp = new XMLHttpRequest();
				if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
	}	

	return xmlhttp;	
}

function getdata(url,obj1)
{
		var xmlhttp=createxmlhttp();
		if(!xmlhttp)
		{
			alert("你的浏览器不支持XMLHTTP！！");
			return;
		}
		xmlhttp.onreadystatechange=function()
		{
				if(xmlhttp.readyState==4 && xmlhttp.status==200)
				{

					var mes=unescape(xmlhttp.responseText)
					GetHTML(obj1,mes);
				}
				else{
					//GetHTML(obj1,"正在加载数据....");
				}
			
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
}

//显示该对象
function openDIV(obj)
{
	if ($(obj).style.display=="") {$(obj).style.display="none"}
	else {$(obj).style.display=""}
}
		
