
	var updated=0;

	//loadDimsMovie();

function open_win(url,winName,features) 
{
        window.open(url,winName,features);
}

function isdefined(object, variable)
{
	return (typeof(eval(object)[variable]) != "undefined");
	
}

function loadDimsMovie()
{
	var rand_no = Math.random();
	rand_no = rand_no * 10000;

/*
	var flashvars = {
        };

	var params = {wmode:"transparent"};
	var attributes = { id:"dimmovie", name:"dimmovie"};
        //swfobject.embedSWF("HeaderText.swf?r="+rand_no, "onepixel", "1", "1", "9.0.48","expressInstall.swf", flashvars, params, attributes);
        swfobject.embedSWF("textDimensions.swf", "onepixel", "1", "1", "9.0.48","expressInstall.swf", flashvars, params, attributes);
	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	if (isIE6)
	{
		supersleight.run();
	}
	//setTimeout('updateHeaders()',3000);
	if (document.getElementById('ticker'))
	{
		var flashvars = { };

		var params = {wmode:"transparent"};
		var attributes = { id:"tickermovie", name:"tickermovie"};
		//swfobject.embedSWF("TickerLoader.swf?r="+rand_no, "ticker", "785", "34", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF("TickerLoader.swf", "ticker", "785", "34", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	}
*/

	//updateHeaders();
}

function enter(p_panel)
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('enterPane', 'ajax/enter.php?panel='+p_panel+'&rand='+myRand);
}

function auditionApplication(p_panel)
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('enterPane', 'ajax/auditionform.php?rand='+myRand);
}

function mobileSubmit()
{   
    if (document.mobileForm.name.value.length==0)
    {
        alert("You must enter your name");
    }
    else
    if (! isValidEmail(document.mobileForm.email.value,true)) {
        alert("You must enter a valid email address");
    }
    else
    if (document.mobileForm.number.value.length==0)
    {
        alert("You must enter your phone number");
    }   
    else
    if (document.mobileForm.make.value.length==0)
    {
        alert("You must enter your make of phone");
    }   
    else
    if (document.mobileForm.model.value.length==0)
    {
        alert("You must enter a mobile phone model");
    }
    else
    {   
        document.mobileForm.submit();
    }

}

function auditionSubmit()
{
    if (document.auditionForm.user_name.value.length==0)
    {
        alert("You must enter your Name.");
    }
    else
    if (document.auditionForm.address.value.length==0)
    {
        alert("You must enter your Address.");
    }
    else
    if (! isValidEmail(document.auditionForm.email.value,true)) {
        alert("You must enter a valid email address.");
    }
    else
    if (document.auditionForm.day_phone.value.length==0)
    {
        alert("You must enter a daytime phone number.");
    }
    else
    if (document.auditionForm.eve_phone.value.length==0)
    {
        alert("You must enter an evening phone number.");
    }
    else
    if (document.auditionForm.mobile_phone.value.length==0)
    {
        alert("You must enter a mobile phone number.");
    }
    else
    if (document.auditionForm.occupation.value.length==0)
    {
        alert("You must enter an occupation.");
    }
    else
    if (document.auditionForm.biography.value.length==0)
    {
        alert("You must tell us why you'd make a great contestant!");
    }
    else
    if (document.auditionForm.privacycheckbox.checked==false)
    {
        alert("You must accept the ITV Privacy Policy.");
    }
    else
    if (document.auditionForm.rulescheckbox.checked==false)
    {
        alert("You must accept the Rules.");
    }
    else
    {
	document.auditionForm.submit();
	//HTML_AJAX.formSubmit('auditionForm','target');
	//window.location="#";
    }
}

function enter2(p_panel)
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('enterPane', 'ajax/enter2.php?panel='+p_panel+'&rand='+myRand);
}

function winners()
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('winnersPane', 'ajax/winners.php?rand='+myRand);
}

function openRulesPanel()
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('rulesLinks', 'ajax/rules_links.php?rand='+myRand);
}

function openRulesPanel2()
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('rulesLinks', 'ajax/rules_links2.php?rand='+myRand);
}

function openTVPane(p_pane)
{
	if (!updated)
		updateHeaders();

        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace('tvPane', 'ajax/tvshow.php?panel='+p_pane+'&rand='+myRand);
	window.location='#';
}

function closePanel(p_id)
{
        myRand=parseInt(Math.random()*99999999);
        HTML_AJAX.replace(p_id, 'ajax/blank.php?rand='+myRand);
}

