//放在此文件最前面
try{
OspodLanguage.languageCheck();
}catch(err){};

function doZoom(num){
	var obj = document.getElementById("zoom");
	obj.style.fontSize=num + "px";
	obj.style.lineHeight=num*2 + "px";
}

function closeMe(){
	window.close(); 
}

/**
* 获得浏览器类型

*/
function Browser() {

  var ua, s, i;
  this.isIE    = false;  // Internet Explorer
  this.isIE7 = false;
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;
  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.version = parseFloat(ua.substr(i + s.length));
    if(this.version == 7){
      this.isIE7 = true;
    }
    this.isIE = true;

    return;
  }

}

var browser = new Browser();

function doPagePrint(obj) {
 //  var oWin = window.open('', 'printwindow', 'menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=400,height=300');
//   var printWrap = document.getElementById(obj);
 // oWin.document.open();
//oWin.document.write(printWrap.innerHTML);
//   alert(printWrap.innerHTML);
// oWin.document.close();
 // oWin.print();
// oWin.close();
	window.print();
}



//==============评论JS开始======================
function doCommentSubmit(id) {
	//var content = document.all("comment.content").value;
	var content = document.getElementsByName("comment.content")[0].value;
	if( content == null || content == "") {
		alert(I18n.commentContentEmpty);
		return;
	}
	var title = document.getElementsByName("comment.title")[0];
	if( title.value == null  || title.value == "" ) {
		title.value = I18n.commentDefaultTitle;
	}

	var url =_contextPath + "/cfn?cmsfn=0101&ID=" + id ;
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
			 if (httpReqeustObject.readyState == 4) {
				 var xmldoc = httpReqeustObject.responseXML;
				 var root = xmldoc.getElementsByTagName('root')[0];
				 var root_node = root.getElementsByTagName('status')[0];
				 var status = root_node.firstChild.data;	
				 var msg_node = root.getElementsByTagName('message')[0];
				 var msg = msg_node.firstChild.data;	

					if(status == "0"){
						if( msg=="NULL" ) 
								msg=I18n.commentSuccess;
						else 
								msg=I18n.commentSuccess + "<br><br>" +msg; 
							_error_msg_show(msg,"window.location=window.location",5,"");
					} else {
						if( msg=="NULL" ) 
							msg=I18n.commentFailure ;
						else
							msg=I18n.commentFailure + "<br><br>" + msg;
						_error_msg_show(msg,"",3,"");   
					}
			 }
		 } //function结束	 

	var formValueStr = getFormParams("commentForm",true);
	 httpReqeustObject.open('POST', url, true);
	 httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
   httpReqeustObject.send(formValueStr);
   
}


function doSupport(id){
	doCommentValueSubmit("0102" , id);
}

function doDisagree(id) {
	doCommentValueSubmit("0103" , id);
}

function doNoCare(id) {
	doCommentValueSubmit("0104" , id);
}

function doCommentValueSubmit(fn, id){
	var url = _contextPath + "/cfn?cmsfn="+fn +"&umID="+id ;
	//var url = "/cmsdemo/templates/red/a.xml";
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 var xmldoc = httpReqeustObject.responseXML;
			 var root = xmldoc.getElementsByTagName('root')[0];
			 var root_node = root.getElementsByTagName('status')[0];
			 var status = root_node.firstChild.data;	
	 			if(status == "0"){
					_error_msg_show(I18n.commentValueSuccess,"windowReload()",5,"");
   				} else {
	   				_error_msg_show(I18n.commentValueFailure,"",3,"");
				}
		}
	 } //function结束	 
   httpReqeustObject.open('GET', url, true);
   httpReqeustObject.send(null);
}

function windowReload() {
	  window.location =  window.location;
}

//==============全文检索JS开始 ======================

//全文检索 
function doSearchSubmit(id){
	//var keyword = document.all("search.keyword").value;
	var keyword = document.getElementsByName("search.keyword")[0].value;
	//alert(keyword);
	if( keyword == null || keyword.replace(/(^\s*)|(\s*$)/g, "")==""){
		alert(I18n.searchKeywordEmpty);
		return;
	}
	//var form = document.forms("searchForm");
	var form = document.forms["searchForm"];
	form.action = _contextPath + "/cc?url=_search";
	form.method = "post";

	var e = getEventSrcElement();
	if(e.tagName.toLowerCase() == "input" && (e.type=="image" || e.type=="submit")){
		//do nothing
	}else{
		form.submit();
	}
}


//高级全文检索
function doAdvancedSearchSubmit(id){
	//var keyword = document.all("search.keyword").value;
	var keyword = document.getElementsByName("search.keyword")[0].value;
	//alert(keyword);
	if( keyword == null || keyword.replace(/(^\s*)|(\s*$)/g, "")==""){
		alert(I18n.searchKeywordEmpty);
		return;
	}

	//var form = document.forms("searchForm");
	var form = document.forms["searchForm"];
	form.action = _contextPath + "/cc?url=_advSearch";
	form.method = "post";
	
	var e = getEventSrcElement();
	if(e.tagName.toLowerCase() == "input" && (e.type=="image" || e.type=="submit")){
		//do nothing
	}else{
		form.submit();
	}
}



//==============留言板JS开始 ======================

function doBoardSubmit(id) {
	if( isNullValue( "board.content" , I18n.boardContentEmpty )) return ; 
	if( isNullValue( "board.title" , I18n.boardTitleEmpty)) return ; 

	var url =_contextPath + "/cfn?cmsfn=0201" ;

	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
	 if (httpReqeustObject.readyState == 4) {
		 var xmldoc = httpReqeustObject.responseXML;
		 var root = xmldoc.getElementsByTagName('root')[0];
		 var status_node = root.getElementsByTagName('status')[0];
		 var status = status_node.firstChild.data;
		 var msg_node = root.getElementsByTagName('message')[0];
		 var msg = msg_node.firstChild.data;	

			if(status == "0"){
				if( msg=="NULL" )
					   msg=I18n.boardCommitSuccess;
				else 
	  				msg=I18n.boardCommitSuccess + "<br><br>" + msg;
					_error_msg_show(msg,"window.location=window.location",5,"");
				} else {
				if( msg=="NULL" ) 
					msg=I18n.boardCommitFailure ;
				else
					msg=I18n.boardCommitFailure + "<br><br>" + msg;
					_error_msg_show(msg,"",3,"");
				}
			}
	 } //function结束	 

   var formValueStr ="boardID=" + id;
	 formValueStr += getAjaxSubmitStr ("board.title" ,  false);
	 formValueStr += getAjaxSubmitStr ("board.user_name" , false);
	 formValueStr += getAjaxSubmitStr ("board.phone" ,  false);
	 formValueStr += getAjaxSubmitStr ("board.email" , false);	 
	 formValueStr += getAjaxSubmitStr ("board.content" ,  false);
	 formValueStr += getAjaxSubmitStr ("board.type", false);
	 //formValueStr += getAjaxSubmitStr ("board.sex" , false);

		
	 //alert(formValueStr);
	 httpReqeustObject.open('POST', url, true);
	 httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
   httpReqeustObject.send(formValueStr);
   
}

//==============公用JS开始 ======================


function getHttpRequestObject() {
	
	var http_request = false ; 

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		  if (http_request.overrideMimeType) {
			   http_request.overrideMimeType('text/xml');
      }
   } else if (window.ActiveXObject) { // IE
     try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
         try {
             http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
     }
   }
	 if (!http_request) {
      alert(I18n.unsupportedHttpProtocol);
      return false;
   }
	return http_request; 
}

function getAjaxSubmitStr(name , firstFlag ) {
	if(!document.all(name)){
		return "";
	}
	var value = 	document.all(name).value;
	if( !value  || value ==null || value == "" ) {
		return "";	
	}
	if(firstFlag )  
		return name + "=" + value;
	else 
		return "&"+name + "=" + value;
}

function isNullValue(name , chineseName) {
	var value = 	document.all(name).value;
	if ( !value || value==null || value=="")  	{
		_error_msg_show( chineseName + I18n.nullValueTipSuffix,"",3,"");
		return true;
	}
	return false;
}

function openWindow( link , width , height , windowParam){
	var widthvalue = (window.screen.width-width)/2;
  var heightvalue = (window.screen.height-height)/2;

  
  var PopWindow;
  PopWindow = window.open(link,"","width="+ width + ",height=" + height+ "," + windowParam   +",left="+widthvalue+",top="+heightvalue,true);
  PopWindow.focus();
}



