var OnPostData, OnGetData;
var loading_msg="<div style='padding:20px 0; text-align:center;'>Loading...Please Wait...</div>";

function CloseControls()
{
	if(b = document.getElementById('DV_PRESENTER'))
		document.body.removeChild(b);
	if(a = document.getElementById('DV_PRESENTER_WINDOW'))
		document.body.removeChild(a);	
}

function AlignCenter()
{
	
	if(document.getElementById('DV_PRESENTER_WINDOW'))
		var bck = document.getElementById('DV_PRESENTER_WINDOW');
	else
	{
		var bck = document.createElement("DIV");
		document.body.appendChild(bck);
		bck.id = 'DV_PRESENTER_WINDOW';
	}
	axe = getPageSize();
	wdt = axe[0];
	hgt = axe[1];
	
	if(detectBrowser())//check lt ie7
	{
		position = 'absolute';
		left = '0';
		atop = 0 + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop );
	}
	else
	{
		position = "fixed";
		left = '0';
		atop = '0';
	}	
	bck.style.cssText = "position:"+position+"; left:"+left+"; top:"+atop+" ; z-index:1999; background:#000; height:"+hgt+"px; width:100%; opacity:0.3; filter:alpha(opacity=30);";
	bck.style.position = position;
	bck.style.left = left;
	bck.style.top = atop + 'px';
	bck.style.zIndex = '1999';
	bck.style.background = '#000';
	bck.style.height = hgt +'px';
	bck.style.width = '100%';
	bck.style.opacity = '0.3';
	bck.style.filter = 'alpha(opacity=30)';
	
	
	atop = (hgt > 500) ? parseInt((hgt - 500)/2) : 0;
	if(detectBrowser())//check lt ie7
	{
		position = 'absolute';
		left = (wdt > 500) ? parseInt((wdt - 500)/2) : 0;
		atop = atop + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop );
	}
	else
	{
		position = "fixed";
		left = (wdt > 500) ? parseInt((wdt - 500)/2) : 0;
		atop = atop;
	}	
	if(document.getElementById('DV_PRESENTER'))
	{
		var fgd = document.getElementById('DV_PRESENTER');		
	}
	else
	{
		var fgd = document.createElement("DIV");
		document.body.appendChild(fgd);
		fgd.id = 'DV_PRESENTER';
	}	
	fgd.style.cssText = "position:"+position+"; left:"+left+"px; top:"+atop+"px; z-index:2000; width:500px; height:300px;";
	fgd.style.position = position;
	fgd.style.left = left+'px';
	fgd.style.top = atop+'px';
	fgd.style.zIndex = '2000';	
	fgd.style.width = '500px';
	fgd.style.height = '300px';
		
}

function ShowCenterContent()
{	
	AlignCenter();
	if(a = document.getElementById('DV_PRESENTER_WINDOW'))
	{
		window.onresize = function(){
			if(document.getElementById('DV_PRESENTER_WINDOW'))
				AlignCenter();
			};
		window.onscroll = function(){
			if(document.getElementById('DV_PRESENTER_WINDOW'))
				AlignCenter();
			};
		//if(document.getElementById('DV_PRESENTER_WINDOW'))
			//document.getElementById('DV_PRESENTER_WINDOW').onclick = CloseControls;
		presenter = document.getElementById('DV_PRESENTER');
		if(presenter)
		{
			presenter.innerHTML = '<DIV id="TOTAL_DV_CONTENT"><DIV id="DV_HEAD"></DIV><DIV id="DV_CONTENT"></DIV><DIV>';
			header = document.getElementById("DV_HEAD");
			content = document.getElementById("DV_CONTENT");
		}
	}	
}

function getPageSize()
{
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;	
	arrayPageSize = [w,h];	
	return arrayPageSize;
}

function detectBrowser() 
{
	var userAgent = navigator.userAgent.toLowerCase();	
	if (userAgent.indexOf('msie')!=-1)
	{
		axe = userAgent.substr(eval(userAgent.indexOf('msie') + 5), 1);		
		if(axe < 7)		
	    	return true;		
	}
	return false;
}

function ProcessRequest() 
{
  if (prequest.readyState == 4) {
	 if (prequest.status == 200) {		 
		 presult = prequest.responseText;
		 if(presult != "")
		 	OnPostData(presult);
	 }		 
  }
}
function PostData(url, parameters) 
{
	prequest = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		prequest = new XMLHttpRequest();
		if (prequest.overrideMimeType) {		
		prequest.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
	 try {
		prequest = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   prequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	
	if (!prequest) {		
	 	window.location.reload();
	}
	prequest.onreadystatechange = ProcessRequest;
	prequest.open('POST', url, true);
	prequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	prequest.setRequestHeader("Content-length", parameters.length);
	prequest.setRequestHeader("Connection", "close");
	prequest.send(parameters);
}

function GetData(url)
{	
	var grequest = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		grequest = new XMLHttpRequest();
		if (grequest.overrideMimeType) {		
		grequest.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
	 try {
		grequest = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   grequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	
	if (!grequest) {	
	 	window.location.reload();
	}
	
	grequest.open('GET', url, true);
	grequest.onreadystatechange = function() {
		if(grequest.readyState == 4) {
		  	gresult = grequest.responseText;
			OnGetData(gresult);
		}
	};	
	grequest.send(null);
}

function CommentPost(head, id)
{
	ShowCenterContent();
	header.innerHTML = head;
	OnGetData = function(var1){content.innerHTML = var1;};
	content.innerHTML = loading_msg;
	GetData(SiteName+"/user/postcomment.php?id="+id);
}
function SendComment(frm)
{
	if(frm.comment.value == "")
	{
		alert(frm.comment.getAttribute("error"));
		frm.comment.focus();
		return false;
	}
	
	params = "&cid="+frm.cid.value;
	params += "&comment="+encodeURI(frm.comment.value);
	OnPostData = function(var1){content.innerHTML = var1;};
	PostData(SiteName+"/user/postcomment.php", params);
	frm.comment.disabled = true;
	frm.btn_submit.disabled = true;
	frm.btn_cancel.disabled = true;
}


