/******************************************************************************
* tc_functions.js							      *
*                                                                             *
* Copyright 2005 by Indiantelevision.com				      *
* Visit http://www.indiantelevision.com					      *
*                                                                             *
* Provides functions for the website which will work on both Netscape	      *
* Communicator and Internet Explorer browsers (version 5.5 and up).  	      *
*									      *
******************************************************************************/
document.write('<link rel="shortcut icon" href="/favicon271208.ico" type="image/x-icon"/>');
document.write('<link rel="icon" href="/favicon271208.ico" type="image/x-icon"/>');

//-----------------------------------------------------------------------------
// Print Window Script
//-----------------------------------------------------------------------------

function printWindow(){
browserVersion = parseInt(navigator.appVersion)
if (browserVersion >= 4) window.print()
}

//-----------------------------------------------------------------------------
// Comment On Story Script
//-----------------------------------------------------------------------------

function get_coment() {
window.open('/comment_story/storycomment.php?story_prop='+document.title+'&story_link='+document.location,'comm','height=380 width=450,status=1,resizable=0,scrollbar=0 resizable=0')  
window.opener = self;
}

//-----------------------------------------------------------------------------
// Email Story Script
//-----------------------------------------------------------------------------

function get_path(){
str = location.pathname; 
window.open('/mailto/mail_friend.php?link='+str.substring(1),'comm','height=480 width=400,status=1,resizable=0,scrollbar=0 resizable=0')  
}

//-----------------------------------------------------------------------------
// Date Script
//-----------------------------------------------------------------------------

function current_date()
{
var day=new Array();
day[0]="Sunday";day[1]="Monday";day[2]="Tuesday";day[3]="Wednesday";day[4]="Thursday";day[5]="Friday";day[6]="Saturday";
var months=new Array(13);
months[0]="January";
months[1]="February";
months[2]="March";
months[3]="April";
months[4]="May";
months[5]="June";
months[6]="July";
months[7]="August";
months[8]="September";
months[9]="October";
months[10]="November";
months[11]="December";
var time=new Date();
var lmonth=months[time.getMonth()];
var tday=day[time.getDay()];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<table border='0' width='95%' height='0'><tr><td align='right'><b> <font color='#ffffff' face='tahoma' size=1>"+tday+" "+date+" "+lmonth+" "+year+"</font> </b></td></tr></table>");
}

//-----------------------------------------------------------------------------
// Footer Script
//-----------------------------------------------------------------------------

function footer()
{
	var my_date=new Date();
var cur_year = my_date.getFullYear();
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>");
document.write("<tr><td colspan='4'><HR color='red' size='2'></td></tr>");
document.write("<tr><td colspan='4' align='center'><a class='commentbold' href='/' target='_blank'>Home</a></td></tr>");
document.write("<tr><td colspan='4' height='5'></td></tr>");
document.write("<tr><td colspan='4' align='center'><a class='commentbold' href='javascript:get_path()'>Email this page</a> | ");
document.write("<a class='commentbold' href='javascript:printWindow()'>Print this page</a> | ");
document.write("<a class='commentbold' href='/archives-index.htm' target='_blank'>Archives</a> | ");
document.write("<a class='commentbold' href='/forum' target='_blank'>Forums</a>");
document.write("</div></td></tr>");
document.write("<tr><td colspan='4' height=5></td></tr>");
document.write("<tr><td colspan='4' align='center'><a class='commentbold' href='http://www.indiantelevision.com' target='_blank'>Indiantelevision.com</a></div></td></tr>");
document.write("<tr height='5'><td colspan='4' align='center'></td></tr>");
document.write("<tr><td colspan='4' align='center'>");
document.write("<font size='2' color='#666666'>Site best viewed in IE4 and above with resolution 800X600 Pixels");
document.write("<br>");
document.write("Copyright 2004-"+cur_year+" Indian Television Dot Com Pvt Ltd. All Rights Reserved.</font>");
document.write("</td></tr>");
document.write("</table><br>");
}

//-----------------------------------------------------------------------------
// Dynamic "Also Read:" script for all templates
//-----------------------------------------------------------------------------

