
var searchobj 				
var colshown = false;
var swshow =false;
var oneoftheconfig=""
var prev_oneoftheconfig=""
var domain=".indiatimes.com"
var ColorCookieName="IndTimesColorCookie"
var Colordivstatus='false'
var arrCssName=new Array('c1','c2','c3','c4','c5','c6','c7')
var arrImgName=new Array('img1','img2','img3','img4','img5','img6','img7')
var arrImgMsid=new Array('2577581','2577562','2577553','2577565','2577571','2577577','2577585')
var arrImgChkMsid=new Array('2577583','2577563','2577556','2577570','2577573','2577580','2577588')
var ids=new Array('mail','mailhover','chat','chathover','dating','datinghover','blogs','blogshover')
var cookiestring= document.cookie;
cookiestring = cookiestring.toLowerCase();
var screen_width = screen.width;
var curres = "xx";
if(screen_width < 1024){						
	if(GetColorCookie('displaytype')==null){curres = "narrow";}
	else{curres = GetColorCookie('displaytype')}	 
}else{
	if(GetColorCookie('displaytype')==null){curres = "wide";}
	else{curres = GetColorCookie('displaytype');}	
} 	
function popup(url, w, h){
	var x = (screen.width - w) / 2;   
    var y = (screen.height - h) / 2  
	tvow=window.open(url,'so','toolbar=0,scrollbars=0,location=0,status=0,menubars=0,resizable=0,width='+w+',height='+h+',top='+y+',left='+x+',maximize=null');
}
function get_random(seccount){
	var ranNum= Math.floor(Math.random()*seccount);
	if (ranNum <0 || ranNum > seccount){return 1;}							
	return ranNum;
}
function putvale(str){
	var myString=str
	var mySplitResult=myString.split(",")
	seccount=mySplitResult.length
	var rannum=get_random(seccount)
	var configtext=mySplitResult[rannum]
	if((prev_oneoftheconfig.toLowerCase()).search(searchobj.toLowerCase())==-1&&prev_oneoftheconfig !=""){
		document.getElementById("query").value=searchobj
	}else{
		document.getElementById("query").value=configtext
	}
	prev_oneoftheconfig=oneoftheconfig
}
function checkradiotab(radiovalue){
	strvalue=radiovalue+1
	if(strvalue==1){
		oneoftheconfig=webconfig
	}else if(strvalue==2){
		oneoftheconfig=indiatimesconfig
	}else if(strvalue==3){
		oneoftheconfig=shopconfig
	}else{
		oneoftheconfig=webconfig
	}
	document.radioform.searchbutton[radiovalue].checked=true
	var sband="/searchband/"+strvalue+".cms"
	populatediv(sband,'SearchBandDisplay')
}
function populatediv(urlval,divval){
	try{
		var xmlhttp=false
		var status=0
		xmlhttp=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")
		searchobj=document.getElementById("query").value
		if(xmlhttp){
			xmlhttp.onreadystatechange=function(){
				if(xmlhttp.readyState==4){
					if(xmlhttp.status==200){
						document.getElementById(divval).innerHTML=xmlhttp.responseText
						putvale(oneoftheconfig)
					}else if(xmlhttp.status==404)status=0
					else status=0
				}
			}
			xmlhttp.open("GET",urlval,true)
			xmlhttp.send(null)
		}
	}catch(e){xmlhttp=false}
}

function checkKeyword(){
	if(document.getElementById("query").value==""){
		alert("Please enter text in search box")
		return false
	}
}
function ManageGoogleimg(radioObj,divid,radiovalue){
	var GetDivId;
	GetDivId=document.getElementById(divid)
	if(radioObj.value=="indiatimes" || radioObj.value=="web")GetDivId.style.visibility="visible"
	else GetDivId.style.visibility="hidden"
	checkradiotab(radiovalue)
}

function getObj(x){
	if(document.getElementById){
		return document.getElementById(x)
	}else if(document.all){
		return document.all[x]
	}else if(document.layers){
		return document.layers[x]
	}
	return null;
}

