try{ var _gpn=document.location.href.match(new RegExp("\/([^\/\?\.]*)\.htm"))[1]; } catch(peein){ var _gpn='index'; }
if (_gpn==""){_gpn="index";}
var _gmlc="/TVPlex/LiveWithRegisKelly_redesign";
var _gacct="DM510312C3MA38EN3;DM51030813MR38EN3;DM5103083LCA38EN3";

//find query attached
var pageLoc = String(document.location);
var queryPos = pageLoc.indexOf("?");
var queryString = (queryPos < 0) ? "" : pageLoc.substring(queryPos);

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}

//action tag
function actionTag(page){
	var actionLoad = 'http://switch.atdmt.com/action/';
	document.action_tag.src = actionLoad + page;
}

//get date MM-DD-YYYY
function formatToday(today){
var vDays=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var vMonths=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
offset=(today.toString().match(/(DT|Daylight|700)/gi)!=null)?7:8;

outdate=vDays[today.getDay()] + " " + vMonths[today.getMonth()] + " " + today.getDate() + " " + today.getHours()+":"+addZero(today.getMinutes())+":"+addZero(today.getSeconds())+" GMT-0"+offset+"00 "+today.getFullYear();
alert(outdate);
return outdate;

}

function store(){ window.open('http://www.shopwithregisandkelly.com'); }

function popup( url, w, h, windowName, r, s ) {
	win = window.open(url, windowName, 'height=' +h+ ', width=' +w+ ', resizable=' +r+ ', status=no, scrollbars=' +s+ ', location=no, menubar=no, toolbar=no, left=50, top=50');
}

function popRecipe(page){
	popup('recipes/'+page, 500, 400, 'recipe', 1, 1);
}

function popRecipeImage(page, hv){ //pass me h or v
	if (hv == 'h'){
		width = 450;
		height = 375;
	}
	else{
		width = 350;
		height = 475;
	}
	popup('recipes/'+page, width, height, 'recipeimage', 1, 1);
}

function popHostChatPlayer(video_id){
	if (video_id) var deeplink = '?video_id='+video_id;
	else var deeplink = '';
	popup('video_archive_player.html'+deeplink, 600, 380, 'hostchat', 0, 0);
}

function closeMe(){
	window.close();
}

function goPage(form) {
	if ((form.options[form.selectedIndex].value) != "-"){
		goToURL = form.options[form.selectedIndex].value;
		document.location = goToURL;
	}
}

//wallpapers - pass me the number and width
//wallpaper(2, 800);
function wallpaper(number, width){
	popup('wallpaper.html?number='+number+'&width='+width, 700, 500, 'wallpaper', 'no', 'yes');
	//will pop wallpaper.html with image passed dynamically - image must be images/wallpapers/(width)_#.jpg
	//example: images/wallpapers/1024_1.jpg
}

//screensaver - pass me the os (win or osx)
//screensaver('win');
function screensaver(os){
	switch(os){
		case 'win': //windows
			popup('download_file.html?file=download/LiveRegisKelly_pc.exe.zip', 300, 250, 'download', 'no', 'no');//sp2 fix
			break;
		case 'osx': //osx
			popup('download_file.html?file=download/LiveRegisKelly_osx.sit', 300, 250, 'download', 'no', 'no');//sp2 fix
			break;
		default:
			break;
	}
}

//buddy icons
function buddyIcons(){
	popup('buddyicons.html', 468, 500, 'icons', 'no', 'no')
}

// browser and os detect
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('safari')) browser = "safari"
else if (checkIt('msie')) browser = "msie"
else if (!checkIt('compatible')) browser = "ns"
else browser = "unknown";

if (checkIt('windows')) os = "pc"
else if (checkIt('mac')) os = "mac"
else os = "unknown";

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

//buddy icons
function buddyIcon(icon){
    var pagePath = "" + window.location;
    var pageRoot = pagePath.substring(0,pagePath.lastIndexOf("/")+1) + "images/aimicons/";
	var iconUrl = "aim:BuddyIcon?src="+pageRoot+icon;
	//var iconUrl = pageRoot+icon;
	if (os == 'pc')
		document.location = iconUrl;
	else alert ('This is a PC feature only.  Please click "Download Full Set".');
}

