	/*********************************************************************/
// script.js : JavaScript include file for Ananthapuri.com
// ŠAnanthapuri.com. All rights reserved.
// Author: Sreekandakumar Pillai, sree@ananthapuri.com
/*********************************************************************/

function init() {
    window.onerror = null;
    window.focus();
//      initslidebar();
//      fnAmznContext();
}

//to display Amazon Context menus
function fnAmznContext() {
 amzn_cl_tag="ananthapurico-20";
 amzn_cl_border_color="CCCCCC";
 amzn_cl_categories="a,b,c,d,e,f,g,i,j,k,l";
  document.write('<scr' + 'ipt type="text/javascript"');
  document.write('src="http://cls.assoc-amazon.com/s/cls.js">');
  document.write('</scr' + 'ipt><br />');
}

function showDivMsg(msg) {
    content = '<table  width="300" border="0" cellpadding="7" cellspacing="0" bgcolor="#FFFFFF"><td align="left" height="100%" width="100%"><font face="Verdana, Arial" color="#000000" size="1"><b>'+ msg + '</b></font></td></table>';
    if (document.getElementById&&!document.all)   {
      elid = document.getElementById("plswait");
      elid.style.pixelLeft = ( (window.innerWidth - 300) / 2);
      elid.style.pixelTop = ( (window.innerHeight - 30) / 2 + window.pageYOffset);
    } else if (document.all) { 
      elid = document.all("plswait");
      elid.style.pixelLeft = ( (document.body.clientWidth - 300) / 2);
      elid.style.pixelTop = ( (document.body.clientHeight - 30) / 2 + document.body.scrollTop);
    };
    elid.innerHTML = content;
    elid.style.visibility = "visible";
}

function showPlsWait() {
    showDivMsg('  Please wait while searching for news headlines ...  ');
}

function showPlsWaitRecipe() {
    showDivMsg('  Please wait while searching recipes for you...  ');
}

function hidePlsWait() {
    hideMsg('plswait');
}

function hideMsg(id)  {
    eval('document.all("'+ id + '").innerHTML=""');
    eval("document.all."+ id + ".style.visibility='hidden'");
}