function sub_Colorchange(classname){
	document.getElementById('netspidersosh').className=''+classname
	setColorCookie(ColorCookieName,classname,7);
}
function colorchange(colour){
	document.getElementById('pageopt').style.visibility="hidden"
	switch(colour){
		case 'orange':sub_Colorchange("c1","1096002","1096014");break;
		case 'blue':sub_Colorchange("c2","1096218","1098826");break;
		case 'black':sub_Colorchange("c3","1339749","1339853");break;
		case 'green':sub_Colorchange("c4","1340147","1340162");break;
		case 'lavender':sub_Colorchange("c5","1382691","1382732");break;
		case 'magenta':sub_Colorchange("c6","1383070","1383089");break;
		case 'paleyellow':sub_Colorchange("c7","1383438","1383470");break;
		case 'violet':sub_Colorchange("c8","1383967","1383973");break;
	}
}
function showColorBox(divid){
	var _optstr = '<table width="122" border="0" cellspacing="0" cellpadding="0" class="pageoptbg" height="20">';
	_optstr += '<tr><td style="padding-left:4px;"><a href="#" onclick="colorchange(\'blue\',\'c2\');"><img name="img2" id="img2" width="12" height="11" alt="Blue" border="0"/></a> </td>';
	_optstr += '<td><a href="#" onclick="colorchange(\'orange\');"><img name="img1" id="img1" width="12" height="11" border="0" alt="Orange"/></a> </td>';
	_optstr += '<td><a href="#" onclick="colorchange(\'black\');"><img name="img3" id="img3" width="12" height="11" border="0" alt="Black"/></a> </td>';
	_optstr += '<td><a href="#" onclick="colorchange(\'green\');"><img name="img4" id="img4" width="12" height="11" alt="Green" border="0"/></a> </td>';
	_optstr += '<td><a href="#" onclick="colorchange(\'lavender\');"><img name="img5" id="img5" width="12" height="11" alt="Lavender" border="0"/></a> </td>';
	_optstr += '<td><a href="#" onclick="colorchange(\'magenta\');"><img name="img6" id="img6" width="12" height="11" alt="Magenta" border="0"/></a> </td>';
	_optstr += '<td><a href="#" onclick="colorchange(\'paleyellow\');"><img name="img7" id="img7" width="12" height="11" alt="Pale Yellow" border="0"/></a></td></tr></table>';	
	getObj(divid).innerHTML = _optstr;
	getImage();
	showdiv(divid);
}
function showdiv(id){
	var obj = getObj(id);
	obj.style.visibility="visible";
	obj.style.display="inline";	
}
function hidediv(id){
	var obj = getObj(id);
	obj.style.visibility="hidden";
	obj.style.display="none";
}
function tabshowhide(id){
	var id_num=id.substr(1,id.length-1)
	var start_point=1
	var end_point=0
	if(id_num<=5){
		start_point=1
		end_point=5
	}else if(id_num>5&&id_num<=9){
		start_point=6
		end_point=9
	}
	for(var l_id=start_point;l_id<=end_point;l_id++){
		var curr_id="l"+l_id
		var curr_content_id="tabcontent"+l_id
		if(curr_id==id){
			document.getElementById(curr_id).className='current'
			document.getElementById(curr_content_id).style.display='block'
		}else{
			document.getElementById(curr_id).className=''
			document.getElementById(curr_content_id).style.display='none'
		}
	}	
}

function setTableWidth(resol){	
	var polldata;
	if(getObj('pollh').innerHTML !="")
		polldata=getObj('pollh').innerHTML
	else
		polldata=getObj('pollv').innerHTML
	try{
		setColorCookie('displaytype',resol,365);
		var tableobj=document.getElementById('netspidersosh')
		if(resol == "wide"){			
			tableobj.width="990"
			getObj('pollv').innerHTML=polldata;
			getObj('pollh').innerHTML="";
			getObj('hotlinksv').innerHTML=document.getElementById('hotlinksh').innerHTML;
			getObj('adsv').innerHTML=document.getElementById('adsh').innerHTML;
			getObj('layouttabimg').innerHTML="<img border=0 style ='margin-right:1px' src = '/photo.cms?msid=2574313'/><a href=# onclick=setTableWidth('narrow')><img alt='Narrow Layout' title='Narrow Layout' border=0 style ='margin-left:1px' src = '/photo.cms?msid=2574319'/></a>";
			getObj('tabcontent10').style.visibility='visible'
			getObj('tabcontent10').style.display='block'
			getObj('adsbottom').style.visibility='hidden'
			getObj('adsbottom').style.display='none'
			getObj('dvbottom').style.visibility='hidden'
			getObj('dvbottom').style.display='none'
			getObj('highlightstab').width="430";
		}else{			
			tableobj.width="768"
			getObj('pollh').innerHTML=polldata
			getObj('pollv').innerHTML=""
			getObj('layouttabimg').innerHTML="<a href=# style=cursor:hand onclick=setTableWidth('wide')><img border=0 alt='Wide Layout' title='Wide Layout' style ='margin-right:1px' src = '/photo.cms?msid=2574314'/></a><img border=0 style ='margin-left:1px' src = '/photo.cms?msid=2574316'/>"
			getObj('tabcontent10').style.visibility='hidden'
			getObj('tabcontent10').style.display='none'
			getObj('adsbottom').style.visibility='visible'
			getObj('adsbottom').style.display='block'
			getObj('dvbottom').style.visibility='visible'
			getObj('dvbottom').style.display='block'
			getObj('highlightstab').width="401";
		}
	}catch(e){}
	refreshads1866();
}