//======================= votebox start ==================
function doVote(xId){
	var cs = document.all("vote." + xId);
	if(!cs || cs == null || cs == "" ){
		_error_msg_show( I18n.voteItemNotExist,"",3,"");
		return true;
	}
	var ps = "";
	var count = 0;
	if(cs && cs.length){
		for(var i=0;i<cs.length;i++){
			if(cs[i].checked){
				if(count>0){
					ps = ps + "&";
				}
				ps =ps + "vote." + xId + "=" + cs[i].value;
				count++;
			}
		}
	}else if(cs){
		if(cs.checked){
			ps = ps + "vote." + xId + "=" + cs.value;
			count++;
		}
	}
	if(count==0){
		_error_msg_show( I18n.voteItemNotSelected,"",3,"");
		return true;
	}

	var url =_contextPath + "/cfn?cmsfn=0301" ;

	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 var xmldoc = httpReqeustObject.responseXML;
			 var root = xmldoc.getElementsByTagName('root')[0];
			 var status_node = root.getElementsByTagName('status')[0];
			 var status = status_node.firstChild.data;
			 var msg_node = root.getElementsByTagName('message')[0];
			 var msg = msg_node.firstChild.data;	

			if(status == "0"){
				if( msg=="NULL" ){
					   msg=I18n.voteSuccess;
				}else {
					msg=I18n.voteSuccess + "<br><br>" + msg;
				}
				_error_msg_show(msg,"window.location=window.location",5,"");
			} else {
					if( msg=="NULL" ) 
						msg=I18n.voteFailure ;
					else
						msg=I18n.voteFailure + "<br><br>" + msg;
					_error_msg_show(msg,"",3,"");
			}
		 }
	 } //function结束	 

	ps += "&vote.vbox_id=" + xId;

	var nextUrl = _contextPath + "/cc?url=_voteResult&vote.vbox_id=" + xId;
	url = _contextPath + "/cc?url=_checkNum&checknum.forward=" + encodeURIComponent(nextUrl) + "&checknum.action=" + encodeURIComponent(url + "&" + ps);
	//alert(url);
	openWindow(url,400,400,"resizable=yes");

}

function doViewVote(xId){
	openWindow(_contextPath + "/cc?url=_voteResult&vote.vbox_id=" + xId,400,400,"resizable=yes");
}
//======================= votebox end  ===================

//======================= check Num start ================

function chgAuthImg(){
	var authImg = document.getElementById('auth_img');
	authImg.src = _contextPath + "/cfn?cmsfn=0401" + '&' + Math.random() ;
	var cNum = document.getElementById('checkNum.inputNum');
	cNum.value = "";
}

function doCheckNum(){
	var url =_contextPath + "/cfn?cmsfn=0402" ;
	var inputNum = document.getElementById("checkNum.inputNum");
	url += "&checkNum.inputNum=" + inputNum.value;

	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 var xmldoc = httpReqeustObject.responseXML;
			 var root = xmldoc.getElementsByTagName('root')[0];
			 var status_node = root.getElementsByTagName('status')[0];
			 var status = status_node.firstChild.data;
			 var msg_node = root.getElementsByTagName('message')[0];
			 var msg = msg_node.firstChild.data;	

			if(status == "0"){
				var sa = document.getElementById("successAction");
				var forward = document.getElementById("forward");
				if(sa.value != ""){
					 httpReqeustObject = getHttpRequestObject();
					 httpReqeustObject.onreadystatechange = function() {
						 if (httpReqeustObject.readyState == 4) {
							window.location=forward.value;
						 }
					 }

					httpReqeustObject.open('POST', sa.value, true);
					httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
					httpReqeustObject.send(null);
				}else{
					window.location=forward.value;
				}
			} else {
				chgAuthImg();
				inputNum = document.getElementById("checkNum.inputNum");
				inputNum.value="";
				inputNum.focus();
				_error_msg_show(msg,"",3,"");
			}
		 }
	 } //function结束	 

	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(null);
}
//======================= check Num end   ================

//======================= user register start ============
function getFormParams(formName,isEncodeURI){
	var formE = document.getElementById(formName);
	//var formE = document.getElementsByName(formName)[0];
	if(!formE || !formE.tagName || formE.tagName.toLowerCase() != "form") {
		throw new Error(I18n.formBindFailure);
	} 
	var params = "";
	var inputs = formE.getElementsByTagName("input");
	var count = 0;
	if(isEncodeURI==null){
		isEncodeURI=false;
	}
	if(inputs){
		for(var i = 0; i < inputs.length; i++) {
			var input = inputs[i];
			var tagType = input.type.toLowerCase();
			if( tagType == "image" || tagType == "button" 
				|| tagType == "file" || tagType == "reset" || tagType == "submit") {
				continue;
			}
			if(count > 0){
				params += "&";
			}
			if((tagType == "radio" || tagType == "checkbox")){
				if(input.checked){
					params += input.name + "=" + (isEncodeURI?encodeURIComponent(input.value):input.value);
				}
			}else{
				params += input.name + "=" + (isEncodeURI?encodeURIComponent(input.value):input.value);
			}
			count++;
		}
	}

	var selects = formE.getElementsByTagName("select");
	if(selects){
		for(var i=0; i<selects.length; i++){
			var select = selects[i];
			if(count > 0){
				params += "&";
			}
			params += select.name + "=" + (isEncodeURI?encodeURIComponent(select.options[select.selectedIndex].value):select.options[select.selectedIndex].value);
		}
	}
	var areas = formE.getElementsByTagName("textarea");
	if(areas){
		for(var i=0; i<areas.length; i++){
			var area = areas[i];
			if(count > 0){
				params += "&";
			}
			params += area.name + "=" + (isEncodeURI?encodeURIComponent(area.value):area.value);
		}
	}

	//alert(params);

	return params;
}

function doUserReg(){
	var e = getEventSrcElement();
	if(e!= null){
		e.disabled = true;
	}
	var url = _contextPath + "/cfn?cmsfn=0501";
	var ps = getFormParams('userRegForm',true);
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {					 
			if( e != null ) {
			  e.disabled=false;
			}
			userInfoResponse(httpReqeustObject);
		 }
	 } //function结束	 

	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(ps);
}

function userInfoResponse(httpRequestObject){
	var xmldoc = httpReqeustObject.responseXML;
	var root = xmldoc.getElementsByTagName('root')[0];
	var status_node = root.getElementsByTagName('status')[0];
	var status = status_node.firstChild.data;	

	if(status == "0"){
		var msg_node = root.getElementsByTagName('message')[0];
		var msg = msg_node.firstChild.data;	
		_error_msg_show(msg,"window.location=window.location",3,"");
	} else {
		var errorInfos = document.getElementsByName("_error");
		if(errorInfos.length != undefined && errorInfos.length > 0){
			var eiLength = errorInfos.length;
			for(var h=0; h<eiLength;h++){
				errorInfos.item(0).removeNode(true);
			}
		}
		var msgNodes = root.getElementsByTagName('message');
		if(msgNodes.length == 1 && msgNodes.item(0).getElementsByTagName('key').length == 0){
			var msg = msgNodes.item(0).firstChild.data;	
			_error_msg_show(msg,"window.location=window.location",3,"");
			return;
		}
		var info = "";
		if(msgNodes.length > 0){
			var count = 0;
			for(var i=0; i<msgNodes.length; i++){
				var msg = msgNodes.item(i);
				if(count > 0){
					info += "\n";
				}
				var mKey = msg.getElementsByTagName('key')[0].firstChild.data;
				var mValue = msg.getElementsByTagName('value')[0].firstChild.data;
				info += mKey + mValue;
				var errorE = document.getElementsByName(mKey)[0];
				if(errorE){
					var parentE = errorE.parentNode;
					var	errorInfoE;
					if(browser.isIE){
						errorInfoE = document.createElement("<b class=\"user_error_info\" id=\"_error\" name=\"_error\"></b>");
					}else{
						errorInfoE = document.createElement("b");
						errorInfoE.setAttribute("class","user_error_info");
						errorInfoE.setAttribute("id","_error");
						errorInfoE.setAttribute("name","_error");
					}
					parentE.appendChild(errorInfoE);
					errorInfoE.innerHTML = mValue;
				}else{
					alert(I18n.userNotFoundItem + mKey);
				}

			}
		}
	}
}


