var ie5=document.all
var ns6=document.getElementById&&!document.all

var disappeardelay=500  //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)


function dropdownmenu(obj, e, dropmenuID)
{
    if (window.event) 
        event.cancelBubble=true
    else if (e.stopPropagation) 
        e.stopPropagation()

    if (typeof dropmenuobj!="undefined") //hide previous menu
        dropmenuobj.style.display="none"

    clearhidemenu();
    
    if (ie5||ns6)
    {
        obj.onmouseout=delayhidemenu
        dropmenuobj=document.getElementById(dropmenuID)
        if (hidemenu_onclick) 
            dropmenuobj.onclick=function()
                {dropmenuobj.style.display='none'}
        
        dropmenuobj.onmouseover=clearhidemenu
        dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
        
        showhide(dropmenuobj.style, e, "block", "none")
        /*dropmenuobj.x=getposOffset(obj, "left")
        dropmenuobj.y=getposOffset(obj, "top")
        dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
        dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"*/
    }
}

function dynamichide(e)
{
    if (ie5&&!dropmenuobj.contains(e.toElement))
        delayhidemenu()
    else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
        delayhidemenu()
}

function delayhidemenu()
{
    delayhide=setTimeout("dropmenuobj.style.display='none'",disappeardelay)
}

function clearhidemenu()
{
    if (typeof delayhide!="undefined")
        clearTimeout(delayhide)
}

function showhide(obj, e, block, none)
{
    /*if (ie5||ns6)
        dropmenuobj.style.left=dropmenuobj.style.top=-500*/
    
    if (e.type=="click" && obj.display==none || e.type=="mouseover")
        obj.display=block
    else if (e.type=="click")
        obj.display=none
}

function getposOffset(what, offsettype)
{
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null)
    {
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    
    return totaloffset;
}

function contains_ns6(a, b) 
{
    while (b.parentNode)
        if ((b = b.parentNode) == a)
            return true;
    
    return false;
}

function clearbrowseredge(obj, whichedge)
{
    var edgeoffset=0
    if (whichedge=="rightedge")
    {
        var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
        dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
        
        if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
            edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
    }
    else
    {
        var topedge=ie5 && !window.opera? iecompattest().scrollTop : window.pageYOffset
        var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
        
        dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
        if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
        { //move up?
            edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
        
            if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
                edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
        }
    }
    return edgeoffset
}

function iecompattest()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

/*****************************/
function CreateBookmarkLink()
{
	title = "India EveryDay - Information all the time";

	url = "http://www.indiaeveryday.com";

	if (window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external )
	{ // IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{ // Opera Hotlist
		return true;
	}
}

/***************World Clock***************/
function updateclock(z){
		zone=z.options[z.selectedIndex].value;
		isitlocal=(z.options[0].selected)?true:false;
}

function WorldClock(){
	now=new Date();
	ofst=now.getTimezoneOffset()/60;
	secs=now.getSeconds();
	//sec=-1.57+Math.PI*secs/30;
	mins=now.getMinutes();
	//min=-1.57+Math.PI*mins/30;

	//alert(zone + " ofst : " + ofst);
	hr=(isitlocal)?now.getHours():(now.getHours() + parseInt(ofst)) + parseInt(zone);

	//handling float minutes
	floatMin = zone - parseInt(zone);
	if (floatMin > 0)
		mins = mins + floatMin * 60;

	if (mins > 60)
	{
		hr = hr + 1;
		mins = mins - 60;
	}

	//hrs=-1.575+Math.PI*hr/6+Math.PI*parseInt(now.getMinutes())/360;
	if (hr < 0) hr+=24;
	if (hr > 23) hr-=24;
	ampm = (hr > 11)?"PM":"AM";
	statusampm = ampm.toLowerCase();

	hr2 = hr;
	if (hr2 == 0) hr2=12;
	(hr2 < 13)?hr2:hr2 %= 12;
	if (hr2<10) hr2="0"+hr2

	var finaltime=hr2+':'+((mins < 10)?"0"+mins:mins)+':'+((secs < 10)?"0"+secs:secs)+' '+statusampm;

	if (document.all)
		worldclock.innerHTML=finaltime
	else if (document.getElementById)
		document.getElementById("worldclock").innerHTML=finaltime
	else if (document.layers){
		document.worldclockns.document.worldclockns2.document.write(finaltime)
		document.worldclockns.document.worldclockns2.document.close()
	}

	setTimeout('WorldClock()',1000);
}


/*****************Search*******************/
function searchClick(e, val)
{
    document.getElementById('ctl00_ancSearchWeb').className = 'searchTags';
	//document.getElementById('ctl00_ancSearchNews').className = 'searchTags';
	document.getElementById('ctl00_ancSearchImages').className = 'searchTags';
	document.getElementById('ctl00_ancSearchVideo').className = 'searchTags';

    document.getElementById('img_' + 'ctl00_ancSearchWeb').src = 'Images/search/ctl00_ancSearchWeb.gif';
    //document.getElementById('img_' + 'ctl00_ancSearchNews').src = 'Images/search/ctl00_ancSearchNews.gif';
    document.getElementById('img_' + 'ctl00_ancSearchImages').src = 'Images/search/ctl00_ancSearchImages.gif';
    document.getElementById('img_' + 'ctl00_ancSearchVideo').src = 'Images/search/ctl00_ancSearchVideo.gif';
    
    document.getElementById('ctl00_hdnSearchSel').value = val;
    
	e.className = 'searchLinkSel';
	var img = document.getElementById('img_' + e.id)
	img.src= 'Images/search/' + e.id + 'Sel.gif';
}

function txtEnterKey(e, btnId)
{
    e = (e == null) ? window.event : e;
    if ((e.which && e.which == 13) || 
        (e.keyCode && e.keyCode == 13))
    {
        var btn = document.getElementById(btnId);
        btn.click();
        return false;
    } 
    else 
        return true;
}

/*************Image Rotator *******************/
var interval = 5; 
var random_display = 0;
interval = interval * 1000;

function imageItem(image_location) 
{
	this.image_item = new Image();
	this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj) 
{
	return(imageObj.image_item.src)
}

function generate(x, y) 
{
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

function getNextImage() 
{
	if (random_display) 
	{
		image_index = generate(0, number_of_image-1);
	}
	else 
	{
		image_index = (image_index+1) % number_of_image;
	}
	
	var new_image = get_ImageItemLocation(image_list[image_index]);
	return(new_image);
}

function rotateImage(place) 
{
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "rotateImage('"+place+"')";
	setTimeout(recur_call, interval);
}

function hidestatus(){
window.status=''
return true
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)

document.onmouseover=hidestatus
document.onmouseout=hidestatus