function alsoread(val)
{

var display = "";
var a1 = "- <a class='alsoread' href='http://www.indiantelevision.com/special/boxpopuli/boxindex.htm' target='_blank'>Subhash Jha's Box Populi</a>";
var a2 = "- <a class='alsoread' href='http://www.indiantelevision.com/special/tellyscope/tscope_index.htm' target='_blank'>Telly Scope</a>";

if(val.indexOf("tab1") <0)
	display = display + a1;

if(val.indexOf("tab2") < 0)
	if (display.length>0)
		display = display + " <br> " + a2;
	else
		display = display + a2;	

document.write(display);
}

//-----------------------------------------------------------------------------
// Index Footer Script
//-----------------------------------------------------------------------------

function index_footer()
{

document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'><tr><td height=2 bgcolor='#333333' colspan='4'></td></tr>");
document.write("<tr><td colspan='4'>&nbsp;</td></tr>");
document.write("<tr><td colspan='4'> <div align='center'><a href='/index.htm' class=commentbold target='_blank' >Indiantelevision.com</a></div></td></tr>");
document.write("<tr><td colspan='4' height='5'></td></tr>");
document.write("<tr><td colspan='4'> <div align='center'><a href='javascript:get_path()' class=commentbold>Email this page</a> | ");
document.write("<a href='javascript:printWindow()' class=commentbold >Print this page</a> | ");
document.write("<a href='/archives-index.htm' class=commentbold target='_blank'>Archives</a> | ");
document.write("<a href='http://www.indiantelevision.com/special/boxpopuli/boxindex.htm' target='_blank' class='commentbold'>Subhash Jha`s Box Populi</a> | ");
document.write("<a href='mailto:editor@tellychakkar.com?subject=feedback on TC' target='_blank' class='commentbold'>Feedback</a>");
document.write("</div></td></tr>");
document.write("<tr><td colspan='4' height=5></td></tr>");
document.write("<tr><td colspan='4'><div align='center'><font color='#c0c0c0' size='2'>");
document.write("Site best viewed in IE4 and above with resolution 800X600 Pixels<br>");
document.write("Conceived, created and maintained by <a href='/index.htm'>Indiantelevision Dot Com Pvt. Ltd.</a><br>");
document.write("©Copyright 2003-2006 All rights reserved.<br>");
document.write("This site is hosted by <a href='http://www.aquariuswebhosting.com'>Aquarius Web Hosting Pvt. Ltd, India. </a><br>");
document.write("</font></td></tr>");
document.write("</table>");
}

//-----------------------------------------------------------------------------
// Archive Footer Script
//-----------------------------------------------------------------------------

function arc_footer()
{
document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>");
document.write("<tr><td colspan='4' align='center'><a class='commentbold' href='/' target='_blank' >Telly Chakkar Home</a> | ");
document.write("<a class='commentbold' href='javascript:get_path()'>Email this page</a> | ");
document.write("<a class='commentbold' href='javascript:printWindow()' >Print this page</a> | ");
document.write("<a class='commentbold' href='/archives-index.htm' target='_blank'>Archives</a> | ");
document.write("<a href='http://www.indiantelevision.com/special/boxpopuli/boxindex.htm' target='_blank' class='commentbold'>Subhash Jha`s Box Populi</a> | ");
document.write("<a class='commentbold' href='/forum' target='_blank'>Telly Chakkar Forums</a>");
document.write("</div></td></tr>");
document.write("<tr><td colspan='4' height=5></td></tr>");
document.write("<tr><td colspan='4' align='center'><a class='commentbold' href='/index.htm' target='_blank'>Indiantelevision.com</a></div></td></tr>");
document.write("</table><br>");
}


//-----------------------------------------------------------------------------
// blend Effect function -starts here
//-----------------------------------------------------------------------------

var imageholder=new Array()
var ie=document.all
var slidespeed=1000
var whichlink=0
var whichimage=0

function ImagePath(slideimages)
{

for (i=0;i<slideimages.length;i++)
{
	imageholder[i]=new Image()
	imageholder[i].src=slideimages[i]
}
}
function slideit()
{
	if (!document.images) return
	if (ie) document.images.slide.filters[0].apply()
		document.images.slide.src=imageholder[whichimage].src
	if (ie) document.images.slide.filters[0].play()
	whichlink=whichimage
	whichimage=(whichimage<slideimages.length-1)? whichimage+1 : 0

	setTimeout("slideit()",slidespeed+blenddelay)
}