function doUserUpdate(){
	var url = _contextPath + "/cfn?cmsfn=0504";
	var ps = getFormParams('userUpdateForm',true);
		
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 
			 userInfoResponse(httpReqeustObject);
		 }
	 } //function结束	 

	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(ps);
}


function doUserDuplicateCheck(){
	var url = _contextPath + "/cfn?cmsfn=0503";
	var uId = document.getElementById("user_id");
	if(uId.value == "" || uId.value == null){
		_error_msg_show(I18n.userIdEmpty,"window.location=window.location",5,"");
		uId.focus();
		return;
	}
	var ps = "uId=" + uId.value;
	
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 var xmldoc = httpReqeustObject.responseXML;
			 var root = xmldoc.getElementsByTagName('root')[0];
			 var status_node = root.getElementsByTagName('status')[0];
			 var status = status_node.firstChild.data;
			 var msg_node = root.getElementsByTagName('message')[0];
			 var msg = msg_node.firstChild.data;

			if(status == "0"){
				if( msg=="NULL" ){
					   msg=I18n.userNotUsed;
				}
				_error_msg_show(msg,"",3,"");
			} else {
				if( msg=="NULL" ) {
					msg=I18n.userAlreadyExist ;
				}
				_error_msg_show(msg,"",5,"");
			}
		 }
	 } //function结束	 

	
	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(ps);
}


function doUserLogin(){
	var url = _contextPath + "/cfn?cmsfn=0505";
	var uId = document.getElementById("user_id");
	if(uId.value == "" || uId.value == null){
		_error_msg_show(I18n.userIdEmpty,"",5,"");
		uId.focus();
		return;
	}
	var uPasswd = document.getElementById("user_passwd");
	if(uPasswd.value == "" || uPasswd.value == null){
		_error_msg_show(I18n.userPasswordEmpty,"",5,"");
		uPasswd.focus();
		return;
	}
	var cNum = document.getElementById("checkNum.inputNum");

	var ps = "user_id=" + uId.value + "&user_passwd=" + uPasswd.value + "&checkNum.inputNum=" + cNum.value;
	
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 var xmldoc = httpReqeustObject.responseXML;
			 var root = xmldoc.getElementsByTagName('root')[0];
			 var status_node = root.getElementsByTagName('status')[0];
			 var status = status_node.firstChild.data;
			 var msg_node = root.getElementsByTagName('message')[0];
			 var msg = msg_node.firstChild.data;
			if(status == "0"){
				window.location.reload();
			} else {
				_error_msg_show(msg,"",5,"");
				chgAuthImg();
			}
		 }
	 } //function结束	 

	
	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(ps);
}

function getWindowEvent(){
	if(browser.isIE){
		return window.event;
	}else{
		var o = arguments.callee.caller; 
		var e; 
		while(o != null){ 
			e = o.arguments[0]; 
			if(e && (e.constructor == Event || e.constructor == MouseEvent)) {return e;} 
				o = o.caller; 
			} 
		return null;
	}
}

function getEventSrcElement(){
	var event = getWindowEvent();
	if(event != null){
		var e = event.target || event.srcElement;
		return e;
	}
	return null;
}

function doUserInfoEdit(){
	//var e = getEventSrcElement();
	//e.href = _contextPath + '/cc?url=_userEdit';	
	window.location =  _contextPath + '/cc?url=_userEdit';
}

function doRegisterUser(){
	//var e = getEventSrcElement();
	//e.href = _contextPath + '/cc?url=_userReg';
	window.location = _contextPath + '/cc?url=_userReg';
}

function doPasswdRetrieve(){
	//var e = getEventSrcElement();
	//e.href = _contextPath + '/cc?url=_forgetPassword';
	window.location = _contextPath + '/cc?url=_forgetPassword';
}

function getRequestCookie(name){
   var arg = name + "="; 
   var alen = arg.length; 
   var clen = document.cookie.length; 
   var i = 0; 
   while (i < clen) { 
   var j = i + alen; 
   if (document.cookie.substring(i, j) == arg) 
   return getcookieval(j); 
   i = document.cookie.indexOf(" ", i) + 1; 
   if (i == 0) break; 
   } 
   return null; 
}

function doUserLogout(){
	var url = _contextPath + '/cfn?cmsfn=0506';
	
	 var nowLocation = window.location;
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			window.location=nowLocation;
			return;
		 }
	 }  
	
	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(null);
	return;
}

function doRetrievePasswd(){
	var  url = _contextPath + '/cfn?cmsfn=0507';

	var uId = document.getElementById("user_id");
	var uEmail = document.getElementById("user_email");
	var uQuestion = document.getElementById("user_question");
	var uanswer = document.getElementById("user_answer");
	var cNum = document.getElementById("checkNum.inputNum");

	var ps = "user_id=" + uId.value + "&user_email=" + uEmail.value 
		+ "&user_question=" + uQuestion.value + "&user_answer=" + uanswer.value
		+ "&checkNum.inputNum=" + cNum.value;

	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			 var xmldoc = httpReqeustObject.responseXML;
			 var root = xmldoc.getElementsByTagName('root')[0];
			 var status_node = root.getElementsByTagName('status')[0];
			 var status = status_node.firstChild.data;
			 var msg_node = root.getElementsByTagName('message')[0];
			 var msg = msg_node.firstChild.data;

			if(status == "0"){
				_error_msg_show(I18n.userRetrievePasswordSuccess,"",3,"");
			} else {
				if( msg=="NULL" ) {
					msg=I18n.userRetrievePasswordFailure ;
				}
				_error_msg_show(msg,"",5,"");
			}
		 }
	 }  
	
	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send(ps);
}
//======================= user register end ==============

function changeErrorStackStatus(){
	var e = document.getElementById("errorStackInfo");
	if(e.style.display=="none"){
		e.style.display="block";
	}else{
		e.style.display="none";
	}
}

function cmsDownload(cmsId,fld,flag){
	if(!cmsId || !fld){
		alert(I18n.downloadFileNotExist);
		return false;
	}
	//var e = event.srcElement;
	var e = getEventSrcElement();
	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
		 if (httpReqeustObject.readyState == 4) {
			var status = httpReqeustObject.responseText;
			if(status && status=="true"){
				return true;
			}else{
				alert(I18n.downloadInfoUpdateFailure);
				return false;
			}
		 }
	 }

	var url = _contextPath + "/down?ID=" + cmsId + "&fld=" + fld;
	httpReqeustObject.open('POST', url, true);
	httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    httpReqeustObject.send("");
}

function changeLocale(locale){
	var e = getEventSrcElement();
	setCookie("_cmsLocale",locale);
	window.location.reload();
}

function showLocaleSelector(){
	var e = getEventSrcElement();
	var menu = document.getElementById("localeSelect");
	menu.style.position = "absolute";
	menu.style.display="block";
	var ePos = getElementPosition(e);
	menu.style.left = ePos.left +  menu.offsetWidth < document.body.offsetWidth ? ePos.left + "px" : 
		((window.screen.width - document.body.offsetWidth)/2 +document.body.offsetWidth-menu.offsetWidth-11)+"px";
	menu.style.top = ePos.top + e.offsetHeight;

}

function hiddenLocaleSelector(event){    
    var label = document.getElementById("changeLocale");
	var menu = document.getElementById("localeSelect"); 
	var ePos = getElementPosition(menu);
	var eventX = event.x ? event.x : event.pageX;
	eventX += document.documentElement.scrollLeft;
	var eventY = event.y ? event.y : event.pageY;
	eventY += document.documentElement.scrollTop;
	if(eventX   >   0   &&   eventX   <  ePos.left + menu.offsetWidth  && eventX > ePos.left   
	&&   eventY   >   0   &&   eventY   <  ePos.top + menu.offsetHeight && eventY > ePos.top)   return;


	//alert("event.x:" + eventX + ",event.y:" + eventY + ",menu.offsetWidth:" + menu.offsetWidth + ",menu.offsetHeight:" + menu.offsetHeight + ",menu.offsetLeft:" + menu.offsetLeft + ",menu.offsetTop:" + menu.offsetTop);
	menu.style.display="none";
	menu.scrollLeft=0;
	menu.scrollTop=0;
}

function getElementPosition(obj) {
    var left_offset = obj.offsetLeft;
    var top_offset = obj.offsetTop;
    
    while((obj = obj.offsetParent) != null) {     

      left_offset += obj.offsetLeft;
      top_offset += obj.offsetTop;

    }

    return { 'left' : left_offset, 'top' : top_offset };
}

