var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+false+',resizable'
	win = window.open(mypage,myname,settings)
}

function neewsWin(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars,resizable'
	win = window.open(mypage,myname,settings)
}

function openNewspaperLink(){
	var newspaper_list =  document.getElementById('newspaper_list');
	
	if(newspaper_list.value == 0 ){
		newspaper_list.focus();
		return;
	}
	
	neewsWin(newspaper_list.value,'NewsPAperLink',1024,768);
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}




function shoutRequest(){
	http=createRequestObject();
	
	
	var txtshout = document.getElementById('txtshout');
	stripHTML(txtshout);
	if(txtshout.value.trim() == 'TYPE YOUR SHOUT HERE!' || txtshout.value.trim() == ''){
		alert("Please type your shout");
		return;
	}
	
	
	
	document.getElementById('ajxLoader_Shout').style.display="";
	
	http.open('POST',  'index.php?section=shoutbox&action=shout');
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.onreadystatechange = __handleShout;
	http.send('txtshout='+txtshout.value);
}

 	
function __handleShout(){ 
  if((http.readyState == 4)&&(http.status == 200)){
	  document.getElementById('ajxLoader_Shout').style.display="none";
		var response = http.responseText;
		var splitResponse = response.split("|");
		var obj = document.getElementById('shouts');
		if(splitResponse[0] == 1){
			//alert("You have just shouted and your shout has been posted");
			obj.style.top = "0px";
			document.getElementById('txtshout').value = '';
			obj.innerHTML = splitResponse[1];
		}else if(splitResponse[0] == 2 || splitResponse[0] == 0 ){
			alert(splitResponse[1]);
		}else if(splitResponse[0] == 3){
			document.getElementById('txtshout').value = '';
			alert(splitResponse[1]);
		}
	}
}

function clearShoutBox(obj){
	if(obj.value = 'TYPE YOUR SHOUT HERE!'){
		obj.value = '';
	}
}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function stripHTML(){
	var re= /<\S[^><]*>/g
	for (i=0; i<arguments.length; i++)
		arguments[i].value=arguments[i].value.replace(re, "")
}


function getElementByClass(theClass) {
	var is_class = false;
	//Create Array of All HTML Tags
	var allHTMLTags=document.getElementsByTagName("*");
	//Loop through all tags using a for loop
	for (i=0; i<allHTMLTags.length; i++) {
		if (allHTMLTags[i].className==theClass) {
			is_class = true;
			break;
			//allHTMLTags[i].style.display="none";
		}
	}
	return is_class;
}
