function SPGGetX(aTag){
	var oTmp = aTag;
	var X = 0;
	do {
		X += oTmp.offsetLeft;
		oTmp = oTmp.offsetParent;
		if(oTmp==null)return X;
	} while(oTmp.tagName!="BODY");
	return X;
}
function SPGGetY(aTag){
	var oTmp = aTag;
	var Y = 0;
	do {
		Y += oTmp.offsetTop;
		oTmp = oTmp.offsetParent;
		if(oTmp==null)return Y;
	} while(oTmp.tagName!="BODY");
	return Y;
}
function SPGIniPageSample(){
	//读取到屏幕
	var sw=window.screen.availWidth;
	var sh=window.screen.availHeight;
	//窗口最大化
	//window.moveTo(0,0);
	window.resizeTo(window.screen.availWidth,window.screen.availHeight);
	//读取客户区大小
	var cw=document.documentElement.clientWidth;
	var ch=document.documentElement.clientHeight;
	//设置页面中div,table的高度
	
	
}
//对于指定的需要进行like操作的字段进行like自动填写
function SPGAutoInputLike(objInput){
    if(objInput==null)return;
    return ;//暂时不用
    //有些事件不处理
    //    if(event.keyCode==32){realkey='\' 空格\''}
    //if(event.keyCode==13){realkey='\' 回车\''}
    //if(event.keyCode==27){realkey='\' Esc\''}
    //if(event.keyCode==16){realkey='\' Shift\''}
    //if(event.keyCode==17){realkey='\' Ctrl\''}
    //if(event.keyCode==18){realkey='\' Alt\''}

    if (event.keyCode==13||(event.keyCode>=37 && event.keyCode<=40)||event.keyCode==27||event.keyCode==16||event.keyCode==17||event.keyCode==18)return;
    if(objInput.tagName.toLowerCase()!="input")return;
    if(objInput.type.toLowerCase()!="text")return;
    var oldValue=objInput.value;
    if(oldValue==null)return;
    if(oldValue.length<1)return;
    if(oldValue.indexOf("=")==0 || oldValue.indexOf("<")==0 || oldValue.indexOf(">")==0 || oldValue.indexOf("!")==0  )return;
    if(oldValue.length<5){
        if("like ".indexOf(oldValue.toLowerCase())>=0)return;
        objInput.value="like "+oldValue;
        return;
    }
    var preValue;
    preValue=oldValue.substring(0,5);
    if(preValue.toLowerCase()!="like "){
        objInput.value="like "+oldValue;
    }    
}
function SPGOpenWindow(url)
{
    window.open(url,'_blank','height='+(window.screen.availHeight-100)+',width='+(window.screen.availWidth-200)+',top=50,left=100,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no');
}
//MsgBoxType=1表示有确认 取消两个按钮，否则只有一个按钮，取消返回0，确认返回1，关闭返回undefine
function CustomMessageBox(MsgBoxType,MsgBoxTitle,Message,IconFile)
{
    var ret=window.showModalDialog("/SPGFrame/SPGApp/ShowMessage.aspx?MsgBoxType="+MsgBoxType+"&MsgBoxTitle="+escape(MsgBoxTitle)+"&Message="+escape(Message)+"&IconPath="+escape(IconFile),ret,"status:no;dialogWidth:350px;DialogHeight=200px;");
    return ret;
}
function SPGCustomMessageBox(MsgURL,MsgBoxType,MsgBoxTitle,Message,IconFile)
{
    var ret=window.showModalDialog(MsgURL+"?MsgBoxType="+MsgBoxType+"&MsgBoxTitle="+escape(MsgBoxTitle)+"&Message="+escape(Message)+"&IconPath="+escape(IconFile),ret,"status:no;dialogWidth:350px;DialogHeight=200px;");
    return ret;
}


function SPGDDLReset(ctrlClientID,arrText,arrValue,selectedValue)
{
    var objDDL=document.getElementById(ctrlClientID);
    if(objDDL==null)return;
    if(objDDL.tagName.toLowerCase()!="select")return;
    SPGDDLRemoveAll(ctrlClientID);
    //开始进行数据添加操作
    var tmpOption;
	//window.alert(selectedValue);	
    
	var i;
	for(i=0;i<arrValue.length;i++)
	{
	    
		tmpOption=new Option(arrText[i],arrValue[i]);
		
		objDDL.options[i]=tmpOption;
		if(arrValue[i]+""==selectedValue+"")
		{
		    objDDL.options[i].selected=true;
		}
	}
}

function SPGDDLRemoveAll(ctrlClientID)
{
    var objDDL=document.getElementById(ctrlClientID);
    if(objDDL==null)return;
    if(objDDL.tagName.toLowerCase()!="select")return;
    var totalOptionCount;
	totalOptionCount=objDDL.options.length;
	for (var j=totalOptionCount-1;j>=0;j--)
	{
		objDDL.options[j]=null;
	}
}