function setCookie(name,value,duration)//两个参数，一个是cookie的名子，一个是值,一个是期限,单位为天，默认30天
{
    var Days = duration ? duration : 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}



function includeJs(file){

	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
			 if (httpReqeustObject.readyState == 4) {
				document.write("<script language=\"javascript\" type=\"text/javascript\">" + httpReqeustObject.responseText + "</script>");
			 }
		 } //function结束	 

	 httpReqeustObject.open('GET', file, false);
	 httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
   httpReqeustObject.send(null);
}

function includeCss(file){

	 httpReqeustObject = getHttpRequestObject();
	 httpReqeustObject.onreadystatechange = function() {
			 if (httpReqeustObject.readyState == 4) {
				document.write("<style>" + httpReqeustObject.responseText + "</style>");
			 }
		 } //function结束	 

	 httpReqeustObject.open('GET', file, false);
	 httpReqeustObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
   httpReqeustObject.send(null);
}

function OspodSlide(pic,width,height,link,text,itv,spd){
  //
//alert(arguments.callee.length);
  if(arguments.length<1){//判断形参和实参数是否相等
    alert(I18n.slideIllegalParameter);
    return false;
  }

  var interval = itv ? itv : 3000;//图片变换间隔
  var duration = spd ? spd : 50;//默认值//滤镜效果的速度
  var xsImgWidth = width ? width : 100 ;//保存图片长和宽
  var xsImgHeight = height ? height : 100 ;
  var link = link ? link : '';
  var texts = text ? text : '';
  texts = texts.replace("\"\"","&quot;");

  var xsTextBar = 1;
  var dNum = 4;
  var pics = pic;
  var textHgt = 25;
  var textBgc = '#000000';
  var slideType = 1;
  var slideBgc = '#000000';
  
  this.setSlideType = function(type){//设置附加参数
    slideType = type;
  }
  
  this.setTextBgc = function(tbgc){
    textBgc = tbgc;
  }

  this.setTextHgt = function(thgt){
    textHgt = thgt;
  }

  this.setdNum = function(dnum){
    dNum = dnum;
  }
  this.setSlideBgc = function(bgColor){
	slideBgc = bgColor;
  }

  var xsImgs = new Array();//图片路径
  var xsImgLinks = new Array();//图片链接
  var xsImgTexts = new Array();//图片说明
  var xsTempImgs = new Array();//缓存图片
  var xsTempImg =new Array();
  var offsetIndex = 0;
  //

  var transitions = new Array;//滤镜
  transitions[0] = "progid:DXImageTransform.Microsoft.Fade(duration="+duration/50+")";
  transitions[1] = "progid:DXImageTransform.Microsoft.GradientWipe(duration="+duration/50+")";
  transitions[2] = "progid:DXImageTransform.Microsoft.Pixelate(maxSquare=10,duration="+duration/50+")";
  transitions[3] = "progid:DXImageTransform.Microsoft.Barn(function=15, duration="+duration/50+")";
  var transition_count = transitions.length;

  var timerId = -1;
  var curImg = 0;//初始图片为curImg+1的图片

  this.initSize =  function(){//图片宽度及缩略图比例计算
    var tHeight =  Math.floor(xsImgHeight*0.75);
    if(browser.isIE7){
      var bImgWidth = (xsImgWidth-18)/dNum;
      var bImgHeight = xsImgHeight>350?xsImgHeight*0.225:xsImgHeight*0.21-1;
    }else if(browser.isIE){
      var bImgWidth = (xsImgWidth-18)/dNum;
      var bImgHeight = xsImgHeight>350?xsImgHeight*0.225:xsImgHeight*0.21-1;
    }else{
      var bImgWidth = (xsImgWidth-18)/dNum;
      var bImgHeight = xsImgHeight>350?xsImgHeight*0.225:xsImgHeight*0.20;
    }
    var bWidth = xsImgWidth;//图片宽度和高度

    var bHeight = Math.floor(xsImgHeight*0.25);
    //xsImgHeight += 4;
    return {'tHeight':tHeight,'bWidth':bWidth,'bImgHeight':bImgHeight,'bImgWidth':bImgWidth,"bHeight":bHeight};
  }

  var bSize;

  this.init = function(){
    bSize = this.initSize();//获得各元素的尺寸

      xsImgs = pics.split("|");
      
      if(link.length == 0){
        for(var i = 0;i<xsImgs.length;i++){
          xsImgLinks[i] = '';
        }
      }else{
        xsImgLinks = link.split("|");
      }
      
      if(texts.length == 0){
        for(var i = 0;i<xsImgs.length;i++){
          xsImgTexts[i] = '';
        }
      }else{
         xsImgTexts = texts.split("|");
      }


      if(slideType){
        document.write("<style type=\"text/css\">");
        document.write("#slidearea{background-color:"+slideBgc+";border:1px solid #959595;width:"+xsImgWidth+"px;height:"+xsImgHeight+"px;}");
        document.write("#slidearea #slidebody{ width:100%; height:" + bSize['tHeight'] + "px; overflow: hidden; margin: 0 auto; text-align: center;vertical-align:middle;} ");

        document.write("#slidearea #slidebody .img{*margin-top:expression((parentElement.parentElement.offsetHeight-this.offsetHeight)/2);}");

        document.write("#slidearea #slidefooter{overflow:hidden;height:" + bSize['bHeight'] + "px;width:100%;}");

        document.write("#slidearea  img{border:0px}");

        document.write("#slidearea #slidefooter img.img1{border:1px solid #959595;padding:1px;}");

        document.write("#slidearea #slidefooter img.img2{border:1px solid #FF0000;padding:1px;}");
        
        document.write("#slidearea #slidefooter img.img3{border:1px solid #33FF00;padding:1px;}");

        document.write("#slidearea #slidefooter table{vertical-align:middle;border-collapse:collapse; margin:1px auto;width:100%;}");

        document.write("#slidearea #slidefooter table td{vertical-align:middle;text-align:center;width:"+bSize['bImgWidth']+"px;}");

        document.write("#slidearea #slidetext {overflow:hidden;word-break:break-all;text-align:center;width:100%;background-color: "+textBgc+"; filter:alpha(opacity=80);border-bottom:1px solid #959595;margin-top:-"+textHgt+"px;line-height:"+textHgt+"px;height:"+textHgt+"px;opacity: 0.80;font-family: 黑体; font-size:16px;color:#ffffff;}");

        document.write("</style>");

        document.write("<div id=\"slidearea\">");
        document.write("<div id=\"slidebody\">" );

        if (xsImgs.length != 0) {
          document.write("<a id=\"imglink\" href=\"" + xsImgLinks[0] + "\" target=\"_blank\"><img id=\"xsimgV\" title=\"" + xsImgTexts[0] + "\" src=\"" + xsImgs[0] + "\" width=" + bSize['bWidth'] + " height=" + bSize['tHeight'] + "\" onload=\"imgZoomer(this," + bSize['bWidth'] + "," + bSize['tHeight'] + ");\" /><\/a>");
        }

        var xsTempV =  document.getElementById('xsimgV');//缓存图片
        for(var i=0;i<xsImgs.length;i++){
          xsTempImg[i] = xsTempV.cloneNode(true);
          xsTempImg[i].src = xsImgs[i];
        }

        document.write("<\/div>");
        document.write("<div id=\"slidetext\">"+xsImgTexts[0]+"<\/div>");//+ xsImgTexts[0] +"<\/span>");
        if (xsTextBar != 0) {
          document.write("<div id=\"slidefooter\">");
          document.write("<table cellpadding=0 cellspacing=0 style=\"table-layout:fixed;\" ><tr><td style=\"width:9px;\" align=\"left\" nowrap><a href=\"#\" onclick=\"OspodSlide.prototype.forward(-1);return false\"><img src=\"img/focus_back1.gif\" onmouseout=\"this.src='img/focus_back1.gif';\" onmouseover=\"javascript:this.src='img/focus_back2.gif';\" onload=\"imgZoomer(this,9," + bSize['bImgHeight'] + ")\"></a></td><td style=\"width:"+(bSize['bWidth']-18)+"px;height:"+(bSize['bImgHeight'])+"px;\"><table  style=\"width:"+(bSize['bWidth']-18)+"px;height:"+(bSize['bImgHeight'])+"px;\"><tr>");
          dNum = xsImgs.length > dNum ? dNum : xsImgs.length;

          for(var i=0;i<dNum;i++){
            document.write("<td><a href=\"#\" id=\"imgtd"+i+"\" onclick=\"OspodSlide.prototype.selectImg("+i+");return false\"><img class=\"img1\" id=\"xs"+i+"\" src=\""+xsImgs[i]+"\" width=\""+bSize['bImgWidth']+"\" height=\""+bSize['bImgHeight']+"\" onload=\"imgZoomer(this,"+bSize['bImgWidth']+","+bSize['bImgHeight']+");OspodSlide.prototype.mouseSelect(this,"+i+");\"></a></td>");
          }
          var xsTemp = document.getElementById('xs0');
          for(var i=0;i<xsImgs.length;i++){//缓存缩略图
            xsTempImgs[i] = xsTemp.cloneNode(true);
            xsTempImgs[i].src = xsImgs[i];
            xsTempImgs[i].id = 'xs'+i;
          }
          document.write("</tr></table></td><td style=\"width:9px;\" align=\"right\" nowrap ><a href=\"#\" onclick=\"OspodSlide.prototype.forward(1,1);return false\"><img style=\"text-align:right;\" src=\"img/focus_forward1.gif\" onmouseout=\"this.src='img/focus_forward1.gif';\" onmouseover=\"javascript:this.src='img/focus_forward2.gif';\" onload=\"imgZoomer(this,9," + bSize['bImgHeight'] + ")\"></a></td><\/tr><\/table>");
          document.write("<\/div>");
        }
        document.write("<\/div>");
      }else{
        document.write("<style type=\"text/css\">#slidebody {background-color:"+slideBgc+";border:1px solid #959595; width:" + xsImgWidth + "px; height:" + xsImgHeight + "px; overflow: hidden; margin: 0 auto; text-align: center; vertical-align:middle;display: table-cell;} #slidearea img {*margin-top:expression((parentElement.parentElement.offsetHeight-this.offsetHeight)/2);}</style>");
        document.write("<div id=\"slidebody\">");
        if (xsImgs.length != 0) {
          document.write("<a id=\"imglink\" href=\"" + xsImgLinks[0] + "\" target=\"_blank\"><img id=\"xsimgV\" title=\"" + xsImgTexts[0] + "\" src=\"" + xsImgs[0] + "\" width=" + xsImgWidth + " height=" + xsImgHeight + "\" onload=\"imgZoomer(this," + xsImgWidth + "," + xsImgHeight + ");\" /><\/a>");
		  
			var xsTempV =  document.getElementById('xsimgV');//缓存图片
			for(var i=0;i<xsImgs.length;i++){
			  xsTempImg[i] = xsTempV.cloneNode(true);
			  xsTempImg[i].src = xsImgs[i];
			}
        }
        document.write("<\/div>")
      }
      window.setTimeout("OspodSlide.prototype.play()", interval);//刷新页面后变换图片的时间
  }


  OspodSlide.prototype.mouseSelect =  function(obj,i){
	  /*
    obj.onmouseover = function(){ OspodSlide.prototype.slideOver(obj,i);}
    obj.onmouseout = function(){OspodSlide.prototype.slideOut(obj,i);}
	*/
    obj.onmouseover = OspodSlide.prototype.slideOver.bind(obj,i);
    obj.onmouseout = OspodSlide.prototype.slideOut.bind(obj,i);
    if(obj.id == 'xs0'){
      document.getElementById('xs0').style.border = "1px solid #33FF00";
      document.getElementById('xs0').style.padding = "1px";
      var Oimg = document.createElement('img');
      Oimg.src = obj.src;
      imgZoomer(Oimg,bSize['bImgWidth'],bSize['bImgHeight']);
      document.getElementById('xs0').style.height = Oimg.height;
      document.getElementById('xs0').style.width =Oimg.width;
    }
  }
  
  OspodSlide.prototype.slideOver = function(img,i){
    img.style.border = "1px solid #FF0000";
    img.style.padding = "1px";
  }

  OspodSlide.prototype.slideOut = function(img,i){
    var Oimg = document.createElement('img');
    Oimg.src = xsTempImgs[i].src;
    imgZoomer(Oimg,bSize['bImgWidth'],bSize['bImgHeight']);
    img.height = Oimg.height;
    img.width = Oimg.width;
    img.style.border = "1px solid #959595";
    img.style.padding = "1px";
    if(i == curImg){
      OspodSlide.prototype.selectedImg(curImg,0);
    }
  }


  OspodSlide.prototype.changeSlide = function(){
    if (document.all){//如果是firefox浏览器 不使用滤镜，单纯替换图片
      var do_transition = Math.floor(Math.random() * transition_count);//取随机滤镜
      document.getElementById('slidebody').style.filter=transitions[do_transition];
      document.getElementById('slidebody').filters[0].Apply();
    }
	if (xsImgs.length !=0){
		document.getElementById('imglink').href = xsImgLinks[curImg];
		document.getElementById('imglink').innerHTML= "";
		document.getElementById('imglink').appendChild(xsTempImg[curImg]);
		document.getElementById('xsimgV').title= xsImgTexts[curImg];
		if(slideType){
			var slideText = xsImgTexts[curImg];
			document.getElementById('slidetext').innerHTML = slideText;
		}
		if (document.all) {
			document.getElementById('slidebody').filters[0].Play();
		}
	}
}

  OspodSlide.prototype.forward = function(j,type){
    if(j){
      curImg = j;
    }else{
      curImg++;
    }
    if (dNum) {
      if(curImg==1){//正常滚动
        for(var i=0;i<xsImgs.length;i++){
          if(i==0){
            var xsImges = xsTempImgs[i];
            var xsImg =  xsTempImg[i];
            var xsText = xsImgTexts[i];
            var xsLink = xsImgLinks[i];
            xsTempImgs[i] = xsTempImgs[i+1];
            xsTempImg[i] = xsTempImg[i+1];
            xsImgTexts[i] = xsImgTexts[i+1];
            xsImgLinks[i] = xsImgLinks[i+1];
          }else if(i == (xsImgs.length-1)){
            xsTempImgs[i] = xsImges;
            xsTempImg[i] = xsImg;
            xsImgTexts[i] = xsText;
            xsImgLinks[i] = xsLink;
          }else{
            xsTempImgs[i] = xsTempImgs[i+1];
            xsTempImg[i] = xsTempImg[i+1];
            xsImgTexts[i] = xsImgTexts[i+1];
            xsImgLinks[i] = xsImgLinks[i+1]
          }
        }
        OspodSlide.prototype.selectedImg(curImg-1,0);
        if(type){
          window.clearInterval(timerId);
     
          timerId = window.setInterval('OspodSlide.prototype.forward();', interval);
        }
      }else{//从点击的地方开始移动
        var mPs = new Array();
        var mP = new Array();
        var mT = new Array();
        var mL = new Array();
        for(var i=0;i<xsImgs.length;i++){//复制图片信息
         mPs[i] = xsTempImgs[i];
         mP[i] = xsTempImg[i];
         mT[i] = xsImgTexts[i];
         mL[i] = xsImgLinks[i];
        }
        if(j==-1){
          curImg = xsImgs.length+j;
        }

        for(var i=0;i<xsImgs.length;i++){
          var m = i-curImg;
          if(m < 0){
            m = xsImgs.length - curImg+i;
          }
          xsTempImgs[m] = mPs[i];
          xsTempImg[m] = mP[i];
          xsImgTexts[m] = mT[i];
          xsImgLinks[m] = mL[i];
        }
          OspodSlide.prototype.selectedImg(xsImgs.length - curImg-1,0);

          window.clearInterval(timerId);
          timerId = window.setInterval('OspodSlide.prototype.forward();', interval);
      }
        curImg = 0;
        var imgfooter="";

        dNum = (xsImgs.length) > dNum ? dNum : xsImgs.length;

        for(var i=0;i<dNum;i++){
          var Oimg =new  Image();
          Oimg.src = xsTempImgs[i].src;
          imgZoomer(Oimg,bSize['bImgWidth'],bSize['bImgHeight']);
          document.getElementById('imgtd'+i).innerHTML= "";
          document.getElementById('imgtd'+i).appendChild(xsTempImgs[i]);

          document.getElementById(xsTempImgs[i].id).style.width =  Oimg.width;
          document.getElementById(xsTempImgs[i].id).style.height =  Oimg.height;
        }
      }else if(curImg >= dNum){
        curImg = 0;
      }
      OspodSlide.prototype.changeSlide();
  }

  OspodSlide.prototype.forward_e = function(){
    curImg++;
    if (curImg >= xsImgs.length) {
      curImg = 0;
    }
    OspodSlide.prototype.changeSlide();
  }


  OspodSlide.prototype.rewind = function(){
    curImg--;
    if (curImg < 0)
    {
      curImg = xsImgs.length-1;
    }
    OspodSlide.prototype.changeSlide();
  }

  OspodSlide.prototype.play = function(){
    if (timerId == -1){
      if(slideType){
        timerId = window.setInterval('OspodSlide.prototype.forward();', interval);
      }else{
        timerId = window.setInterval('OspodSlide.prototype.forward_e();', interval);
      }
    }
  }

  OspodSlide.prototype.selectImg = function(i){//选择性变换图片
    OspodSlide.prototype.selectedImg(i,1);
  }

  OspodSlide.prototype.selectedImg = function(j,type){//点击缩略图,type
   var img = document.createElement('img');//获得缩略图大小
   dNum = xsImgs.length > dNum ? dNum : xsImgs.length;
   for(var i=0;i<dNum;i++){
     if(i == j){
        xsTempImgs[j].style.border = "1px solid #33FF00";
        xsTempImgs[j].style.padding = "1px";
        if(document.getElementById('xs'+j)){
          document.getElementById('xs'+j).style.border = "1px solid #33FF00"; 
          document.getElementById('xs'+j).style.padding = "1px";
        }
        img.src = xsTempImgs[j].src;
        imgZoomer(img,bSize['bImgWidth'],bSize['bImgHeight']);

        xsTempImgs[j].height = img.height;
        xsTempImgs[j].width = img.width;

        if(type){
         if(j==0){
          img.src = xsTempImgs[dNum-1].src;
          imgZoomer(img,bSize['bImgWidth'],bSize['bImgHeight']);

          xsTempImgs[dNum-1].className = "img1";
          xsTempImgs[dNum-1].height = img.height;
          xsTempImgs[dNum-1].width = img.width;
         }else{
          img.src = xsTempImgs[j-1].src;
          imgZoomer(img,bSize['bImgWidth'],bSize['bImgHeight']);

           xsTempImgs[j-1].style.border = "1px solid #959595";
           xsTempImgs[j-1].style.padding = "1px";

           xsTempImgs[j-1].height = img.height;
           xsTempImgs[j-1].width = img.width;
         }
         OspodSlide.prototype.forward(j);
        }
     }else{
       xsTempImgs[i].style.border = "1px solid #959595";
       xsTempImgs[i].style.padding = "1px";
       img.src = xsTempImgs[i].src;
       imgZoomer(img,bSize['bImgWidth'],bSize['bImgHeight']);

       xsTempImgs[i].height = img.height;
       xsTempImgs[i].width = img.width;
     }
   }
 }
}