function GetColorCookie(name){
	var nameEQ=name+"="
	var ca=document.cookie.split(';')
	for(var i=0;i<ca.length;i++){
		var c=ca[i]
		while(c.charAt(0)==' ')c=c.substring(1,c.length)
		if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);
	}
	return null
}
function setColorCookie(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 setTableClass(tableid){
	if(GetColorCookie(ColorCookieName)!=null){
		document.getElementById(tableid).className=GetColorCookie(ColorCookieName)
	}
}

function hidepageoption(evt){
	if(window.event&&window.event.srcElement){
		if(window.event.srcElement.id=="arrow" || window.event.srcElement.id=="pgarrow" || window.event.srcElement.id=="pgarrowsw")
		{}else{
			hidediv("pageopt");
		}
	}
}

function getImage(){
	var CookieVal=GetColorCookie(ColorCookieName);
	for( i=0; i<arrCssName.length;i++){
		if(arrCssName[i]==CookieVal)
			document.getElementById(""+arrImgName[i]).src="/photo.cms?msid=" + arrImgChkMsid[i];
		else
			document.getElementById(""+arrImgName[i]).src="/photo.cms?msid=" + arrImgMsid[i];
	}
	if( CookieVal== null)
		document.getElementById(""+arrImgName[1]).src= "/photo.cms?msid=1564207";
}

function mailtrim(mvalue){
	var temp1 = mvalue;
	var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
	if (obj.test(temp1)) { temp1 = temp1.replace(obj, '$2'); }
	var obj = /  /g;
	while (temp1.match(obj)) { temp1 = temp1.replace(obj, " "); }
	return temp1;
}

function changeForm(){
	if(mailtrim(document.marketform.ticker1.value)==false){	
		alert('Please enter any symbol');
		document.marketform.ticker1.value="";
		document.marketform.ticker1.focus();
		return false;
	}else{
		var c = escape(document.marketform.ticker1.value);  
		document.marketform.ticker.value = c;       
		document.marketform.action="http://economictimes.indiatimes.com/currentquote.cms";
		document.marketform.ticker1.value = "";
		return true;
	}															
}

function submitmyformp(f,w,h){				
	var ch=0;			
	for(i=0;i<document.pollform.PRadio.length;i++){					
		if(document.pollform.PRadio[i].checked==1){
			ch=1;		
			document.pollform.action="/vote.cms";															
			break;
		}
	}
	if(ch==0){
    	alert("Please select an Option to participate in the poll");
		return false;
	}
	f.target = 'foo';
	var x = (screen.width - w) / 2;   
    var y = (screen.height - h) / 2  
	window.open('',f.target,'menubar=no,scrollbars=0, width='+w+',height='+h+',top='+y+',left='+x);
	document.pollform.submit();
	return false;
}

	function submitmyforma_newpoll(f){
		f.target = 'foo';
		window.open('',f.target,'menubar=no,scrollbars=0, width=595,height=320');
		f.submit();
		return false;
	}
function submitmyforma(f){
		f.target = 'foo';
		window.open('',f.target,'menubar=no,scrollbars=0, width=521,height=460');
		f.submit();
		return false;
}

function checkVal(theForm){
	if (theForm.login.value==""){
		alert("Please enter a value for the \"Indiatimes ID\" field.");
		theForm.login.focus();
		return (false);
	}
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
	var checkOK1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.";
	var checkStr = theForm.login.value;
	if (checkStr.length > 50){
		alert("Please enter upto 50 characters in the \"Indiatimes ID\" field.");theForm.login.focus();theForm.login.value="";
		return (false);
	}
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		ch1 = checkStr.charAt(0);
		for (k=0; k < checkOK1.length; k++)
			if (ch1 == checkOK1.charAt(k))
		    	break;
		  		if (k == checkOK.length){
					allValid = false;
					break;
				}	
				for (j = 0;  j < checkOK.length;  j++)
				   	if (ch == checkOK.charAt(j))
				  		break;
				   	if (j == checkOK.length){
					    allValid = false;
					    break;
					}
	}
	if (!allValid){
		alert("Please enter a valid Indiatimes ID only letters (a-z), numbers (0-9), underscore (_) and dot(.) without any space in between. Indiatimes ID must start with a letter. ");
		theForm.login.focus();
		return (false);
	}
	if (theForm.passwd.value == ""){
		alert("Please enter a value for the \"Password\" field.");
		theForm.passwd.focus();
		return (false);
	}
	theForm.submit();
	return(true);
}