//-----------------------------------------------------------------------------
// blend Effect function -ends here
//-----------------------------------------------------------------------------

//---------------------
//Multi Blend effect start here
//---------------------

function multiblend(imgarr,slideno)
{
document.write("<script language='text/javascript'>");
//document.write("var imageholder=new Array()");
document.write("var imageholder"+slideno+"=new Array()");
document.write("var ie=document.all");
document.write("var slidespeed=1000");
document.write("var whichlink=0");
document.write("var whichimage=0");


//document.write("function ImagePath(slideimages)");
document.write("function ImagePath"+slideno+"("+imgarr+")");
document.write("{");
//document.write("for (i=0;i<slideimages.length;i++)");
document.write("for (i=0;i<"+imgarr+".length;i++)");
document.write("{");
//document.write("	imageholder[i]=new Image()");
document.write("	imageholder"+slideno+"[i]=new Image()");
//document.write("	imageholder[i].src=slideimages[i]");
document.write("	imageholder"+slideno+"[i].src="+imgarr+"[i]");
document.write("}");
document.write("}");
//document.write("function slideit()");
document.write("function slideit"+slideno+"()");
document.write("{");
document.write("	if (!document.images) return");
//document.write("	if (ie) document.images.slide.filters[0].apply()");
document.write("	if (ie) document.images.slide"+slideno+".filters[0].apply()");
//document.write("		document.images.slide.src=imageholder[whichimage].src");
document.write("		document.images.slide"+slideno+".src=imageholder"+slideno+"[whichimage].src");
//document.write("	if (ie) document.images.slide.filters[0].play()");
document.write("	if (ie) document.images.slide"+slideno+".filters[0].play()");
//document.write("	whichlink=whichimage");
document.write("	whichlink=whichimage");
//document.write("	whichimage=(whichimage<slideimages.length-1)? whichimage+1 : 0");
document.write("	whichimage=(whichimage<slideimages"+slideno+".length-1)? whichimage+1 : 0");
//document.write("	setTimeout('slideit()',slidespeed+blenddelay)");
document.write("	setTimeout('slideit"+slideno+"()',slidespeed+blenddelay)");
document.write("}");
document.write("</script>");
}

//---------------------
//Multi Blend effect start here
//---------------------


//-----------------------------------------------------------------------------
// Disabling of Right Click on Images - starts here
//-----------------------------------------------------------------------------
var clickmessage='Copyright 2003-2006 Indian Television Dot Com Pvt Ltd  and/or its licensors. No use without permission. Contact enquiries@indiantelevision.com'
function disableclick(e) {
if (document.all) {
		if (event.button==2||event.button==3) {
		if (event.srcElement.tagName=='IMG'){
		alert(clickmessage);
		return false;
		}
		}
	} else if (document.layers) {
		if (e.which == 3) {
		alert(clickmessage);
		return false;
		}
	} else if (document.getElementById) {
		if (e.which==3&&e.target.tagName=='IMG'){
		alert(clickmessage)
		return false;
		}
		}
}
function associateimages() {
		for(i=0; i<document.images.length;i++) {
			document.images[i].onmousedown=disableclick;
		}
}
if (document.all) {
document.onmousedown=disableclick
} else if (document.getElementById) {
document.onmouseup=disableclick
} else if (document.layers) {
associateimages()
}


//-----------------------------------------------------------------------------
// Disabling of Right Click on Images - ends here
//-----------------------------------------------------------------------------

var locat='/images/ratings/rating.php?';

function rate(art,im)
{

	document.write("<table border='1' width='267' align='center' cellpadding='0' cellspacing='0'>");
	document.write("<tr bgcolor='#000000' align='center' bordercolor='#000000'>");
	document.write("<td height='24'><font face='Georgia, Times New Roman, Times, serif' size='5' color='#FFFFFF'>Rate This Show</font></td>");
	document.write("</tr>");

	document.write("<tr bgcolor='#000000' align='center' bordercolor='#000000'>");
	document.write("<td colspan='2'><img src='/images/ratings/wow.jpg' width='55' height='30' onclick='sub(1)' name='rate' value='1' style='cursor:hand;'><img src='/images/ratings/ho-hum.jpg' width='83' height='30' style='cursor:hand;' onclick='sub(2)'><img src='/images/ratings/ugh.jpg' width='60' height='30' style='cursor:hand;' onclick='sub(3)'><img src='/images/ratings/zzz.jpg' width='55' height='30' style='cursor:hand;' onclick='sub(4)'></td>");
	document.write("</tr>");
	document.write("</table>");
	locat='/images/ratings/rating.php?url='+art+'&im='+im;
	
}