//不失真加载图片
function imgZoomer(imgObj,canvas_width,canvas_height){
    var obj = imgObj;
    var src_width = GetImageWidth(obj);
    var src_height =GetImageHeight(obj);
    var widthScale =  src_width / canvas_width;
	  var heightScale = src_height / canvas_height;
  
    if (widthScale >= 1 || heightScale >= 1) {
      //哪边差的小，以哪边为基准放大
      if (widthScale < heightScale) {
        obj.width = src_width / heightScale;
        obj.height = canvas_height;
      } else {
        obj.width = canvas_width;
        obj.height = src_height / widthScale;
      }
    }else {
        obj.width = src_width;
        obj.height = src_height;
    }
}

var OriginImage=new Image();
function GetImageWidth(oImage){
  if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src;
  return OriginImage.width;
}

function GetImageHeight(oImage){
  if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src;
  return OriginImage.height;
}

//dir可为空
function ImageViewer(obj,dir){

  var IMGDIR= (dir!=null) ? dir: "img";//图标路径

  var zoomobj =new Array();
  
  var zoomimglayer_bg = document.getElementById('zoomimglayer_bg');//背景层
  var zoomimglayer = document.getElementById('zoomimglayer'); //图片层


  this.zoom = function(obj){
    var append_parent = document.getElementById('append_parent');
  
    if(!append_parent){//创建外层DIV容器
      append_parent  = document.createElement('div');
      append_parent.id = 'append_parent';
        
      document.body.appendChild(append_parent);
    }

    zimg = obj.src;

    //zoomimglayer_bg = document.getElementById('zoomimglayer_bg');
    if(!zoomimglayer_bg){//创建半透明的图片背景
      zoomimglayer_bg = document.createElement('div');
      zoomimglayer_bg.id = 'zoomimglayer_bg';
      zoomimglayer_bg.style.position = 'absolute';
      zoomimglayer_bg.style.top = '0px';
      zoomimglayer_bg.style.left = '0px';
	  /*
      if(browser.isIE){
        zoomimglayer_bg.style.width = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth + 'px';//获得窗口宽度
      }else{
        zoomimglayer_bg.style.width = document.body.clientWidth+'px';
      }
	  */
	  zoomimglayer_bg.style.width = document.documentElement.clientWidth > document.body.clientWidth ? document.documentElement.clientWidth + 'px' : document.body.clientWidth + 'px';
	  

      zoomimglayer_bg.style.height = document.body.scrollHeight +'px';

      zoomimglayer_bg.style.backgroundColor = '#000';
      zoomimglayer_bg.style.display = 'none';
      zoomimglayer_bg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=80,finishOpacity=100,style=0)';
      zoomimglayer_bg.style.opacity = 0.8;
      append_parent.appendChild(zoomimglayer_bg);
      
      zoomimglayer = document.createElement('div');//点击图片时出现的动画层
      zoomimglayer.id = 'zoomimglayer';
      zoomimglayer.style.position = 'absolute';
      zoomimglayer.style.padding = 0;
      append_parent.appendChild(zoomimglayer);
    }
    zoomobj['srcinfo'] = this.fetchOffset(obj);//取得页面上的图片位置
    zoomobj['srcobj'] = obj;
    zoomobj['zimg'] = zimg;


    zoomimglayer.style.display = '';
    
    zoomimglayer.style.left = zoomobj['srcinfo']['left'] + 'px';
    zoomimglayer.style.top = zoomobj['srcinfo']['top'] + 'px';
    zoomimglayer.style.width = zoomobj['srcobj'].width + 'px';
    zoomimglayer.style.height = zoomobj['srcobj'].height + 'px';
    zoomimglayer.style.border = "0px solid #FF0000";
    zoomimglayer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=40,finishOpacity=100,style=0)';
    zoomimglayer.style.opacity = 0.4;
    zoomimglayer.style.zIndex = 999;
    zoomimglayer.innerHTML = '<table width="100%" height="100%" cellspacing="0" cellpadding="0" style="border:1px solid #FF0000;"><tr><td align="center" valign="middle"><img src="' + IMGDIR + '/loading.gif"></td></tr></table><div style="position:absolute;top:-100000px;visibility:hidden"><img src="'+zoomobj['zimg']+'" onload="javascript:ImageViewer.prototype.zoomimgresize(this);"></div>';
   
  }