function getCookievalue(strcookie){ 
	var ipos = cookiestring.indexOf(strcookie);
	var ipos2 = cookiestring.indexOf(';',ipos);  
	if (ipos != -1){
		if (ipos2 == -1) 
			ipos2 = cookiestring.length;
		return unescape(cookiestring.substring((ipos+strcookie.length+1),ipos2));
	}
}
function setHomepage(what, url){
	if (navigator.appName == 'Microsoft Internet Explorer' && document.getElementById)  
		setHomepageExplorer(what, url);
	else if (document.layers || document.getElementById) setHomepageNetscape(what, url);
		return false;
}

function setHomepageNetscape(what, url){
	var warn = 'Due to Netscapes security handling, making Indiatimes US Edition ' + 'your homepage, will show you a dialog with a warning.' + 'If you do not wish to grant this site the access to ' + 'your browser settings, you can manually copy ' + 'http://usedition.indiatimes.com and paste it in the location field in ' + 'Edit|Preferences|Navigator.';
	if (confirm(warn)){
		netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
		navigator.preference('browser.startup.homepage', url);netscape.security.PrivilegeManager.disablePrivilege("UniversalPreferencesWrite");
	}
}

function setHomepageExplorer(what, url){
	what.style.behavior = 'url(#default#homepage)';
	what.setHomePage(url);
}
function Set_Ckie(name,value,expires,path,domain,secure){
	var today=new Date()
	today.setTime(today.getTime())
	if(expires){expires=expires*1000*60*60*24}
	var expires_date=new Date(today.getTime()+(expires))
	document.cookie=name+"="+escape(value)+((expires)? ";expires="+expires_date.toGMTString(): "")+((path)? ";path="+path : "")+((domain)? ";domain="+domain : "")+((secure)? ";secure" : "")
}
function Get_Ckie(name){
	var start=document.cookie.indexOf(name+"=")
	var len=start+name.length+1
	if((!start)&&(name !=document.cookie.substring(0,name.length))){
		return null
	}
	if(start==-1)return null;
	var end=document.cookie.indexOf(";",len)
	if(end==-1)end=document.cookie.length
	return unescape(document.cookie.substring(len,end))
}
function Delete_Ckie(name,path,domain){
	if(Get_Ckie(name))document.cookie=name+"="+((path)? ";path="+path : "")+((domain)? ";domain="+domain : "")+";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function remIDPASS(){
	if(document.getElementById("rememberpassword").checked){
		var userid=document.getElementById("login").value
		var pass=document.getElementById("passwd").value
		Set_Ckie("commlogu",userid,100,"/",".indiatimes.com","")
		Set_Ckie("commlogp",pass,100,"/",".indiatimes.com","")
		document.loginfrm.submit()
	}else{
		Delete_Ckie("commlogu","/",".indiatimes.com")
		Delete_Ckie("commlogp","/",".indiatimes.com")
	}
}
function strtrim(str){
	if(!str || typeof str !='string')
	return null;
	return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function loadIDPass(){
	var pass=Get_Ckie("commlogp");
	var userid=Get_Ckie("commlogu");
	pass=strtrim(pass);
	userid=strtrim(userid);
	if(pass=="" || pass==null){}
	else{
		document.getElementById("passwd").value=pass
		document.getElementById("rememberpassword").checked=true;
	}
	if(userid=="" || userid==null){}
	else{
		document.getElementById("login").value=userid;
	}
}
function callAction(){document.loginform.submit();}
function callGo(){document.quickSearchForm.submit();}
function make_blank(){document.marketform.ticker1.value=""}
function hidepageoption(evt){
	if(window.event.srcElement.id=="pgarrow"){}
	else{
		if(Colordivstatus=="true"){
			hidediv("pageopt")
		}
	}
}
document.onclick = hidepageoption;
try{
	var sUser = getCookievalue('commlogu');
	var sPwd = getCookievalue('commlogp');
	if ((cookiestring.indexOf('commlogp') != -1) && (sPwd.length > 0 ) && (sPwd != 0 )){
		document.frmlog.Password.value=sPwd;
		document.frmlog.rememberpassword.checked = true;
	}
	if (sUser.length > 0 ){
		document.frmlog.User.value=sUser;
	}
}catch(er){}
 