// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();


// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
					  (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_safari = (agt.indexOf('safari') != -1);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
var is_ie7up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6);


function PopupWin(url, popwidth, popheight) {
	agent = navigator.userAgent;
	windowName = 'PopupWin';
	params  = '';
	params += 'toolbar=0,';
	params += 'location=0,';
	params += 'directories=0,';
	params += 'status=0,';
	params += 'menubar=0,';
	params += 'scrollbars=0,';
	params += 'resizable=0,';
	params += 'width=';
	params += popwidth;
	params += ',';
	params += 'height=' 
	params += popheight;
	win = window.open(url, windowName , params);
	if (agent.indexOf('Mozilla/2') != -1 && agent.indexOf('Win') == -1) {
		win = window.open(url, windowName , params);
	}
	if (!win.opener) {
		win.opener = window;
	}
}

/**
 * Used to trigger Send to a Friend pop-up.  Specific section can be provided via
 * this call.
 *
 * @param	pgCode:String		Code for the page to send to friend.
 */
function sendToFriend(pgCode, vidId) {
	var path = "/MysteryFabric/MF_SendToAFriend/?pgCode=" + pgCode;
	if (vidId) {
		path += "&vidId=" + vidId;
	}
	 popUp(path, 605, 450);
}

function newsletterSignup() {
	popUp("/MysteryFabric/NewsletterSignup/", 605, 350);
}

function readTestimonial(vidId) {
	popUpScroll("/MysteryFabric/FashionVictimFirstPerson/readTestimonial.asp?vidId=" + vidId, 605, 430);
}

function storySubmission() {
	// popUpScroll("http://www.mysteryfabric.com/Sweepstakes/MysteryFabricContest/", 620, 580);
	popUpScroll("/Sweepstakes/MF_SubmitAStory/", 620, 580);
}

function enterVoteToWin() {
	popUpScroll("/Sweepstakes/MysteryFabricIISweeps/", 620, 500);
}

function viewAvatar(path) {
	popUp("avatar.htm?path=" + path, 380, 300);
}

function addPageCode() {
	var pgCode = getQueryParamValue("pgCode");
	if (pgCode != null) {
		document.write('<input name="pgCode" type="hidden" value="' + pgCode + '" />');	
	}
}
function addComment() {
	var pgCode = getQueryParamValue("pgCode");
	if (pgCode != null) {
		var comm=document.Send2Friend.Comments;
		if (pgCode=='fvf') { 
			comm.value='Check out this first person testimonial about a Mystery Fabric experience. It\'s pretty funny!';
		} else if (pgCode=='cot') { 
			comm.value='Watch this funny video of someone caught in a Mystery Fabric!';
		} else if (pgCode=='fqu') {
			comm.value='I have a feeling you might be caught in a Mystery Fabric. Take this quiz to find out!';
		} else if (pgCode=='sga') {
			comm.value='Try catching as much Cotton as you can while avoiding the Mystery Fabric!';	
		}		
	}
}	
function addVidId() {
	var vidId = getQueryParamValue("vidId");
	if (vidId != null) {
		document.write('<input name="vidId" type="hidden" value="' + vidId + '" />');
	}
}


function popUp(URL, intWidth, intHeight) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=" + intWidth + ",height="  +  intHeight + " ');");
}

function popUpScroll(URL, intWidth, intHeight) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + intWidth + ",height="  +  intHeight + " ');");
}


/**** Green Quiz ****/
 
function showLightningRoundResults(setNum) {
	var winW;
	var fileName = "GreenQuiz_lr_results_" + setNum + ".html";
	if (is_gecko) {
		winW = 607;
	} else {
		winW = 590;
	}
	popUpGQ(fileName, winW, 600, 1, 0);
}

function showPrize(prize, girl) {
	var url = "GreenQuiz_prizeDescription.html?prize=" + prize + "&girl=" + girl;
	popUpGQ(url, 597, 304, 0, 0);
}

function showCaution() {
	var url = "GreenQuiz_caution.html";
	popUpGQ(url, 597, 304, 0, 0);
}

function showEmailSignup() {
	var url = "GreenQuiz_emailSignup.html";
	popUpGQ(url, 597, 304, 0, 0);
}

function sendToFriendGreen() {
	var url = "GreenQuiz_sendToFriend.html";
	popUpGQ(url, 596, 343, 0, 0);
}

function sendResultsToFriend(scoreId) {
	var url = "GreenQuiz_sendToFriend.html?scoreId=scoreId";
	popUpGQ(url, 596, 343, 0, 0);
}

function showTryMore() {
	var url = "GreenQuiz_tryMore.html";
	popUpGQ(url, 597, 304, 0, 0);
}

function reloadQuiz() {
	window.opener.location.reload();
 	window.setTimeout('window.close()',10);
}

function popUpGQ(filename, width, height, scrollbars, resize) {
	var etcParams = ",directories=0,location=0,menubar=0,resizable="+(resize ? "1" : "0")+",status=0,toolbar=0,scrollbars=" + (scrollbars ? "1" : "0");
	var popup = window.open(filename, "_blank", "width=" + width + ",height=" + height + etcParams);
	popup.focus();
}