this.fetchOffset = function(obj) {//取得图片在屏幕上的相对位置，居中显示
    var left_offset = obj.offsetLeft;
    var top_offset = obj.offsetTop;
    
    while((obj = obj.offsetParent) != null) {
      

      left_offset += obj.offsetLeft;
      top_offset += obj.offsetTop;

    }

    return { 'left' : left_offset, 'top' : top_offset };
  }
    var zoomdragstart = new Array();
    var zoomclick = 0;

  ImageViewer.prototype.zoomdrag = function(e, op) {//拖动
    if(op == 1) {
      zoomclick = 1;
      zoomdragstart = browser.isIE ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
      zoomdragstart[2] = parseInt(zoomimglayer.style.left);
      zoomdragstart[3] = parseInt(zoomimglayer.style.top);
      ImageViewer.prototype.doane(e);
    } else if(op == 2 && zoomdragstart[0]) {
      zoomclick = 0;
      var zoomdragnow = browser.isIE ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
      zoomimglayer.style.left = (zoomdragstart[2] + zoomdragnow[0] - zoomdragstart[0]) + 'px';
      zoomimglayer.style.top = (zoomdragstart[3] + zoomdragnow[1] - zoomdragstart[1]) + 'px';
      ImageViewer.prototype.doane(e);
    } else if(op == 3) {
      if(zoomclick){
        ImageViewer.prototype.zoomclose();
      }
      zoomdragstart = [];
        ImageViewer.prototype.doane(e);
    }
  }

  ImageViewer.prototype.doane = function(event) {//静态方法
    e = event ? event : window.event;
    if(browser.isIE) {
      e.returnValue = false;
      e.cancelBubble = true;
    } else if(e) {
      e.stopPropagation();
      e.preventDefault();
    }
  }
	
  ImageViewer.prototype.setImageDir = function(dir) {
	IMGDIR = dir;
  }

  ImageViewer.prototype.zoomST = function(c) {
    if(zoomimglayer.style.display == '') {
      zoomimglayer.style.left = (parseInt(zoomimglayer.style.left) + zoomobj['x']) + 'px';
      zoomimglayer.style.top = (parseInt(zoomimglayer.style.top) + zoomobj['y']) + 'px';
      zoomimglayer.style.width = (parseInt(zoomimglayer.style.width) + zoomobj['w']) + 'px';
      zoomimglayer.style.height = (parseInt(zoomimglayer.style.height) + zoomobj['h']) + 'px';
      var opacity = c * 20;
      zoomimglayer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ',finishOpacity=100,style=0)';
      zoomimglayer.style.opacity = opacity / 100;
      c++;
      if(c <= 5) {
        setTimeout('ImageViewer.prototype.zoomST(' + c + ')', 5);
      } else {

        zoomimglayer.style.filter = '';
        zoomimglayer_bg.style.display = '';
        zoomimglayer.innerHTML = '<table cellspacing="0" cellpadding="2"><tr><td style="text-align: right;color:white;" nowrap>'+I18n.imageViewerZoomTip+'<a href="' + zoomobj['zimg'] + '" target="_blank"><img src="' + IMGDIR + '/newwindow.gif" border="0" style="vertical-align: middle" title="'+I18n.imageViewerOpenTip+'" /></a> <a href="javascript:return false;" onclick="ImageViewer.prototype.zoomimgadjust(event, 1)"><img src="' + IMGDIR + '/resize.gif" border="0" style="vertical-align: middle" title="'+I18n.imageViewerNormalSizeTip+'" /></a> <a href="javascript:ImageViewer.prototype.zoomclose();"><img style="vertical-align: middle" src="' + IMGDIR +'/close.gif" title="'+I18n.imageViewerCloseTip+'" /></a>&nbsp;</td></tr><tr><td align="center" id="zoomimgbox"><img id="zoomimg"  style="cursor: move; margin: 5px;" src="' + zoomobj['zimg'] + '" width="' + zoomimglayer.style.width + '" height="' + zoomimglayer.style.height + '"></td></tr></table>';
        zoomimglayer.style.overflow = 'visible';
        zoomimglayer.style.width = zoomimglayer.style.height = 'auto';

        if(browser.isIE){
          zoomimglayer.onmousewheel = ImageViewer.prototype.zoomimgadjust;
          document.getElementById('zoomimgbox').onmousedown = ImageViewer.prototype.zoomdrag.bind(event,1);
          document.getElementById('zoomimgbox').onmousemove = ImageViewer.prototype.zoomdrag.bind(event,2);
          document.getElementById('zoomimgbox').onmouseup = ImageViewer.prototype.zoomdrag.bind(event,3);
        } else {
          zoomimglayer.addEventListener("DOMMouseScroll", ImageViewer.prototype.zoomimgadjust, false);
          //document.getElementById('zoomimgbox').addEventListener("mousedown", ImageViewer.prototype.zoomdrag.bind(event,1), false);
          //document.getElementById('zoomimgbox').addEventListener("mousemove", ImageViewer.prototype.zoomdrag.bind(event,2), false);
          //document.getElementById('zoomimgbox').addEventListener("mouseup", ImageViewer.prototype.zoomdrag.bind(event,3), false);
        }
 


      }
    }
  }

  ImageViewer.prototype.zoomimgresize = function(obj) {//生成大图片的缩略图
    zoomobj['zimginfo'] = [obj.width, obj.height];
    var r = obj.width / obj.height;
    var w = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
    w =  w*0.95;
    w = obj.width > w ? w : obj.width;//控制图片的宽度不超过浏览器窗口宽度的95%
    var h = w / r;
    var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;

    var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;//页面滚动高度

    if(h > clientHeight) {
      h = clientHeight;
      w = h * r;
    }

    var l = ((document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth) - w) / 2;//按照浏览器窗口宽度计算，而非按照body宽度计算
    var t = h < clientHeight ? (clientHeight - h) / 2 : 0;
    t += + scrollTop;
   
    zoomobj['x'] = (l - zoomobj['srcinfo']['left']) / 5;
    zoomobj['y'] = (t - zoomobj['srcinfo']['top']) / 5;
    zoomobj['w'] = (w - zoomobj['srcobj'].width) / 5;
    zoomobj['h'] = (h - zoomobj['srcobj'].height) / 5;

    zoomimglayer.style.filter = '';
    zoomimglayer.innerHTML = '';
    setTimeout('ImageViewer.prototype.zoomST(1)', 5);//图片放大效果
  }

  ImageViewer.prototype.zoomimgadjust = function(e, a) {
     var zoomimg = document.getElementById('zoomimg'); 
    if(!a) {
      if(!e) e = window.event;
      if(e.altKey || e.shiftKey || e.ctrlKey) return;
      var l = parseInt(zoomimglayer.style.left);
      var t = parseInt(zoomimglayer.style.top);
      var img = GetImageSize(zoomobj['srcobj']);//获得图片的原始大小
	  var scale = img.width/img.height;
      if(e.wheelDelta <= 0 || e.detail > 0) {

//alert(zoomimg.width);
        if(zoomimg.width <= 100 || zoomimg.height <= 100) {//当图片的宽度或者高度小于原大小时不缩放
          ImageViewer.prototype.doane(e);return;
        }
        zoomimg.width -= zoomobj['zimginfo'][0] / 10;
        zoomimg.height -= (zoomobj['zimginfo'][1] / 10)*scale;
		/*
        l += zoomobj['zimginfo'][0] / 20;
        t += zoomobj['zimginfo'][1] / 20;
		*/
      } else {
        /*if(zoomimg.width >= zoomobj['zimginfo'][0]) {//放大到原图片大小就不再放大
          this.zoomimgadjust(e, 1);return;
        }*/
        zoomimg.width += zoomobj['zimginfo'][0] / 10;
        zoomimg.height += (zoomobj['zimginfo'][1] / 10)*scale;
		/*
        l -= zoomobj['zimginfo'][0] / 20;
        t -= zoomobj['zimginfo'][1] / 20;
		*/
      }
	  
    } else {
		/*
      var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
      var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
      var clientWidth =  document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	  */
      zoomimg.width = zoomobj['zimginfo'][0];zoomimg.height = zoomobj['zimginfo'][1];
	  /*
      var l = (clientWidth - zoomimg.clientWidth) / 2;l = l > 0 ? l : 0;
      var t = (clientHeight - zoomimg.clientHeight) / 2 + scrollTop;t = t > 0 ? t : 0;
	  */
    }
	  var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	  var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
	  var clientWidth =  document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
	  var l = (clientWidth - zoomimg.clientWidth) / 2;l = l > 0 ? l : 0;
	  var t = (clientHeight - zoomimg.clientHeight) / 2 + scrollTop;t = t > 0 ? t : 0;

    zoomimglayer.style.left = l + 'px';
    zoomimglayer.style.top = t + 'px';
    zoomimglayer_bg.style.height = t + zoomimglayer.clientHeight > zoomimglayer_bg.clientHeight ? (t + zoomimglayer.clientHeight) + 'px' : zoomimglayer_bg.style.height;
    ImageViewer.prototype.doane(e);
  }

  ImageViewer.prototype.zoomclose = function() {
    zoomimglayer.innerHTML = '';
    zoomimglayer.style.display = 'none';
    zoomimglayer_bg.style.display = 'none';
  }
  this.zoom(obj);
}