function updateHeaders()
{
	var rand_no = Math.random();
	rand_no = rand_no * 10000;

	updated=1;

	if (document.getElementById('ontheshow'))
	{
		flashText('ontheshow', 'Do You Want To Be On\nThe Show?',24);
	}

	if (document.getElementById('viewergame'))
	{
		flashText('viewergame', 'Viewer Game',24);
	}

	if (document.getElementById('latestWinners'))
	{
		flashText('latestWinners', 'Latest winners',23);
	}

	if (document.getElementById('viewergame2'))
	{
		flashText('viewergame2', 'Viewer Game',26);
	}

	if (document.getElementById('contact'))
	{
		flashText('contact', 'Contact',26);
	}

	if (document.getElementById('congrats'))
	{
		flashText('congrats', 'Congratulations to our latest winners...',25);
	}

	if (document.getElementById('internetfaqtitle'))
	{
		flashText('internetfaqtitle', 'INTERNET ENTRY FAQS',25);
	}

	if (document.getElementById('smsfaqtitle'))
	{
		flashText('smsfaqtitle', 'SMS ENTRY FAQS',25);
	}

	if (document.getElementById('tvshowbox1title'))
	{
		flashText('tvshowbox1title', 'Who Wants To Be A Millionaire?\nCelebrity',23);
	}

	if (document.getElementById('tvshowbox2title'))
	{
		flashText('tvshowbox2title', 'Did you know?',23);
	}

	if (document.getElementById('aboutcttitle'))
	{
		flashText('aboutcttitle', 'About Chris Tarrant',23);
	}

	if (document.getElementById('aroundTheWorld'))
	{
		flashText('aroundTheWorld', 'Around the world',23);
	}

	if (document.getElementById('enterInternettitle'))
	{
		flashText('enterInternettitle', 'Enter via Internet',23);
	}

	if (document.getElementById('enterSMStitle'))
	{
		flashText('enterSMStitle', 'Enter via SMS',23);
	}

	if (document.getElementById('gluPromoTitle'))
	{
		flashText('gluPromoTitle', 'Win A Free Mobile Game Download!',23);
	}

	if (document.getElementById('wrongAnswer'))
	{
		flashText('wrongAnswer', 'Wrong answer',23);
	}

	if (document.getElementById('correctAnswer'))
	{
		flashText('correctAnswer', 'Correct Answer - please enter your details:',23);
	}

        if (document.getElementById('thanksPrizeDraw'))
        {
                flashText('thanksPrizeDraw', 'Thanks for entering the prize draw. We will notify you if you are a winner. Good luck!',23);
        }

        if (document.getElementById('recordingChange'))
        {
                flashText('recordingChange', 'Change to Millionaire Recording Dates',23);
        }
}

function setFlashTextColour(p_id,p_color)
{
	var movie=document.getElementById(p_id+'movie');
	if (movie)
	{
		movie.setFlashTextColour(p_color);
	}
}

function flashText(p_id, p_text,p_size)
{
	var dims=getFlashTextDimensions(p_text,p_size);

	var width=dims.width;
	var height=dims.height;

	var flashvars = {
        header_text: p_text,
        text_size: p_size,
        text_colour: 0xffffff
        };

	var rand_no = Math.random();
	rand_no = rand_no * 10000;

	//alert(document.getElementById(p_id));

	var id=p_id+'movie';
	var params = {wmode:"transparent"};
	var attributes = {id:id, name:id};

	//swfobject.embedSWF("HeaderText.swf?r="+rand_no, p_id, width, height, "9.0.48","expressInstall.swf", flashvars, params, attributes);
	swfobject.embedSWF("HeaderText.swf", p_id, width, height, "9.0.48","expressInstall.swf", flashvars, params, attributes);
//alert(p_id);
}


function getFlashTextDimensions(p_text,p_size)
{
        var movie = document.getElementById('dimmovie');
	//alert(movie);
        //thisMovie('jackpotmovie');
        if (movie)
        {
                var dims = movie.getFlashTextDimensions(p_text,p_size);
                //alert('width:'+movie.getFlashTextDimensions(p_text,p_size).width+' height:'+movie.getFlashTextDimensions(p_text,p_size).height);
                return(movie.getFlashTextDimensions(p_text,p_size));
        }

}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.lastIndexOf("@")!=email.indexOf("@")) { // only one @ allowed
        return false;
    } else if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.lastIndexOf(".")+2 > email.length-1) {  // 2 or more letters after the last dot
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
        return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
        return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

