//DNN Module: janet.Articles
//Version 01.00.05
//Creation Date: 29th May 2007
//Author: Neil
//Copyright: Copyright 2006-2007 Janet Systems Ltd.
//URL: http://www.janetsystems.co.uk

var ie4=document.all&&!document.getElementById
var ns4=document.layers
var isIE = document.all ? true : false;
var rotateDelay=5000
var itemNum=0
function rotate(){
	if (itemNum>=rotateImages.length){
		itemNum=0;
	}
	if (document.getElementById){
		document.getElementById("janetClient_rotate").innerHTML="<span>" + rotateImages[itemNum]+ "</span>";
		itemNum++
		setTimeout("rotate()",rotateDelay)
	}
}
//news scroll
function janetArticles_Scroll(item)
{
	var it = document.getElementById(item);
	it.style.top=it.style.top.replace(/px|pt,*\)*/g,"")-1;
	if((parseInt(it.style.top) + parseInt(it.offsetHeight))<=0)
	{
		it.style.top=it.parentNode.offsetHeight;
	}
}
//gallery
function janetArticlesGalleryBack(item, itemNum) {
	var n = parseInt(document.getElementById(itemNum).innerHTML)
	n = n - 1;
	if (n < 0) {
		n = 3
	}
	document.getElementById(item).innerHTML="<span>" + janetArticlesGallery[n]+ "</span>";
	document.getElementById(itemNum).innerHTML=n;
}
function janetArticlesGalleryNext(item, itemNum) {
	var n = parseInt(document.getElementById(itemNum).innerHTML)
	n = n + 1;
	if (n > 3) {
		n = 0
	}
	document.getElementById(item).innerHTML="<span>" + janetArticlesGallery[n]+ "</span>";
	document.getElementById(itemNum).innerHTML=n;
}
function janetArticles_NextBack() {
	if (document.getElementById) {
		document.getElementById('Scroll').style.height=document.getElementById('Surround').offsetHeight +'px';
		var ReviewScroll = document.getElementById('ReviewScroll')
		var ReviewSurround = document.getElementById('ReviewSurround')
		if (ReviewScroll) {
			document.getElementById('Scroll').style.height=ReviewSurround.offsetHeight +'px';
			ReviewScroll.style.height=ReviewSurround.offsetHeight +'px';
		//alert(document.getElementById('ReviewSurround').offsetHeight +'px')
		//alert(document.getElementById('Surround').offsetHeight +'px')
			
		}
	}
}
//AJAX Postback coding
//AJAX initalisation
var xmlHttp;
//var requestURL = 'http://localhost/misctest/getusernames.aspx?q=';
//var requestURL// = 'desktopmodules/janet.Articles/Articles_NextBack.aspx?'
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
//netscape, safari, mozilla behave the same???
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 