//element用于滚动的容器ID；spd 滚动速度1-50；type滚动方式1：向上；2：向下；3：向左；4：向右；
function Marquee(elm,width,height,spd,type,wspace){
  if(arguments.length<1){//判断形参和实参数是否相等
    alert(I18n.marqueeIdEmpty);
    return false;
  }
  var element = elm;//滚动区域div
  var scrollwidth = width ? width : 800;//默认值
  var scrollheight = height ? height : 200;
  scrollwidth = parseInt(scrollwidth);
  scrollheight = parseInt(scrollheight);
  var scrollwspace = wspace ? wspace : 5;
  var scrolltype = type ? type :3;
  var speed = spd ? spd : 30;
  var scrolltext = new Array();  
  var obj1 = document.getElementById(element);//滚动区域，定义滚动区域宽高
  if(!obj1){
    alert(I18n.marqueeIllegalParameter);
    return false;
  }
  obj1.style.height = scrollheight+'px';
  obj1.style.width = scrollwidth+'px';
  obj1.style.border = '0px solid #000';
  var obj2 = document.createElement("div");
  obj2.id = 'obj2';
  var obj3 = document.createElement("div");//创建滚动容器
  obj3.id = "obj3";
  obj2.style.border = '0px solid #000';
  var objtab = document.createElement('table');
  var objtr = document.createElement('tr');
  var objtd = document.createElement('td');
  
  objtd.innerHTML = obj1.innerHTML;
  obj1.innerHTML = "";
  objtab.style.display = "inline";
  objtab.cellpadding = "0";
  objtab.cellspacing = "0";
  objtab.id = element +'tab';
  objtab.style.border = "0px solid #FF0000";

  objtd.style.whiteSpace = "nowrap";
  objtr.appendChild(objtd);
  objtab.appendChild(objtr);
  obj2.innerHTML = objtab.outerHTML;
  obj1.appendChild(obj2);
  obj1.appendChild(obj3);
  obj3.style.width = obj2.style.width =scrollwidth+'px';

  if(scrolltype == 1 || scrolltype == 2){
    if(obj2.offsetHeight < scrollheight){
	  var tabheight = scrollheight - obj2.offsetHeight;
     var  tabmarginleft =(obj2.offsetWidth>scrollwidth) ? scrollwidth : (obj2.offsetWidth+scrollwidth)/2;
	  if(tabheight<0){
		tabheight=0;
	  }else{
		obj2.innerHTML += "<table border=0 style='border:1px solid #ff0000;margin-left:"+tabmarginleft+"px;' cellpadding='0' cellspacing='0'><tr><td style='height:"+tabheight+"px;' nowrap></td></tr></table>";
	  }
      //obj3.style.height = obj2.style.height = scrollheight+'px';
    }
  }
  document.write("<style type=\"text/css\">#"+element+"{overflow:hidden;width:"+scrollwidth+"px;} #"+element+" #"+obj2.id+",#"+element+" #"+obj3.id+"{padding:0px !important;padding:0px;margin:0px !important;margin:0px;float:none;} #"+obj2.id+" img,#"+obj3.id+" img{margin-right:"+scrollwspace+"px;}</style>");

  if(scrolltype == 3 || scrolltype == 4){//计算出图片不换行的实际宽度
     obj1.style.whiteSpace = "nowrap";
     obj2.style.display = "inline";
    
     var tabwidth = scrollwidth - obj2.offsetWidth;
     var  tabmargintop =(obj2.offsetHeight>scrollheight) ? scrollheight : (obj2.offsetHeight+scrollheight)/2;

     if(tabwidth<0){
        tabwidth = 0;
        //obj2.innerHTML += "<table border=0 style='display:inline;margin-top:"+tabmargintop+"px;' cellpadding='0' cellspacing='0'><tr><td style='width:"+tabwidth+"px;' nowrap></td></tr></table>";
     }else{//当使用w3c标准时，使用table撑出空白区域
        obj2.innerHTML += "<table border=0 style='display:inline;margin-top:"+tabmargintop+"px;' cellpadding='0' cellspacing='0'><tr><td style='width:"+tabwidth+"px;' nowrap></td></tr></table>";
     }
  }
  
  obj3.innerHTML=obj2.innerHTML;//将图片复制到滚动区域

  Marquee.prototype.marqueeScrollTop = function(){//1循环向上滚动
    if(obj2.offsetHeight > scrollheight)
      if(obj3.offsetTop-obj1.scrollTop<=0){
        obj1.scrollTop -= obj3.offsetTop;
      }else{
        var oldScrollTop = obj1.scrollTop;
		obj1.scrollTop++;
		if(oldScrollTop == obj1.scrollTop){
			obj1.scrollTop = 0;
		}
      }
    else{
      if(scrollheight-obj1.scrollTop<=0){
        obj1.scrollTop -= scrollheight;
      }else{
        obj1.scrollTop++;
      }
    }
  }
  
  Marquee.prototype.marqueeScrollDown = function(){//2循环向下滚动
   if(document.all){
    if(obj2.offsetTop-obj1.scrollTop>=0){
      obj1.scrollTop+=obj3.offsetHeight;
    }else{
      obj1.scrollTop--;
    }
   }else{
    if(obj2.offsetTop-obj1.scrollTop-obj2.offsetTop>=0){
      obj1.scrollTop+=obj3.offsetHeight;
    }else{
      obj1.scrollTop--;
    }
   }
  }

  Marquee.prototype.marqueeScrollLeft = function(){//3循环向左滚动
    if(obj3.offsetWidth-obj1.scrollLeft<=0){
      obj1.scrollLeft-=obj2.offsetWidth;
    }else{
      obj1.scrollLeft++;
    }
  }

  Marquee.prototype.marqueeScrollRight = function(){//4循环向右滚动
     if(obj1.scrollLeft<=0){
      obj1.scrollLeft+=obj3.offsetWidth;
     }else{
      obj1.scrollLeft--;
     }
  }
  
  var count;
  Marquee.prototype.marqueeStart = function(){//开始滚动 并判断滚动方向
     switch(scrolltype){
       case 1://向上滚动
         if(Marquee.prototype.scrollTopOrDown()){
          count =  window.setInterval(Marquee.prototype.marqueeScrollTop,speed);
         }break;
       case 2://向下滚动
         if(Marquee.prototype.scrollTopOrDown()){
          count = window.setInterval(Marquee.prototype.marqueeScrollDown,speed);
         }break;
       case 3://向左滚动
          Marquee.prototype.scrollLeftOrRight();
          count = window.setInterval(Marquee.prototype.marqueeScrollLeft,speed);break;
       case 4://向右滚动
          Marquee.prototype.scrollLeftOrRight();
          count =  window.setInterval(Marquee.prototype.marqueeScrollRight,speed);break;
     }
  }

  Marquee.prototype.scrollLeftOrRight = function(){//横向滚动时的条件
     obj3.style.display = "inline";
  }

  Marquee.prototype.scrollTopOrDown = function(){//纵向滚动时，判断图片宽度是否超出滚动区域宽度
     //obj2.style.display = "inline";obj3.style.display = "inline";
     if(scrollwidth-obj2.offsetWidth<0){
        //alert(I18n.marqueeWidthNotEnough);
        return true;
     }else{
       obj2.style.display = "block";
       return true;
     }
  }
  
  obj1.onmouseover=function() {window.clearInterval(count);}
  obj1.onmouseout=function() {Marquee.prototype.marqueeStart();};
  Marquee.prototype.marqueeStart();
}

