//alert("inside");
//For HTML includes validation
// -----------------------------------------------------------------------------
// Globals
//This value will not be empty if the page is called from the top navigation 
var selheadersection = "";
//This value will not be empty if the page is called from the left navigation
var selleftnavsection = "";
//This value will not be empty if the page is called from the right navigation
var selrightnavsection = "";
//This value will not be empty if the page is called from the games
var selgamesrightnavsection = "";
// -----------------------------------------------------------------------------

//For Video and Audio Link
// -----------------------------------------------------------------------------
//This value should not be empty if there is a Download Video link within the parent page
var nvideo_link = "";
//This value should not be empty if there is a Download Audio link within the parent page
var naudio_link = "";
// -----------------------------------------------------------------------------

//For Flash detection
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------

//For AU Promotions
// -----------------------------------------------------------------------------
// Globals
var gpromo_ctycode = "";
var gpromo_code = "";

//Flash sizes
// -----------------------------------------------------------------------------
//For homepage flash
var homepage_fwidth = 460;
var homepage_fheight = 437;

//For Champions Selection flash
var cselection_fwidth = 150;
var cselection_fheight = 347;

//For Champions Main Page flash
var champ_large_fwidth = 162;
var champ_large_fheight = 347;
var champ_small_fwidth = 110;
var champ_small_fheight = 236;

//For Champions Sub Page
var vother_champions_fwidth = 115;
var vother_champions_fheight = 115;
var vmain_champion_fwidth = 121;
var vmain_champion_fheight = 320;

//For Champions Game
var vgame_fwidth = 898;
var vgame_fheight = 430;

//For Mach3 Turbo Window size
var m3t_width = 800;
var m3t_height = 500;


// -----------------------------------------------------------------------------

//Flash sizes
// -----------------------------------------------------------------------------
var vmouseover_color = "#F96242";
var vmouseout_color = "#FFFFFF";
// -----------------------------------------------------------------------------

//2 Col List Counters
// -----------------------------------------------------------------------------
var leftcolstart = 1;
var rightcolstart = 0;
// -----------------------------------------------------------------------------

var glocale = "";
var downloadcomments = "<p class='small'>*&Eacute; necess&aacute;rio software Winzip/WinRAR para descompactar os v&iacute;deos.</p>";

/*Start: Google Analytics*/

/*----------Start: To add google-analytics javascript file to page----------*/
var headID = document.getElementsByTagName("head")[0]; 
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
//newScript.onload=fgooglevar;
newScript.src = 'http://www.google-analytics.com/urchin.js';
headID.appendChild(newScript);
/*----------End: To add google-analytics javascript file to page----------*/

/*----------Start: To add google-analytics tracking code----------*/
function fgooglevar()
{
	var vlocation = window.location.href;
	if(vlocation.search(/en_th/) != -1 || vlocation.search(/en_my/) != -1 || vlocation.search(/en_in/) != -1)
	{
		//alert("IN | MY | TH");
		_uacct = "UA-2043740-5"; 
		_userv=2;
		urchinTracker();
	}
	else
	{
		//alert("SG | AU");
		_uacct = "UA-2043740-4";
		urchinTracker();
		_uff = 0;
		_userv=2;
		_uacct = "UA-2043740-5";
		urchinTracker();
	}
	
	
	//alert(_uacct);
}
/*----------End: To add google-analytics tracking code----------*/

/*End: Google Analytics*/



/*----------Start: Browser Detect----------*/
function BrowserDetectLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;

	// browser name
	this.isGecko     = (ua.indexOf('gecko') != -1);
	this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
	this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera     = (ua.indexOf("opera") != -1); 
	this.isKonqueror = (ua.indexOf("konqueror") != -1); 
	this.isIcab      = (ua.indexOf("icab") != -1); 
	this.isAol       = (ua.indexOf("aol") != -1); 
	this.isWebtv     = (ua.indexOf("webtv") != -1); 
	this.isOmniweb   = (ua.indexOf("omniweb") != -1);
	this.isDreamcast   = (ua.indexOf("dreamcast") != -1);
	
	// spoofing and compatible browsers
	this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
	this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);
	
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number for NS6+ 
	if (this.isNS && this.isGecko) {
		this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
	}
	
	// correct version number for IE4+ 
	else if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	
	// correct version number for Opera 
	else if (this.isOpera) {
		if (ua.indexOf('opera/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
		}
	}
	
	// correct version number for Konqueror
	else if (this.isKonqueror) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
	}
	
	// correct version number for iCab 
	else if (this.isIcab) {
		if (ua.indexOf('icab/') != -1) {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
		}
		else {
			this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
		}
	}
	
	// correct version number for WebTV
	else if (this.isWebtv) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('webtv/') + 6 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
	
	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);
	this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('linux') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
	
	// specific browser shortcuts
	this.isNS4x = (this.isNS && this.versionMajor == 4);
	this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
	this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
	this.isNS4up = (this.isNS && this.versionMinor >= 4);
	this.isNS6x = (this.isNS && this.versionMajor == 6);
	this.isNS6up = (this.isNS && this.versionMajor >= 6);
	
	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();