function SPGAjaxResetDDL(createArrayURL,ctrlClientID,retrieveKey,parentValue,selectedValue)
{
    //window.alert('ddd');   
    //create object
    var xmlHttpRequest=null;
	if(window.ActiveXObject){
	    	try {
	                 xmlHttpRequest = new ActiveXObject("Msxml3.XMLHTTP");
	        } catch (e) {
		    	try {
		                 xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		        } catch (e) {
			   	try {
			                xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			       	} catch (e) {
					//do nothing
				}
			}
		}
  	}else if(window.XMLHttpRequest){
          	xmlHttpRequest=new XMLHttpRequest();
          	if (xmlHttpRequest.overrideMimeType) xmlHttpRequest.overrideMimeType('text/xml');
 	}
 	if(xmlHttpRequest==null)return;
 	
 	
 	//construct url
 	var url="/SPGFrame/SPGApp/SPGCreateListArray.aspx";
 	if (createArrayURL.length>0){
		url=createArrayURL;
	}
	
 	var formData="parentValue="+encodeURIComponent(parentValue)+"&retrieveKey="+encodeURIComponent(retrieveKey);
 	xmlHttpRequest.open("POST", url, false);
 	
	if (formData.length>0){
		xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
		xmlHttpRequest.setRequestHeader("Content-Length",formData.length);
	}
	//window.alert("Send!!");
	xmlHttpRequest.send(formData);
	
	var sResponseText="";
	
	if (xmlHttpRequest.readyState == 4) {
    	    // only if "OK"
	    //window.alert(objRequest.responseText);
	    //document.forms[0].TextArea1.value=objRequest.responseText;
	    if (xmlHttpRequest.status == 200) {
		    //window.alert( objRequest.responseBody.getElementById(sDisplayerID).innerHTML);
		    sResponseText=xmlHttpRequest.responseText;
	    } else {  
		    window.alert("There was a problem retrieving the XML data:" +xmlHttpRequest.statusText);
		    //document.write(objRequest.responseText);
		    return;
	    }
	}else{
	    return;
	}
	
	//返回数据
	//window.alert(sResponseText);
	var func="SPGDDLReset(\""+ctrlClientID+"\",arrText,arrValue,\""+selectedValue+"\");";
	func=sResponseText+func;
	//window.alert(func);
	window.execScript(func);

}
function SPGAjaxResetDDLNew(createArrayURL,ctrlClientID,selectedValue)
{
    //window.alert('ddd');   
    //create object
    var xmlHttpRequest=null;
	if(window.ActiveXObject){
	    	try {
	                 xmlHttpRequest = new ActiveXObject("Msxml3.XMLHTTP");
	        } catch (e) {
		    	try {
		                 xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		        } catch (e) {
			   	try {
			                xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			       	} catch (e) {
					//do nothing
				}
			}
		}
  	}else if(window.XMLHttpRequest){
          	xmlHttpRequest=new XMLHttpRequest();
          	if (xmlHttpRequest.overrideMimeType) xmlHttpRequest.overrideMimeType('text/xml');
 	}
 	if(xmlHttpRequest==null)return;
 	
 	
 	//construct url
 	
 	xmlHttpRequest.open("GET", createArrayURL, false);
 	
	
	//window.alert("Send!!");
	xmlHttpRequest.send();
	
	var sResponseText="";
	
	if (xmlHttpRequest.readyState == 4) {
    	    // only if "OK"
	    //window.alert(xmlHttpRequest.responseText);
	    //document.forms[0].TextArea1.value=objRequest.responseText;
	    if (xmlHttpRequest.status == 200) {
		    //window.alert( objRequest.responseBody.getElementById(sDisplayerID).innerHTML);
		    sResponseText=xmlHttpRequest.responseText;
	    } else {  
		    window.alert("There was a problem retrieving the XML data:" +xmlHttpRequest.statusText);
		    //document.write(objRequest.responseText);
		    return;
	    }
	}else{
	    return;
	}
	
	//返回数据
	//window.alert(sResponseText);
	var func="SPGDDLReset(\""+ctrlClientID+"\",arrText,arrValue,\""+selectedValue+"\");";
	func=sResponseText+func;
	//window.alert(func);
	window.execScript(func);

}
function SPGEnterToTab()
{
    
    //if(window.event.keyCode==13){window.event.keyCode=9;return true;}
    if(window.event==null)return true;
    if(window.event.keyCode!=13){return true;}
    
    var objElement=window.event.srcElement;
    if(objElement==null)return;
    var method = objElement.tagName.toLowerCase();
	//window.alert(method+":");
	switch (method) 
	{
	    case 'input':
		{
		    //window.alert(objElement.type.toLowerCase());
			switch (objElement.type.toLowerCase()) 
			{
	      		case 'hidden':
	      		case 'password':
	      		case 'text':
	      		case 'checkbox':  
	      		case 'radio':
				{
					if(window.event.keyCode==13){window.event.keyCode=9;return true;}
				}
				case "submit":
				case "image":
				{
					//do nothing
					//return false;
					window.event.keyCode=13;return true;
				}
			}
		}
		case 'textarea':	
	    case 'select':
		{
			if(window.event.keyCode==13){window.event.keyCode=9;return true;}
		}
	}
	
}
function SPGFirstFocus(ctrlID)
{
    var objInput=document.getElementById(ctrlID);
    try{
	    if(objInput!=null)
	    {
	        objInput.focus();
	        objInput.select();
        }
    }
    catch(err)
    {
        //do nothing
    }
}