//firefox 支持outerHTML
if(typeof(HTMLElement)!="undefined" && !window.opera) 
{ 
    HTMLElement.prototype.__defineGetter__("outerHTML",function() 
    { 
        var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++) 
        if(a[i].specified) 
            str+=" "+a[i].name+'="'+a[i].value+'"'; 
        if(!this.canHaveChildren) 
            return str+" />"; 
        return str+">"+this.innerHTML+"</"+this.tagName+">"; 
    }); 
    HTMLElement.prototype.__defineSetter__("outerHTML",function(s) 
    { 
        var r = this.ownerDocument.createRange(); 
        r.setStartBefore(this); 
        var df = r.createContextualFragment(s); 
        this.parentNode.replaceChild(df, this); 
        return s; 
    }); 
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function() 
    { 
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase()); 
    }); 
} 
//

Function.prototype.bind = function(){
	var _method = this;
	var arg = arguments;
	return function(){
	  _method.apply(window,arg);
	}
}

function GetImageSize(oImage){//获得图片的原始大小
  var OriginImage=new Image();
  if(OriginImage.src!=oImage.src)OriginImage.src=oImage.src;
  return {"width":OriginImage.width, "height":OriginImage.height};
}

//var imageViewer = new ImageViewer();//dir图标的保存路径；name实例化的对象名