function showServerImage(obj)   {
    imgname = (obj.value).replace(/\'/g,"\\'");
    content = '<img src="/image/' + imgname+ '" border="0" height="150" weight="150">';
    eval('document.all("imagepreview").innerHTML=\'' + content +"'");
    document.all.imagepreview.style.visibility ='visible';
}

function newWin(src, name,_width,_height)  {
    _left = window.screenLeft + (document.body.clientWidth - _width)/2;
    _top = window.screenTop +(document.body.clientHeight - _height)/2;
    features ='channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,,resizable=1,width='+_width+',height='+_height+',top='+_top+',left='+_left;
    eval(name +"= window.open(src,name, features)");
    eval("if ("+name+"!= null) "+name+".focus()");
}

function MailingList()  {
    if(!/^[\w_-]+(\.[\w_-]+)*@[\w_-]+(\.[\w_-]+)*\.[a-z]{2,4}$/i.test(document.frmMailingList.email.value)) {
        alert("Please enter a valid email address");
        document.frmMailingList.email.focus();
        return false;
    } else {
        return true;
    }
}

function favorites()  {
  window.external.AddFavorite(location.href, document.title);
}

function makeHome()  {
  this.style.behavior='url(#default#homepage)'; this.setHomePage('http://www.ananthapuri.com/');
}

function HelpClose()    {
    if ( (window.opener != null) && !window.opener.closed)
            window.opener.focus();
    window.close();
}

function return2Home() {
    if (window.opener != null)  {
        if (window.opener.closed) {
            home_win = window.open("/","home_win");
            if (home_win != null)
                home_win.focus();
        } else {
        window.opener.focus();
        }
    } else {
        home_win = window.open("/","home_win");
        if (home_win != null)
            home_win.focus();
    }
}

// Set focus to the firstavailable textbox/textarea/select/file uplaod element of the first available form.
function initFocus() {
    var i, iForms=document.forms.length;
    var bExit = false;
    for(i=0; (i<iForms && bExit==false); i++){
        var oForm=document.forms[i];
        var j, iElements=oForm.elements.length;
        for(j=0; (j<iElements && bExit==false); j++){
            var oElement=oForm.elements[j];
            if (oElement.type == "textarea" || oElement.type == "text" || oElement.type == "file" || oElement.type == "password" || oElement.type == "select-one" || oElement.type == "select-multiple")  {
                oElement.focus();
                bExit=true;
                break;
            }
        }
    }
}

function DisplayCurrentTime(){
  var dte = new Date();
  dte.setTime(dte.getTime() + (dte.getTimezoneOffset()+330)*60*1000); 
  var currTime = dte.toLocaleString();
  if (document.getElementById&&!document.all)   {
    document.getElementById("datetime").innerHTML="<b>India Time: </b> "+currTime;
  } else if (document.all) {
    document.all("datetime").innerHTML="<b>India Time: </b> "+currTime;
  };
}

function convertToLocalTime(sTime){
//a space before AM/PM returned from moreover. This is required in Firefox to identify a time string
  sTime = sTime.substring(0, sTime.length-2) + " " + sTime.substring(sTime.length-2, sTime.length);
  var dte = new Date(sTime);
  dte.setTime(dte.getTime() - dte.getTimezoneOffset()*60*1000); 
  document.write(dte.toLocaleString());

}

function greetUser (strUser) {
var curTime, curHour, greeting;
	curTime = new Date();
	curHour = curTime.getHours();
	if (curHour > 18) greeting = "Evening";
	else if (curHour >12) greeting = "Afternoon";
	else greeting = "Morning";
	document.write("<b>Good " + greeting + ", " + strUser + "</b>");
}

//===============================================
//SLIDEBAR advertisement script
var ie=document.all;
var dom=document.getElementById;
var ns4=document.layers;
var slideobj=null;
var slidetop = 210;

function initslidebar(){
    if (!dom&&!ie&&!ns4) return;
    if (document.body.clientWidth < 985) return;
    slideobj=(dom)?document.getElementById("slidebar").style : ie? document.all.slidebar : document.slidebar;
    slideobj.left=(document.body.clientWidth/2+370)+'px';
    slideobj.top=document.body.clientHeight+'px'
//    slideobj.top='1px';
    slideobj.top=slidetop + 'px';
//    slideobj.display=(dom||ie)? "" : "none";
    dropstart=setInterval('slideobj.display=(dom||ie)? "" : "none";', 2000);
//    dropstart=setInterval("slidebar()",10);
    window.onresize=resizeslidebar;
}

function slidebar(){
if (parseInt(slideobj.top)<slidetop)
    if (parseInt(slideobj.top)<=(slidetop+2))
        slideobj.top=parseInt(slideobj.top)+2+'px'
    else
        slideobj.top=slidetop+'px';
else
    clearInterval(dropstart);
}

function dismissbox(){
    if (window.dropstart) clearInterval(dropstart);
    slideobj.display="none";
}

function truebody(){
    return (document.compatMode!="BackCompat")? document.documentElement : document.body
}

function resizeslidebar(){
    if (slideobj!=null) dismissbox(); 
    initslidebar();
}
//window.onresize=resizeslidebar;


//===============================================
//LOCKFORM - Lock the form from submitting again.
//Add the following script to the input submit element in the form.
//onclick=return(lockForm(document.formName));

var formSubmitted = false;
function lockForm(oForm) {
  if(oForm.Submit.value != 'Please Wait...') {
    if(!formSubmitted) {
      formSubmitted=true;
      oForm.Submit.value = 'Please Wait...';
      oForm.Submit.disabled = true;
//      oForm.submit();
//return true;
    }
  }
}
//===============================================
//Displays two ads horizontally in a box, below the menu bar
function adBannerMenu() {
google_ad_client = "ca-pub-8709410846673588";
/* Ananthapuri_Main_Banner */
google_ad_slot = "5985284293";
google_ad_width = 468;
google_ad_height = 60;
document.write('<scr' + 'ipt type="text/javascript"');
document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scr' + 'ipt>');
}

//Displays two ads horizontally in a box, for contents
function adBanner2() {
google_ad_client = "ca-pub-8709410846673588";
/* Ananthapuri_banner_content_box */
google_ad_slot = "6610639325";
google_ad_width = 468;
google_ad_height = 60;
document.write('<scr' + 'ipt type="text/javascript"');
document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scr' + 'ipt>');
}

//Display 4 ads in a tower box - for SIDE bar
function adTower4() {
google_ad_client = "ca-pub-8709410846673588";
/* Ananthapuri_Tower_Sidebar */
google_ad_slot = "4571178180";
google_ad_width = 160;
google_ad_height = 600;
document.write('<scr' + 'ipt type="text/javascript"');
document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scr' + 'ipt>');
}

//Displays 4 link ads vertically in a box
function adlinks4() {
google_ad_client = "ca-pub-8709410846673588";
/* Adlinks_200x90x4 */
google_ad_slot = "6116285526";
google_ad_width = 200;
google_ad_height = 90;
document.write('<scr' + 'ipt type="text/javascript"');
document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scr' + 'ipt>');
}

//Displays Ad Links a box 200x90
function adlinksforum() {
google_ad_client = "ca-pub-8709410846673588";
/* Adlinks_200x90x4 */
google_ad_slot = "6116285526";
google_ad_width = 200;
google_ad_height = 90;
document.write('<scr' + 'ipt type="text/javascript"');
document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scr' + 'ipt>');
}

//Displays 5 adlinks horizontally (below the menu in all pages)
function adlinks5_horizontal() {
google_ad_client = "ca-pub-8709410846673588";
/* Ananthapuri_adlinks468x15x5 */
google_ad_slot = "3577344373";
google_ad_width = 468;
google_ad_height = 15;
document.write('<scr' + 'ipt type="text/javascript"');
document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
document.write('</scr' + 'ipt>');
}


//Google Referrals ads vertically in a box
//Display 4 ads in a tower box - for SLIDE bar
function showSponsoredLinks () {
    google_ad_client = "pub-8709410846673588";
    google_alternate_ad_url = "http://www.ananthapuri.com/slidebar.asp";
    google_ad_width = 120;
    google_ad_height = 600;
    google_ad_format = "120x600_as";
    google_cpa_choice = "CAEaCCVdpbbcBurZUAVQA1AIULcDUJ0CUBJQQ1A0";    
    google_ad_channel ="0474553077";
    google_ad_type = "text";    
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "000000";
    google_color_text = "000000";
    document.write('<scr' + 'ipt type="text/javascript"');
    document.write('src="http://pagead2.googlesyndication.com/pagead/show_ads.js">');
    document.write('</scr' + 'ipt>');
}

//Displays Shaadi and Fropper rectangle ads 
function adShaadiFropper() {
    document.write('<p align="center"><a href="http://www.fropper.com/dating-member/index.php?register=Y&ptnr=anant345"><img src="http://www.fropper.com/partners/get-banner.php?banner_type=banners-buttons&banner_size=468x60" border="0"></a><br />&nbsp;<br /><a href="http://www.shaadi.com/ptnr.php?ptnr=ananthapuri"><img src="http://www.shaadi.com/shaadi-rewards/get-banner.php?banner_type=buttons&banner_size=468x60" border=0></a></p>');
}

// Load Active Objects for displaying PEEDY
function LoadMSAgent() {
// Load Microsoft Agent Control
    document.write('<OBJECT ID="AgentControl" width=0 height=0 \n');
    document.write('CLASSID="CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F" \n');
    document.write('CODEBASE="http://activex.microsoft.com/activex/controls/agent2/MSagent.exe#VERSION=2,0,0,0"> \n');
    document.write('</OBJECT> \n');

//Text-to-Speech (TTS) -->
    document.write('<OBJECT id="TTS" width=0 height=0 \n');
    document.write('CLASSID="CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575" \n');
    document.write('CODEBASE="http://activex.microsoft.com/activex/controls/agent2/tv_enua.exe#VERSION=6,0,0,0"> \n');
    document.write('</OBJECT> \n');

//SAPI 4.0a -->
    document.write('<OBJECT WIDTH=0 HEIGHT=0 \n');
    document.write('CLASSID="CLSID:0C7F3F20-8BAB-11D2-9432-00C04F8EF48F" \n');
    document.write('CODEBASE="http://activex.microsoft.com/activex/controls/sapi/spchapi.exe#VERSION=4,0,0,0"> \n');
    document.write('</OBJECT> \n');
}

var _modalWindow = null;
function openModalDialog(url, w, h, scrollbarTag, nameStr, toolbar) {
	if(window.Event) window.top.captureEvents(Event.CLICK|Event.FOCUS);
	window.top.onclick = ignoreEvents;
	window.top.onfocus = focusHandler;
	if (toolbar == null) {
	    toolbar = "no";
	}
	l = (screen.width - w) / 2;
	t = (screen.height - h) / 2;
	_modalWindow = window.open(url, nameStr, 
 		"height="+h+",width="+w+",left="+l+",top="+t+
 		",status=no,toolbar="+toolbar+",menubar=no,location=no," + scrollbarTag);	
	_modalWindow.window.focus();
}

function ignoreEvents(e) {
	return false;
}

function focusHandler() {
	if(_modalWindow) {
		if(!_modalWindow.closed) {
			_modalWindow.focus();
		} else {
			if(window.Event) window.top.releaseEvents(Event.CLICK|Event.FOCUS);
			window.top.onclick = "";
		}
	}
}

	
//Display NEW WINDOW icon next to external links
function doOpenNewWindow() {

 if (!document.getElementsByTagName) return false;
 var links = document.getElementsByTagName("a");

 var i = links.length;

 while (i--) {
 	var lnk = links[i];
//	alert("i=" + i + " href=" + lnk.href);
//	alert("links.length=" + links.length);

    if (lnk.href.indexOf("ananthapuri.com") == -1) {

//    if (lnk.href.split('/')[2].replace(/www\./, '') != document.domain.replace(/www\./, '') && !lnk.getAttribute('target') && lnk.href.indexOf("teck.in") == -1 ) {
	    var img = document.createElement("img");
	    img.setAttribute("src", "http://www.ananthapuri.com/image/newwin.gif");
	    img.setAttribute("alt", "(opens in a new window)");
	    img.setAttribute("border", "0");

	    var anchr = document.createElement("a");
	    anchr.setAttribute("href", lnk.href);
	    anchr.setAttribute("title", lnk.title + "\n(opens in a new window)");
	    anchr.setAttribute("target", "_blank");
	    anchr.appendChild(img);

	    // append new elements
	    var spc = document.createTextNode(' ');
	    lnk.parentNode.insertBefore(spc, lnk.nextSibling);
	    lnk.parentNode.insertBefore(anchr, lnk.nextSibling.nextSibling);

    }
  }
}

//Script to display running GMAIL inbox size
function updateEmailSize() {
   var CP = [ [ 1193122800000, 4321 ], [ 1199433600000, 6283 ], [ 2147328000000, 43008  ]];
   var now = (new Date()).getTime(); 
   var quota, i;
   
   if (document.getElementById) {
      quota = document.getElementById("quota");
   } else if (window["quota"]) {
      quota = window[id];
   }
   for (i = 0; i < CP.length; i++) {
      if (now < CP[i][0]) {
         break;
      }
   }
    
   if (i == CP.length) {
      quota.innerHTML = 'Over ' + CP[i - 1][1];
   } else {
      var ts = CP[i - 1][0];
      var bs = CP[i - 1][1];
      quota.innerHTML = Math.floor(((now-ts) / (CP[i][0]-ts) * (CP[i][1]-bs)) + bs); 
   }
}

// Google CSE Search Box Begins
function fnGoogleCSE() {
 var strGoogleCSE;
 strGoogleCSE =
	'<form class="search" method="get" onsubmit="if(this.q.value==\'Search Ananthapuri.com\'){return false;};" id="searchbox_009477821170850572014:_bib_ujlsx4" action="/search.html"> ' +
	'<input type="hidden" name="cx" value="009477821170850572014:_bib_ujlsx4" /> ' +
	'<input type="hidden" name="cof" value="FORID:11" /> ' +
	'<input name="q" type="text" size="28" class="textbox" value="Search Ananthapuri.com" title="Enter Your Search Query Here to Search at Ananthapuri.com" />&nbsp;' +
	'<input type="submit" name="sa" value="Search" class="searchbutton" /> ' +
	'</form> ';
	document.write(strGoogleCSE);
	(function() { var f = document.getElementById("searchbox_009477821170850572014:_bib_ujlsx4"); if (f && f.q) { var q = f.q; var n = navigator; var l = location; if (n.platform == "Win32") { q.style.className = "textbox";} var b = function() { if (q.value == "") {q.value="Search Ananthapuri.com";} }; var f = function() { if(q.value=="Search Ananthapuri.com"){q.value=""};}; q.onfocus = f; q.onblur = b; if (!/[&?]q=[^&]/.test(l.search)) { b(); } } })();
}

