//Standard site functions
function fnChangeImage(Obj, Img){
	Obj.src = Img;
}

function fnSubmitForm(Obj1, IPValue){
		Obj1.mode.value = IPValue;
		Obj1.submit();
}


function fnProfileSubmitForm(IPValue){
		document.frmProfile.mode.value = IPValue;
		document.frmProfile.submit();
}

function fnCheckKeyPress(Obj, Obj1, IPValue){
	if (Obj == 13){
		Obj1.mode.value = IPValue;
		Obj1.submit();
	}
}

function fnStatusChange(Obj){
	window.status = Obj
}


function fnSendEmail(id){
	window.open('/inc/emailer.asp?cid='+id,'Emailer','width=310,height=200,toolbars=1,scrollbars=0,resizable=0')
}

function fnLoadIE(){
	window.open('http://www.e-treasury.co.za/ie-app.asp','headlines','width=190,height=220,toolbars=1,scrollbars=1,resizable=1')
}

function fbreakout(obj){
	if (window.top!=window.self) 
	{
		window.top.location=obj
	}
}


//Change class
function fnChangeClass(obj, cname){
	obj.className = cname
}

function fnChangeImage(obj, cname){
	obj.src = cname
}

function fnStripHTML(InString){
var intag=false;
var inlitag=false;
var cleanedbuffer="";
InString=StdreplaceString(0,InString,"&nbsp;"," ",true);
	for(var i = 0; i < InString.length; i++){
		var tmpval=InString.charAt(i);
		if(tmpval=='<')intag=true;
		if(tmpval=='p'&&intag==true){
			cleanedbuffer+=	' '
		}
		
		//--------------------------------------------------
		var tmpval2 = ((i+1)<InString.length)?InString.charAt(i+1):"";
		if((intag && tmpval.toLowerCase()=='t' && tmpval2.toLowerCase()=='d') ||
		   (intag && tmpval.toLowerCase()=='t' && tmpval2.toLowerCase()=='h'))
		{
			cleanedbuffer+=' ';
		}
		
		if(tmpval=='l'&&intag==true){
			inlitag=true;
		}
		if(tmpval=='i'&&inlitag==true&&intag==true){
			cleanedbuffer+=	' '
			inlitag=false;
			continue;
		}
		if(tmpval=='>'&&intag==true){
			intag=false;
			continue;
		}
		if(intag)continue;
		cleanedbuffer+=	tmpval;
	}
return cleanedbuffer;
}

function StdreplaceString(StartPos,SearchString,FindText,ReplaceWithText,doall){
	//be sure to reset LastStartPosition between functions.
	var TempMatched=0;
	var fSubstring, sSubstring;
	var changeall=false
	if(doall==true)
		changeall=true;

	while(TempMatched>-1){
		TempMatched=SearchString.indexOf(FindText,StartPos);
		if(TempMatched==-1)return SearchString;
		StartPos=TempMatched+ReplaceWithText.length;
		fSubstring=SearchString.substring(0,TempMatched);
		sSubstring=SearchString.substring(TempMatched+FindText.length,SearchString.length);
		SearchString=fSubstring + ReplaceWithText + sSubstring;
		if(!changeall)
			break;
	}
	
	return SearchString; //Return changed text
}

function ValidateLogin(obj){
	if (obj.txtUserUID.value == ""){
		alert("Please enter a username");
		obj.txtUserUID.focus();
		return false;
	}
	
	if (obj.txtUserPWD.value == ""){
		alert("Please enter a password");
		obj.txtUserPWD.focus();
		return false;
	}
	
	return true;
}

function fnTimeInterval(){
	setInterval("makeRequest('process.asp?action=reuters')",60000)
}

function makeRequest(url) {
	var httpRequest;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
	httpRequest.open('GET', url, true);
	httpRequest.send(null);

}

function alertContents(httpRequest) {
	try {
		if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				var rspText = httpRequest.responseText;
				var oResponseArray = rspText.split("##");
				if (oResponseArray.length != 0){
					if (oResponseArray[0] == 'reuters'){
						document.getElementById('headlines').innerHTML = oResponseArray[1]
					}
				}
			} 
		}
	}
	
	catch( e ) {
	//	alert('Caught Exception: ' + e.description);
	}
}
