  jQuery.support.cors = true;
 
	//创建xml DOM对象
  function createxmlDoc() {
		var xmlDoc;
		var aVersions = [ "MSXML2.DOMDocument","MSXML2.DOMDocument.5.0",
		"MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0",
		"Microsoft.XmlDom"];
		for (var i = 0; i < aVersions.length; i++) {
			try  {
				xmlDoc = new ActiveXObject(aVersions[i]);
				break;
			} catch (e) {
				xmlDoc = document.implementation.createDocument("", "", null);
				break;
			}
		}
		xmlDoc.async="false";
		return xmlDoc;
  }
	//从xml字符串中解析xml
  function parseXmlFromStr(szXml) {
		if(null == szXml || '' == szXml) {
			return null;
		}
		var xmlDoc=new createxmlDoc();
		if(navigator.appName == "Netscape" || navigator.appName == "Opera") {
			var oParser = new DOMParser();
			xmlDoc = oParser.parseFromString(szXml,"text/xml");
		} else {
			xmlDoc.loadXML(szXml);
		}
		return xmlDoc;
  }
            // ptz
	//SetZoomInStart
	function SetZoomInStart() {
		StopPTZAuto();
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" +
			"<zoom>" + (m_iPtzSpeed) + "</zoom>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL = m_lHttp + m_szHostName + ":" + m_lHttpPort + "/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}
		});
	}
	
	//停止云台自转
	function StopPTZAuto() {
		ptzAuto();	//如果云台自转，就停止
	}
	
	//SetZoomOutStart
	function SetZoomOutStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" +
			"<zoom>" + (-m_iPtzSpeed) + "</zoom>" +
			"</PTZData>";
		var xmlDoc=parseXmlFromStr(szSetXml);
		//if(m_iChannel <= m_iAnalogChannelNum) {
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		//} else {
		//	var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/ContentMgmt/PTZCtrlProxy/channels/" + m_iChannel + "/continuous";
		//}	
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//停止PTZ操作
	function SetPTZStop(iType) {
		StopPTZAuto();
		if(m_iChannel < 0) {
			return;
		}
		var szSetXml;
		if(iType == 0) {
			szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + 0 + "</pan>" +
			"<tilt>" + 0 + "</tilt>" +
			"</PTZData>";
		} else {
			szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" +
			"<zoom>" + 0 + "</zoom>" +
			"</PTZData>";
		}
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				////that.setState(xhr);
			}		
		});
	}
	
	//开始向左转
	function SetPTZLeftStart() {
		StopPTZAuto();
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + (-m_iPtzSpeed) + "</pan>" +
			"<tilt>" + 0 + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//开始向左上转
	function SetPTZLeftUpStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + (-m_iPtzSpeed) + "</pan>" +
			"<tilt>" + (m_iPtzSpeed) + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//开始向左下转
	function SetPTZLeftDownStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + (-m_iPtzSpeed) + "</pan>" +
			"<tilt>" + (-m_iPtzSpeed) + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//开始向右转
	function SetPTZRightStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + (m_iPtzSpeed) + "</pan>" +
			"<tilt>" + 0 + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//开始向右上转
	function SetPTZRightUpStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + (m_iPtzSpeed) + "</pan>" +
			"<tilt>" + (m_iPtzSpeed) + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//开始向右下转
	function SetPTZRightDownStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + (m_iPtzSpeed) + "</pan>" +
			"<tilt>" + (-m_iPtzSpeed) + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}	
		});
	}
	
	
	//SetPTZUpStart
	function SetPTZUpStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + 0 + "</pan>" +
			"<tilt>" + (m_iPtzSpeed) + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}
		});
	}
	
	//SetPTZDownStart
	function SetPTZDownStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><PTZData version='1.0' xmlns='urn:psialliance-org'>" + 
			"<pan>" + 0 + "</pan>" +
			"<tilt>" + (-m_iPtzSpeed) + "</tilt>" +
			"</PTZData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/continuous";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//云台自动
	function ptzAuto() {
		var szSetXml = '';
		if(!m_bPTZAuto0) {
			szSetXml = "<?xml version='1.0' encoding='UTF-8'?><autoPanData version='1.0'><autoPan>" + (m_iPtzSpeed) + "</autoPan></autoPanData>";
		} else {
			szSetXml = "<?xml version='1.0' encoding='UTF-8'?><autoPanData version='1.0'><autoPan>0</autoPan></autoPanData>";
		}
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/PTZCtrl/channels/" + m_iChannel + "/autoPan";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			success: function(xmlDoc, textStatus, xhr) {
				m_bPTZAuto0=!m_bPTZAuto0;
				if(m_bPTZAuto0) {
					$("#ptzAutoId").attr("src","../images/ptz/auto.png");
				} else {
					$("#ptzAutoId").attr("src","../images/ptz/ptz_normal/auto.png");
				}				
			},
			error:function (xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}
		});
	}
	/*************************************************
	Function:		SetFocusInStart
	Description:	
	Input:			无
	Output:			无
	return:			无
	*************************************************/
	function SetFocusInStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><FocusData version='1.0' xmlns='urn:psialliance-org'>" +
			"<focus>" + (m_iPtzSpeed) + "</focus>" +
			"</FocusData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/Image/channels/" + m_iChannel + "/focus";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//SetFocusStop
	function SetFocusStop() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><FocusData version='1.0' xmlns='urn:psialliance-org'>" +
			"<focus>" + 0 + "</focus>" +
			"</FocusData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/Image/channels/" + m_iChannel + "/focus";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//SetFocusOutStart
	function SetFocusOutStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><FocusData version='1.0' xmlns='urn:psialliance-org'>" +
			"<focus>" + (-m_iPtzSpeed) + "</focus>" +
			"</FocusData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/Image/channels/" + m_iChannel + "/focus";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//IrisInStart
	function IrisInStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><IrisData version='1.0' xmlns='urn:psialliance-org'>" +
			"<iris>" + (m_iPtzSpeed) + "</iris>" +
			"</IrisData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/Image/channels/"+m_iChannel+"/iris";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//IrisOutStart
	function IrisOutStart() {
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><IrisData version='1.0' xmlns='urn:psialliance-org'>" +
			"<iris>" + (-m_iPtzSpeed) + "</iris>" +
			"</IrisData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/Image/channels/"+m_iChannel+"/iris";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}
	
	//IrisStop
	function IrisStop() {	
		var szSetXml = "<?xml version='1.0' encoding='UTF-8'?><IrisData version='1.0' xmlns='urn:psialliance-org'>" +
			"<iris>" + 0 + "</iris>" +
			"</IrisData>";
		var xmlDoc = parseXmlFromStr(szSetXml);
			var szURL=m_lHttp+m_szHostName+":"+m_lHttpPort+"/ISAPI/Image/channels/"+m_iChannel+"/iris";
		$.ajax({
			type: "put",
			url: szURL,
			async: false,
			timeout: 15000,
			processData: false,
			data: xmlDoc,		
			beforeSend: function(xhr) {
				xhr.setRequestHeader("If-Modified-Since", "0");
				xhr.setRequestHeader("Authorization", "Basic " + m_szUserPwdValue);
			},
			error:function(xhr, textStatus, errorThrown) {
				//that.setState(xhr);
			}		
		});
	}