/* --------------------------------------------	*/
/* HTTPRequests START							*/
/* --------------------------------------------	*/
function MSXMLObj(pType) {	
	switch (pType) {
	case "HTTP":
		try {return new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {
			try {return new ActiveXObject("Microsoft.XMLHTTP") } catch (e) {}
		}
		break;
	case "DOM":
		try {return new ActiveXObject("Msxml2.DomDocument") } catch (e) {
			try {return new ActiveXObject("Msxml.DomDocument") } catch (e) {}
		}
		break;
	default: break;
	}
}
			
function xmlHttpCall(pURL, pReceiveFunction, pErrorFunction) {
	try {
		if (is_ie) var xmlhttp = MSXMLObj('HTTP')
		else var xmlhttp = new XMLHttpRequest()
	
		window.status='Data Requested'

		zURL = pURL				
		date = new Date();
		if (pURL.indexOf("?") != -1) zURL += "&"
		else zURL += "?"
		zURL += 'Date=' + date.getTime(); 

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				window.status = "Data received"
				if (is_ie) {
					var dom = MSXMLObj('DOM')
					dom.loadXML(xmlhttp.responseText)
				} else {
					var objDOMParser = new DOMParser();
					var dom = objDOMParser.parseFromString(xmlhttp.responseText, "text/xml")
				}						
				pReceiveFunction(dom, pURL)
			}
		}
		xmlhttp.open("GET",zURL,true)	// Asynchronous request
		xmlhttp.send(null)
	} catch (e) {
		pErrorFunction(e,pURL)
	}
}
var xmlhttpAsync
function xmlHttpCallAsync(pURL, pReceiveFunction, pErrorFunction) {
	try {
		if (is_ie) xmlhttpAsync = MSXMLObj('HTTP')
		else xmlhttpAsync = new XMLHttpRequest()
		xmlhttpAsync.onreadystatechange = function() {
			if (xmlhttpAsync.readyState == 4) {
				xmlhttpAsync.onreadystatechange = function() {}
				pReceiveFunction(xmlhttpAsync.responseText)
			}
		}
		xmlhttpAsync.open("GET",pURL,true)	// Asynchronous request
		xmlhttpAsync.send(null)
	} catch (e) {
		pErrorFunction(e)
	}
}
function xmlHttpCallAsyncII(pURL, pReceiveFunction, pErrorFunction) {
	try {
		if (is_ie) var xmlhttpAsyncII = MSXMLObj('HTTP')
		else var xmlhttpAsyncII = new XMLHttpRequest()
		xmlhttpAsyncII.onreadystatechange = function() {
			if (xmlhttpAsyncII.readyState == 4) pReceiveFunction(xmlhttpAsyncII.responseText)
		}
		xmlhttpAsyncII.open("GET",pURL,true)	// Asynchronous request
		xmlhttpAsyncII.send(null)
	} catch (e) {
		pErrorFunction(e)
	}
}

function xmlHttpCallSync(pURL) {
	try {
		if (is_ie) var xmlhttp = MSXMLObj('HTTP')
		else var xmlhttp = new XMLHttpRequest()
	
		xmlhttp.open("GET",pURL,false)	// Synchronous request
		xmlhttp.send(null)
		return xmlhttp.responseText
	} catch (e) {
		return "ERR"+e.description
	}
}


function xmlGetNodes (pDom, pNode) {
	var zDom
	try {
		if (is_ie) zDom = pDom.selectNodes(pNode);
		else {
			zDom = pDom
			var Arr = pNode.split('/')
			for (var i=1; i<Arr.length;i++) {
				if (i==Arr.length-1) zDom = zDom.getElementsByTagName(Arr[i]);
				else zDom = zDom.getElementsByTagName(Arr[i])[0];
			}
		}
	} catch (e) {}
	return zDom
}
function xmlGetText(pObj) {
	var z = ''
	try {z = pObj.firstChild.data} catch (e) {}
	return z
}
function xmlGetSingleNodeText(pDom, pNode) {
	var z = ''
	try {
		if (is_ie) var z = pDom.selectSingleNode(pNode).text
		else {
			var z = xmlGetNodes(pDom, pNode)
			z = z[0].firstChild.data
		}
	} catch (e) {}		
	return z
}
/* --------------------------------------------	*/
/* HTTPRequests End								*/
/* --------------------------------------------	*/