//Review Next/Back article postback
function ajaxPostBack(requestURL,PortalId,ModuleId,TabID,itemId,Category,SubCategory,SubCategory2,UseSeq,Action) {
	document.getElementById(lblJanetArticles).innerHTML="<div width=100% height=100% align=center><div><img src=" + progress + "></div>"
	if (document.getElementById("itemId")!=null) {
		itemId=document.getElementById("itemId").value;
	}
	
	var url = requestURL + "?PortalId=" + PortalId + "&ModuleId=" + ModuleId + "&TabID=" + TabID + "&itemId=" + itemId + "&Category=" + Category + "&SubCategory=" + SubCategory + "&SubCategory2=" + SubCategory2 + "&Action=" + Action;
   //alert(itemId)
   //alert(url)
   //Create the xmlHttp object to use in the request
   //stateChangeHandler will fire when the state has changed, i.e. data is received back
   // This is non-blocking (asynchronous)
   xmlHttp = GetXmlHttpObject(stateChangeHandler);
   //Send the xmlHttp get to the specified url
   xmlHttp_Get(xmlHttp, url);
}
function FillDatagrid(item,str) {
	document.getElementById(dtgDirectory).innerHTML = "";
}
//http://aspalliance.com/773
function FillTable(scity)
{
  //var auth = scity.getElementsByTagName('EventInfo'); 
  var tbl = document.getElementById(dtgListing);//.getElementsByTagName("tbody")[0];
  for(var i=0;i<tbl.context.childNodes(0).parentNode.childNodes.length;i++)
  {
   var row = document.createElement("TR"); 
   row.setAttribute("className","text");
   row.setAttribute("bgColor","#ECECEC");
  for(var j=0;j<auth.context.childNodes(0).childNodes.length;j++)
  {
   var cell = document.createElement("TD"); 
   cell.innerHTML = auth.context.childNodes(i).childNodes(j).text;
   row.appendChild(cell); 
  }
   tbl.appendChild(row)
  }
}
function setOpacity(id, opacity) {
//alert(id)
//alert(opacity)
  var obj = document.getElementById(id);
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari&lt;1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
//handles fade effect of adding new article
function doFade(i,str) {
	setOpacity('JanetArticlesNew',i);
	setOpacity('lblJanetArticles',100-i);
	i++;
	if (i < 100) {
		window.setTimeout( "doFade(" + i + ")", 0);
	}
	else {
		document.getElementById(lblJanetArticles).innerHTML = document.getElementById("JanetArticlesNew").innerHTML;
		document.getElementById("JanetArticlesNew").style.visibility = 'hidden';
		document.getElementById("JanetArticlesNew").innerHTML = "";
		setOpacity('JanetArticlesNew',0);
		setOpacity('lblJanetArticles',100);
	}
}
//stateChangeHandler will fire when the state has changed, i.e. data is received back
// This is non-blocking (asynchronous)
function stateChangeHandler()
{
   //readyState of 4 or 'complete' represents that data has been returned
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
      //Gather the results from the callback
      //alert(xmlHttp.responseText)
      var str = xmlHttp.responseText;
		//document.getElementById("JanetArticlesNew").innerHTML = str;
		//document.getElementById("JanetArticlesNew").style.visibility = 'visible';
		//doFade(100); 
		arStr = str.split("@@NAT@@");
		document.getElementById(lblJanetAction).innerHTML =arStr[0];
		document.getElementById(lblJanetTitle).innerHTML = arStr[1];
		document.getElementById(lblJanetArticles).innerHTML = arStr[2];
		document.getElementById(lblJanetArticles).scroll(0,0)
	
   }
}

// XMLHttp send GET request
function xmlHttp_Get(xmlhttp, url) {
   xmlhttp.open('GET', url, true);
   xmlhttp.send(null);
}

function GetXmlHttpObject(handler) {
   var objXmlHttp = null;    //Holds the local xmlHTTP object instance

   //Depending on the browser, try to create the xmlHttp object
   if (is_ie){
      //The object to create depends on version of IE
      //If it isn't ie5, then default to the Msxml2.XMLHTTP object
      var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
      
      //Attempt to create the object
      try{
            objXmlHttp = new ActiveXObject(strObjName);
            objXmlHttp.onreadystatechange = handler;
      }
      catch(e){
      //Object creation errored
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
            return;
      }
   }
   else if (is_opera){
      //Opera has some issues with xmlHttp object functionality
      alert('Opera detected. The page may not behave as expected.');
      return;
   }
   else{
      // Mozilla | Netscape | Safari
      objXmlHttp = new XMLHttpRequest();
      objXmlHttp.onload = handler;
      objXmlHttp.onerror = handler;
   }
   
   //Return the instantiated object
   return objXmlHttp;
}

// XMLHttp send GET request
function xmlHttp_Post(xmlhttp, url) {
var theData = '';
  var theform = document.forms[0];
  var thePage = window.location.pathname + window.location.search;
  var eName = '';
 
  theData  = '__EVENTTARGET='  + 
              escape(eventTarget.split("$").join(":")) + '&';
  theData += '__EVENTARGUMENT=' + eventArgument + '&';
  theData += '__VIEWSTATE=' + 
              escape(theform.__VIEWSTATE.value).replace(new 
                              RegExp('\\+', 'g'), '%2b') + '&';
  theData += 'IsCallBack=true&';
  for( var i=0; i<theform.elements.length; i++ )
  {
    eName = theform.elements[i].name;
    if( eName && eName != '')
    {
      if( eName == '__EVENTTARGET' || eName == '__EVENTARGUMENT' 
                                       || eName == '__VIEWSTATE')
      {
        // Do Nothing
      }
      else
      {
        theData = theData + escape(eName.split("$").join(":")) + '=' + 
                                            theform.elements[i].value;
        if( i != theform.elements.length - 1 )
          theData = theData + '&';
      }
    }
  }
   xmlhttp.open('POST', url, true);
   xmlhttp.send(theData);
}

function doInsertFlag() {

}
