// JavaScript Document
<!--
var xmlHttp;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

MM_preloadImages(moha_static_url+'/images/loading.gif');
MM_preloadImages(moha_static_url+'/images/null.gif');

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName, x, newText, empStr) { //v3.0
  var obj =objName;

  if ( (obj) && ( (obj.value == empStr) || (obj.value == '') ) ) {
  	obj.value = newText;
  }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function enable (source, objName, empStr) {
	var src = document.getElementById(source);
	var obj = objName;

	if ( (src.value == '') || (src.value == empStr) ) {
		obj.disabled=true;
	}
}

function gotox (loc) {
	document.location=loc;
}

/* AJAX */

var obj;
function GetXmlHttpObject(handler)
{
	var objXMLHttp=null

	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

return objXMLHttp
}

function wait(millis)
{
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); }
	while(curDate-date < millis);
}


function AJAX(objEff, req)
{
	obj=objEff;

	xmlHttp=GetXmlHttpObject()

	if (xmlHttp == null)
	{
		alert ("Browser does not support AJAX. Try Mozilla Firefox.")
	return
	}

	var url=req;

	url=url;

	msgLoading()

	xmlHttp.onreadystatechange=stateChanged;

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);


}

function stateChanged()
{
	if (xmlHttp.readyState == 1) {
		document.getElementById('loadMes').innerHTML+='.';
	}

	if (xmlHttp.readyState == 4)
	{
		msgLoadingDone();
		document.getElementById(obj).innerHTML=xmlHttp.responseText;

	}
	return;
}

function msgLoading() {
	document.getElementById('loadMes').innerHTML='<img src="'+moha_static_url+'/images/loading.gif" alt="loading" align="top" /> Loading...';

}

function msgLoadingDone() {
	document.getElementById('loadMes').innerHTML='<img src="'+moha_static_url+'/images/null.gif" alt="loading" align="top" />';
}

function addToFavorites(urlAddress,pageName) {
	if (window.external) {
		window.external.AddFavorite(urlAddress,pageName);
	} else {
		alert("Sorry! Your browser doesn't support this function.");
	}
}

function hide_special_content() {
	$('special_message').style.display = 'none';
	createCookie('mohanjith-hide-special',true,3650);
}

//-->
/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function googleSearchHighlight() {	
	if (!document.createElement) return;
	ref = document.referrer;	
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');	        
        	if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0] == 'query') { // q= for Google, p= for Yahoo
				words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
				for (w=0;w<words.length;w++) {
					highlightWord(document.getElementById("content"),words[w]);
					highlightWord(document.getElementById("sidebar"),words[w]);
                }
	        }
	}
}
jQuery.noConflict();

function initMenu() {
	jQuery('ul.submenu').hide();

	jQuery('#navigation li').hover(
		function() {
			jQuery("ul", this).fadeIn('fast');
			jQuery(this).animate({backgroundColor: '#000000'}, 'normal');
		},

		function() {
			jQuery("ul", this).slideUp('fast');
			jQuery(this).animate({backgroundColor: '#333333'}, 'normal');
		}
	);

	jQuery('ul.submenu li').hover(
		function() {
			jQuery(this).animate({backgroundColor: '#000000'}, 'normal');
		},

		function() {
			jQuery(this).animate({backgroundColor: '#222222'}, 'normal');
		}
	);

	if (document.all) {
        	jQuery("#navigation li").hoverClass("sfHover");
    	}
}

jQuery.fn.hoverClass = function(c) {
    return this.each(function(){
        jQuery(this).hover(
            function() { jQuery(this).addClass(c);  },
            function() { jQuery(this).removeClass(c); }
        );
    });
};

jQuery(document).ready(function() {
	initMenu();
});