function sub(x)
{
	locat=locat+'&rate='+x;
	window.open(locat,'hi', 'width=350,height=300,resizable=0,scrollbars=0');
}

//-----------------------------------------------------------------------------
// Get your friends to read Tellychakkar.com! -  Starts Here
//-----------------------------------------------------------------------------

function fnmail()
{
 document.writeln(" <table width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor='#FFFFFF' bordercolor='#000000'>");
document.writeln("<tr><td bgcolor='#FFFFFF'>");
document.writeln("<div align='center'><font size='1' face='Verdana, Arial, Helvetica, sans-serif'><b><font size='2' face='Arial, Helvetica, sans-serif' color='#CC0000'>");
document.writeln("Get your friends to read Tellychakkar.com!</font><font size='2' face='Arial, Helvetica, sans-serif' color='#003366'><br>");
document.writeln("</font></b><font size='2' face='Arial, Helvetica, sans-serif' color='#003366'>");
document.writeln("<font color='#000000'>Fill in 5 email addresses of people who you feel would like to read Telly Chakkar.</font><font color='#FF0000'>.</font></font></font></div>");
document.writeln("</td> </tr>");
document.writeln("<tr> <td ><br><font size='2' face='Arial, Helvetica, sans-serif' color='#003366'>");
document.writeln("<form name='form1' >");
document.writeln("&nbsp;Your Email:&nbsp;<input type='text' name='email' size='20'>&nbsp;&nbsp;&nbsp;&nbsp;Feedback:&nbsp;<input type='text' name='feedback' size='40'><BR><font size='-4'>&nbsp;</font><br>Referred Emails :- <br>");
document.writeln("<input type='text' name='email1' size='15'><input type='text' name='email2' size='15'><input type='text' name='email3' size='15'><input type='text' name='email4' size='15'><input type='text' name='email5' size='15'><input type='button' name='Submit' value='Ok' onclick='thanks()'>");
document.writeln(" </font></form>");
document.writeln("</td></tr>");
document.writeln("</table>");
}

function thanks()
{
	var txt=document.all.form1;
	loc="/js/confirm.php?feedback="+txt.feedback.value+"&email="+txt.email.value+"&email1="+txt.email1.value+"&email2="+txt.email2.value+"&email3="+txt.email3.value+"&email4="+txt.email4.value+"&email5="+txt.email5.value;

	window.open(loc,'hi', 'width=600,height=20,resizable=0,scrollbars=0');
}

//-----------------------------------------------------------------------------
// Get your friends to read Tellychakkar.com! -  Ends Here
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Email check functions starts here
//-----------------------------------------------------------------------------

function emailCheck (emailStr) { 
   
	var checkTLD=1;
        var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
        var emailPat=/^(.+)@(.+)$/;
        var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
        var validChars="\[^\\s" + specialChars + "\]";
        var quotedUser="(\"[^\"]*\")";
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
        var atom=validChars + '+';
        var word="(" + atom + "|" + quotedUser + ")";
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
        var matchArray=emailStr.match(emailPat);
        if (matchArray==null) {
                return "Email address is invalid";
                //return ;
        }

        var user=matchArray[1];
        var domain=matchArray[2];
        for (i=0; i<user.length; i++) {
                if (user.charCodeAt(i)>127) {
                        return "Ths username contains invalid characters.";
                        //return ;
                   }
        }
        for (i=0; i<domain.length; i++) {
                if (domain.charCodeAt(i)>127) {
                        return "Ths domain name contains invalid characters.";
                        //return ;
                  }
        }
        if (user.match(userPat)==null) {
                return "The username doesn't seem to be valid.";
                //return ;
        }
        var IPArray=domain.match(ipDomainPat);
        if (IPArray!=null) {
                for (var i=1;i<=4;i++) {
                        if (IPArray[i]>255) {
                                return "Destination IP address is invalid!";
                                //return ;
                         }
                }
                return "Valid";
        }
        var atomPat=new RegExp("^" + atom + "$");
        var domArr=domain.split(".");
        var len=domArr.length;
        for (i=0;i<len;i++) {
                if (domArr[i].search(atomPat)==-1) {
                        return "The domain name does not seem to be valid.";
                        //return ;
                 }
        }

        if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
                return "The address must end in a well-known domain or two letter " + "country.";
                //return ;
        }

        if (len<2) {
                return "This address is missing a hostname!";
                //return ;
        }
        return "Valid";
}

	function download1(val)
	{
		if(val!="")
		{
			location.href=val;
		}	
	} 
	
	function openUrl(url,id)
	{
		if(screen.width==1024)
		{
			window.open(url+"?id="+id+"&size=large","Viewer","width=800,height=600,status=1,menubar=yes,title=yes,toolbar=yes,resizable=1,scrollbars=yes");
		}
		else
		{
			window.open(url+"?id="+id+"&size=small","Viewer","width=800,height=600,status=1,menubar=yes,title=yes,toolbar=yes,resizable=1,scrollbars=yes");
		}
		
	}