//download - pass me the file
//download('aimicons/icons.zip');
function download(file){
	popup('download_file.html?file='+file, 300, 250, 'download', 'no', 'no');//sp2 fix
	//alert(file);//test
}

//form validation
function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isFieldEmpty(string) {
	if ((string != "") && (string != null)) // just check that it's not empty
        return true;
    else
        return false;
}

function isFieldProper(string) {
    if (string.search(/^\w+( \w+)?$/) != -1) // check for illegal characters
        return true;
    else
        return false;
}

function validate(page, form){
	var listerrors = "";
	
	//tickets
	if (page == 'tickets'){
		if (isFieldEmpty(form.name.value) == false) {
			listerrors += "- Name\n";
		}
		if (isFieldEmpty(form.address.value) == false) {
	        listerrors += "- Address\n";
	    }
		if (isFieldEmpty(form.city.value) == false) {
	        listerrors += "- City\n";
	    }
		if (form.state.value == '-') {
			listerrors += "- State\n";
		}
		if (isFieldEmpty(form.zip.value) == false) {
			listerrors += "- Zip Code\n";
		}
		if (isFieldEmpty(form.email.value) == false) {
			listerrors += "- Email Address\n";
		}
		else if (isEmail(form.email.value) == false) {
			listerrors += "- Email Address must be valid\n";
		}
		if (isFieldEmpty(form.phone.value) == false) {
			listerrors += "- Phone Number\n";
		}
		if ( (form.mo1.value == '-') || (form.day1.value == '-') || (form.yr1.value == '-')) {
			listerrors += "- First Choice\n";
		}
		if ( (form.mo2.value == '-') || (form.day2.value == '-') || (form.yr2.value == '-')) {
			listerrors += "- Second Choice\n";
		}
		if ( (form.mo3.value == '-') || (form.day3.value == '-') || (form.yr3.value == '-')) {
			listerrors += "- Third Choice\n";
		}
		if (form.ticket_amt.value == '-') {
			listerrors += "- Number of Tickets\n";
		}
	}
	//guest
	else if (page == 'guest'){
		if (isFieldEmpty(form.guest_requested.value) == false) {
			listerrors += "- Who would you like to see?\n";
		}
	}
	//showidea
	else if (page == 'showidea'){
		if (isFieldEmpty(form.name.value) == false) {
			listerrors += "- Name\n";
		}
		if (isFieldEmpty(form.email.value) == false) {
			listerrors += "- Email Address\n";
		}
		else if (isEmail(form.email.value) == false) {
			listerrors += "- Email Address must be valid\n";
		}
		if (isFieldEmpty(form.phone.value) == false) {
			listerrors += "- Phone Number\n";
		}
		if (isFieldEmpty(form.idea.value) == false) {
			listerrors += "- Show Idea\n";
		}
		if (!form.oldenough.checked) {
	        listerrors += "- Sorry, you must be 13 years or older\n";
	    }
	}
	//postmsg
	else if (page == 'postmsg'){
		if (isFieldEmpty(form.name.value) == false) {
			listerrors += "- Name\n";
		}
		if (isFieldEmpty(form.message.value) == false) {
			listerrors += "- Message\n";
		}
		if (!form.oldenough.checked) {
	        listerrors += "- Sorry, you must be 13 years or older\n";
	    }
	}
		
    if (listerrors != "")	{
		alert("Please complete the form. The following fields are required:\n\n" + listerrors);
		return false;
	} else	{
		return true;
	}
}


function thisMovie(movieName) {
    if (navigator.userAgent.indexOf("MSIE") != -1) {
        return window.opener.document.getElementById(movieName);
    }
    else if (navigator.userAgent.indexOf("Safari") != -1) {
        return opener.document[movieName];
    }
    else {
		return opener.document[movieName][1];
    }
}

//live guide video stuff
function videoFullScreen(video_path, time_code){
	full_video = window.open('full_video.html?video_path='+ video_path +'&time_code='+ time_code, 'full_video','width=800,height=600,left=0,top=0,statusbar=0,scrollbars=0,resizable=1');
	full_video.focus();
}

function videoFullScreenClose(time_code){
	thisMovie('flash_movie').resumePlayer(time_code);
	self.close();
}

function clearField(field){
	default_text = 'Search Live Guide Archive';
	if (field.value == default_text) field.value = '';
	else if (field.value == '') field.value = default_text;
}