/*----------End: Browser Detect----------*/

function changecss(theClass,element,value) 
{
	var cssRules;
	if (document.all) 
	{
		cssRules = 'rules';
	}
	else if (document.getElementById) 
	{
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++)
	{
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) 
		{
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) 
			{
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
	  	}
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*----------Start: Search Object----------*/
function returnObjById( id ) 
{ 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}

function returnObjByName( name ) 
{ 
    if (document.getElementsByName) 
        var returnVar = document.getElementsByName(name); 
    else if (document.all) 
        var returnVar = document.all[name]; 
    else if (document.layers) 
        var returnVar = document.layers[name]; 
    return returnVar; 
}
/*----------End: Search Object----------*/

//To show html page within IFRAME and at the same time change the selected link to the currently selected link
// -----------------------------------------------------------------------------
function fdisplay_content(nmenuitemname, nmenuitemno, ntotallinks, ntargetfile,framename)
{
	var vselectedid = nmenuitemname + nmenuitemno;
	var vclick_url = "";
	var vlinkobj = returnObjById(vselectedid);
	var vmenuitemno = nmenuitemno - 1;
	if(vlinkobj.className == "subnav_links")
	{
		var vtargetfile = ntargetfile + nmenuitemno + ".html";
		frefresh_frame(framename,vtargetfile);
		vlinkobj.className = "subnav_selected";
		vlinkobj.style.color = vmouseover_color;
		for (var i=0; i<ntotallinks; i++)
		{
			if(i != vmenuitemno)
			{
				vselectedid = nmenuitemname + eval(i+1);
				vlinkobj = returnObjById(vselectedid);
				vlinkobj.className = "subnav_links";
				vlinkobj.style.color = vmouseout_color;
			}
		}
	}
}

function link_mouseover(nid)
{
	var vlinkobj = returnObjById(nid);
	if(vlinkobj.className == "subnav_links")
	{
		vlinkobj.style.color =  vmouseover_color;
	}
}

function link_mouseout(nid)
{
	var vlinkobj = returnObjById(nid);
	if(vlinkobj.className == "subnav_links")
	{
		vlinkobj.style.color = vmouseout_color;
	}
}

function frefresh_frame(nframe,nurl)
{
	var viframe = returnObjById(nframe);
	viframe.src = nurl;
}

// -----------------------------------------------------------------------------

//To clear the global variables values so that it is reset when the next page is generated
// -----------------------------------------------------------------------------
function fclearglobalvar()
{
	selheadersection = "";
	selleftnavsection = "";
	selrightnavsection = "";
	fchangeheaderbg();
	famendcss();
	fgooglevar();
}

// -----------------------------------------------------------------------------

function famendcss()
{
	if(browser.isIE)
	{
		changecss('.radiolabel','position','relative');
		changecss('.radiolabel','top','3px');
		changecss('.radiolabel','left','0px');
		if(browser.isIE6x)
		{
			changecss('#container #content #contentarea #promo_reg_left .potherslayout LABEL','margin','2px 8px 2px 0px');
		}
		
	}
	else
	{
		changecss('.radiolabel','position','relative');
		changecss('.radiolabel','top','0');
		changecss('.radiolabel','left','2px');
		changecss('form input[type="radio"]','position','relative');
		changecss('form input[type="radio"]','top','1px');
		changecss('form input[type="checkbox"]','position','relative');
		changecss('form input[type="checkbox"]','top','3px');
	}
}

function fchangeheaderbg()
{
	var vIsChampions = 0;
	var vIsWinners = 0;
	var vdoc_title = document.title;
	vdoc_title = vdoc_title.toLowerCase();
	vIsChampions = vdoc_title.indexOf('champions',0);
	vIsWinners = vdoc_title.indexOf('winners',0);
	if(vIsChampions > 0)
	{
		//alert("Is a Champions Site");
		changecss('#container #content #header','backgroundImage','url(../images/home_04.jpg)');
	}
	else if(vIsWinners > 0)
	{
		//alert("Is a Winners Site");
		changecss('#container #content #header','backgroundImage','url(../images/home_04.jpg)');
	}
	else
	{
		//alert("Is a Others Site");
		changecss('#container #content #header','backgroundImage','url(../images/home_04.jpg)');
	}
}

//To pass the values from the iframe details page to the parent page
// -----------------------------------------------------------------------------
function fdownloadlinks(varVideo, varAudio) { 
	nvideo_link = varVideo;
	naudio_link = varAudio;
	
	var myiframe = document.getElementById("frame_content"); // the iframe element 
	var iwindow = myiframe.contentWindow; // the iframe's window object. 
	iwindow.fgooglevar();
	/*iwindow.include_dom("../../../standard/en_sg/includes/test.js");
	if(browser.isIE == false)
	{
		iwindow.document.write('<script type="text/javascript"> testvar = "UA-2043740-5-1"; urchinTracker(); </script>')
	}*/
} 
// -----------------------------------------------------------------------------

//To download the appropriate audio/video file when the Download Video/Download Audio button is clicked
// -----------------------------------------------------------------------------
function fdownload(nlink)
{
	if(nlink != "")
	{	
		if(nlink.search(/.zip/) != -1)
		{
			if(nlink.search(/Tiger/) != -1)
			{
				urchinTracker('/tw_interview/Downloads/Video');
			}
			else if(nlink.search(/Henry/) != -1) 
			{
				urchinTracker('/th_interview/Downloads/Video');
			}
			else if(nlink.search(/Federer/) != -1) 
			{
				urchinTracker('/rf_interview/Downloads/Video');
			}
			else if(nlink.search(/Rahul/) != -1) 
			{
				urchinTracker('/rd_interview/Downloads/Video');
			}
		}
		if(nlink.search(/.mp3/) != -1)
		{
			//alert(nlink.search(/.mp3/));
			if(nlink.search(/Tiger/) != -1)
			{
				urchinTracker('/tw_interview/Downloads/Audio');
			}
			else if(nlink.search(/Henry/) != -1) 
			{
				urchinTracker('/th_interview/Downloads/Audio');
			}
			else if(nlink.search(/Federer/) != -1) 
			{
				urchinTracker('/rf_interview/Downloads/Audio');
			}
			else if(nlink.search(/Rahul/) != -1) 
			{
				urchinTracker('/rd_interview/Downloads/Audio');
			}
		}
		window.location.href = nlink;
	}
	
}
// -----------------------------------------------------------------------------

function PopupWindow_WName(theURL,nwidth,nheight,nwinname) {
	
	var windowprops = "width="+nwidth+", height="+nheight+", location=no, toolbar=no, menubar=no, scrollbars=no, resizable=no";
	popup = window.open(theURL,nwinname,windowprops);
	popup.focus();
}

function fsplitlist(rowcount)
{
	var vsplit = parseFloat(rowcount) / 2
	var vsplitstr = vsplit.toString()
	var vsplitInt = parseInt(vsplitstr);
	if(vsplitstr.indexOf(".") == 1)
	{
		rightcolstart = vsplitstr.substring(0, vsplitstr.indexOf("."))
		rightcolstart = parseInt(rightcolstart) + 2;
	}
	else
	{
		rightcolstart = parseInt(vsplitInt) + 1;
		
	}
}

/************************Start: Form Validations************************/

var gemail_errmsg = "Sorry, the email format is not acceptable. Please try again.";

/*----------Start: Email Address Validation----------*/
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
//alert("Email address seems incorrect (check @ and .'s)");
return false;
}