//-----------------------------------------------------------------------------
// Email check functions ends here
//-----------------------------------------------------------------------------


function openEmailPop(e,id,cat,divid1,divid2,frameid,framename)
{
	posx = 0; posy = 0; 
	if (!e){var e = window.event;} 
	if (e.pageX || e.pageY){ 
	posx = e.pageX; 
	posy = e.pageY; 
	} 
	else if (e.clientX || e.clientY){ 
	posx = e.clientX; 
	posy = e.clientY; 
	} 
	//alert("Scren :"+e.screenX+' '+e.screenY+"\nPage :"+e.pageX+' '+e.pageY+"\nClent :"+e.clientX+' '+e.clientY+"\nOffsetr :"+e.offsetX+' '+e.offsetY+"\nxy :"+e.x+' '+e.y+"\nDocumet"+document.width+" "+document.height);
	if((posx+500)>screen.width)
	{
		posx=screen.width-500;
	}
	if((posy+document.body.scrollTop+500)>e.screenX)
	{
		posy=screen.height-500;
	}
	
	document.getElementById(divid2).style.top=10+document.body.scrollTop;
	document.getElementById(divid2).style.left=254;
	document.getElementById(divid2).style.position="absolute";
	
	if(document.all)
	{
		var object = document.getElementById(divid1).style; 
		object.opacity = 10;
		object.MozOpacity = 10;
		object.KhtmlOpacity = 10;
		object.filter = "alpha(opacity=" + 10 + ")";
		document.getElementById(frameid).src="../generic/components/emailed/com.emailed.php?contentid="+id+"&category="+cat+"&type=wallpaper&displayType=popup";
		
	}
	else
	{
		var object = document.getElementById(divid1);
		object.style.MozOpacity = 0.10;
		document.getElementById(frameid).src="../generic/components/emailed/com.emailed.php?contentid="+id+"&category="+cat+"&type=wallpaper&displayType=popup";	
		
	}
	
	document.getElementById(divid2).style.display="block";
	
}
function closeEmailPop(divid1,divid2,frameid,framename)
{
	
	document.getElementById(divid2).style.display="none";
	var object = document.getElementById(divid1).style; 
	object.opacity = 100;
	object.MozOpacity = 100;
	object.KhtmlOpacity = 100;
	object.filter = "alpha(opacity=" + 100 + ")";
	
	var object = document.getElementById(divid2).style; 
	object.opacity = 100;
	object.MozOpacity = 100;
	object.KhtmlOpacity = 100;
	object.filter = "alpha(opacity=" + 100 + ")";
	if(document.all)
	{
		document.getElementById(framename).src="about:blank";
	}
	else
	{
		document.getElementById(frameid).src="about:blank";	
	}
		
	
}
function openEmailBlank(id,cat)
{
	window.open("../generic/components/emailed/com.emailed.php?contentid="+id+"&category="+cat+"&type=wallpaper&displayType=blank","EmailPage","width=520,height=580,status=1,menubar=no,title=yes,toolbar=no,resizable=0,scrollbars=yes");
}

function textCounter(field,cntfield,maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
 		field.value = field.value.substring(0, maxlimit);
 	else
 		cntfield.value = maxlimit - field.value.length;
}