/* --------------------------------------------	*/
/* E-Mail Functions START						*/
/* --------------------------------------------	*/
function loadEmail() {
	document.getElementById("email").focus()
	document.getElementById("email").value=email.address
	document.getElementById("emailBottom").value=document.getElementById("email").value
}
function isEmail (sEmail) {
	if (sEmail=='') return false
	var regEmail = /^([\w-]+\.?)*\w+@([\da-zA-z-]+\.)+[a-zA-z]{2,3}$/
	if (sEmail==null || sEmail == "") { 
		if (isEmail.arguments.length == 1) return true;
		else {return (isEmail.arguments[1] == true);}
	} else {
		return regEmail.test(sEmail)
	}
}
function emailSync(pType, pValue) {
	if (pType=='') document.getElementById("emailBottom").value=pValue
	else document.getElementById("email").value=pValue
}
function emailEnter(e,pType) {
	var zKeyCode = (e.which) ? e.which : e.keyCode
  	if (zKeyCode == 13) {
  		try {sendMail(pType)} catch (e) {}
  	}
}
function sendMail(pType) {
	// emailLoad('Loading')
	var zURL = email.URL
	var date = new Date()
	zURL += '&TimeStamp='+date.getTime()
	
	zEmailAddress = document.getElementById("email"+pType).value
	if (!isEmail(zEmailAddress)) {
		document.getElementById("email"+pType).focus()
		document.getElementById("email"+pType).select()
		alert(email.errorAddress)
		return
	}
			
	var zSubject = email.subject
	
	var zMail =	'Address='+zEmailAddress +
				'amp;Subject='+encodeUtf8(zSubject)
			
	zURL += '&SendByMail='+zMail
	SayLoading()
	
	xmlHttpCallAsync(zURL, EmailDone, EmailError)

}
function emailLoad(pType) {
	try {
		if (pType=='Loading') {
			document.getElementById("emailLoaded").style.display='none'
			document.getElementById("emailLoading").style.display=''
			try {
				document.getElementById("emailLoadedBottom").style.display='none'
				document.getElementById("emailLoadingBottom").style.display=''
			} catch (e) {}
		} else {
			document.getElementById("emailLoading").style.display='none'
			document.getElementById("emailLoaded").style.display=''
			try {
				document.getElementById("emailLoadingBottom").style.display='none'
				document.getElementById("emailLoadedBottom").style.display=''
			} catch (e) {}
		}
	} catch (e) {}
}
function EmailDone(pText) {
	
	var z = pText
	if (z.substr(0,3)=='ERR') {
		var e = new Object()
		e.description = z.substr(3)
		EmailError(e)
		return
	}
	document.getElementById('Loading').style.display='none'
	document.getElementById('emailsent').style.display=''
}
function EmailError(pError) {
	document.getElementById('Loading').style.display='none'
	document.getElementById('Loaded').style.display=''
	alert(pError.description)
}
function SayLoading() {
	ResizeContentsII()
	document.getElementById('Loading').style.display=''
	document.getElementById('Loaded').style.display='none'
}
function ResizeContentsII() {
	try {
		var o = window.parent
		o.document.getElementById("oIframe").style.height = 1
		o.parent.document.body.scroll="no"
		o.document.getElementById("oIframe").style.height = o.document.body.scrollHeight
	} catch(e){}
}
/* --------------------------------------------	*/
/* E-Mail Functions END							*/
/* --------------------------------------------	*/
