var left_time=100;
var time_leave=false;

//对象克隆
function cloneObj(myObj){
  if(typeof(myObj) != 'object') return myObj;
  if(myObj == null) return myObj;
  
  var myNewObj = new Object();
  
  for(var i in myObj){
     myNewObj[i] = myObj[i];
  }
  return myNewObj;
}

function getCheckedElements(chkName) {
	var elements = document.getElementsByName(chkName);
	var result = "";
	for (var i = 0; i < elements.length; i++) {
		if (elements[i].checked) {
			result += elements[i].value + ",";
		}
	}
	if (result != "") {
		result = result.substring(0, result.length - 1);
	}
	return result;
}

function roundDoubleToStr(value, decLength) {
	if(decLength==0){
		return value;
	}
	if(value.toString().indexOf(',')>-1){
		value = value.toString().replace(',','');
	}
	if(decLength){
		return Number(value).toFixed(decLength);
	}
	return "";
}


function updateDiv(div,url,param,loadingImage,updateId){
	var imageUrl=getElementValue('web_root')+'/webtrader/images/uploading.gif';
	if(loadingImage){
		getElementById(div).innerHTML = "<table bgcolor='#ffffff' width='100%'><tr><td height='150' align='center'><img src='"+imageUrl+"' /><font color='#999999'>  "+getLocalText('ajax_update_view')+"</font></td></tr></table>";
	}
	jQuery.noConflict();  
  	new Ajax.Updater({success:div}, 
				  url, 
				 {method: 'post', 
				  asynchronous:true, 
				  evalScripts:true, 
				  onComplete: function(request) {
  					if(updateId){
  						enableObj(updateId);
  					}
  				  },
				  parameters:param
				  });
}

function moveUpDown(id, i) {
	var select1 = getIdObj(id);
	var si = select1.selectedIndex;
	var ops = select1.options;
	if (si + i >= 0 && ops[si + i] && ops[si]) {
		ops[si + i].swapNode(ops[si]);
	}
}
function keyDown() {
	ns4 = (document.layers) ? true : false;
	ie4 = (document.all) ? true : false;
	var key;
	if (ns4) {
		key = e.which;
	}
	if (ie4) {
		key = event.keyCode;
	}
	if (key == 13) {
		ajaxFormSubmit(formId);
	}
}

function changeImgSrc(id, url) {
	getElementById(id).src = url;
}
function enableObj(id) {
	if(getElementById(id))
	getElementById(id).disabled = false;
}
function disableObj(id) {
	if(getElementById(id))
	getElementById(id).disabled = true;
}
function display(id) {
	getElementById(id).style.display = "";
}
function hide(id) {
	if(getElementById(id))
	getElementById(id).style.display = "none";
}
function trim(str) {
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function getElementById(id) {
	return document.getElementById(id);
}

function getToLogin(){
	var strPath=window.document.location.pathname;
	var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
	var url=postPath+"/loginAction!loginInit.action";
	window.location.href=url;
}

function getElementValue(id,defaultValue) {
	if(getElementById(id)){
		if(getElementById(id).value==""){
			if(defaultValue){
				return defaultValue;
			}
		}
		return getElementById(id).value;
	}else{
		if(defaultValue){
			return defaultValue;
		}
	}
	return "";
}

function getElementInnerHtml(id) {
	if(getElementById(id)){
		return getElementById(id).innerHTML;
	}
	return "";
}


function elementIsEmpty(id) {
	return getElementValue(id)=='';
}

function setElementInnerHtml(id,innerHtml) {
	var element=getElementById(id);
	if(element){
		element.innerHTML=innerHtml;
	}
}
function setElementValue(id,value) {
	var element=getElementById(id);
	if(element){
		element.value=value;
	}
}
function setElementFocus(id) {
	getElementById(id).focus();
}

function changeClass(id, className) {
	if(getElementById(id))
	getElementById(id).className=className;
}

function switchOn(id) {
	var switchOn=getElementById(id);
	var ds = switchOn.disabled;
	if (ds) {
		switchOn.disabled = false;
		setElementFocus(id);
	} else {
		switchOn.disabled = true;
	}
}

function controlyDiv(thId) {
	var showObj = document.getElementById(thId);
	if (showObj.style.display == "none") {
		showObj.style.display = "block";
	} else {
		showObj.style.display = "none";
	}
}


function selectItemByValue(selectId,selectValue)
{    
     //判断是否存在
     var isExit = false;
     var objSelect=getElementById(selectId);
     for(var i=0;i<objSelect.options.length;i++)
     {
    	 if(objSelect.options[i].value == selectValue)
         {
             objSelect.options[i].selected = true;
             isExit=true;
             break;
         }
     }
     return isExit;
}

function getSelectText(selectId)
{    
	var   selectObj   = getElementById(selectId);  
	if(selectObj&&selectObj.disabled==false){
		return selectObj.options[selectObj.selectedIndex].text;
	}
	return "";
}

function isPositiveInteger(s) {//判断字符串是否是正整数
	var v = parseInt(s);
	if(v <=0 || v != s) {
		return false;
	} 
	return true;
}