var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}

for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 
if (user.match(userPat)==null) {

// user is not valid
//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's 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) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}
/*----------End: Email Address Validation----------*/

/*----------Start: Function to left trim and right trim empty spaces in a string ----------*/
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};
/*----------End: Function to left trim and right trim empty spaces in a string ----------*/


function checktxtblank(nfield,nmessage,nstring,nseperator)
{
	var verror_fields = "";
	
	if(nfield.value == "")
	{
		verror_fields = nstring + nseperator + nmessage;
	}
	else
	{
		verror_fields = nstring;
	}
	return verror_fields;
}

function fcheckemail(nobj)
{
	var nvalid = "false";
	if(nobj.value != "")
	{
		nvalid = emailCheck(nobj.value);
		if(nvalid == false)
		{
			alert(gemail_errmsg);
			nobj.focus();
		}
	}
}

function fcheckemailval(nobj)
{
	var nvalid = "false";
	var nerrmsg = ""; 
	if(nobj != "")
	{
		nvalid = emailCheck(nobj);
		if(nvalid == false)
		{
			nerrmsg = gemail_errmsg;
			return nerrmsg;
		}
	}
	return nerrmsg;
}

function femailcheck(nobj)
{
	var verror_fields = fcheckemailval(nobj.value);
	if(verror_fields != "")
	{
		verror_fields = "<div id='verr_msg'>"+verror_fields+"</div>";
		showPopWin('error_msg.html', nobj, verror_fields, 487, 340, null)
	}
}


/*----------Start: Function to retrieve a querystring value----------*/
function GetQueryStringVal(param)
{
	var q = document.location.search || document.location.hash;
	if(q)
	{
		var startIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
		if (q.length > 1 && startIndex > -1) 
		{
			return q.substring(q.indexOf("=", startIndex)+1, endIndex);
		}
	}
	return "";
}


/************************End: Form Validations************************/

