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) { //v3.0
  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); 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];}
}

function loadtool(page) {
	OpenWin = this.open(page, "CtrlWindow", "height=400,width=620,left=15,top=15,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}

function openGame(theURL) {
	newWindow = window.open (theURL,'gameWin','width=500,height=400') 
}

function popupPageleave(URL){
	document.cookie = 'refPageName='+document.title;
	self.name = "main"; aWindow=window.open(URL,"thewindow","toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=620,height=570");
}

function popupCozileave(URL){
	self.name = "main"; aWindow=window.open(URL,"thewindow","toolbar=1,location=1,menubar=1,width=750,height=630");
}


function goURL(form){
var URL = form.site.options[form.site.selectedIndex].value;
top.location.href = URL;
}

function MLPpopup() {
	newwindow = window.open("http://www.hasbro.com/common/popups/mlp_pop.cfm","popupad",
"width=770,height=414,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no");
            	} 

function basicPopup(url,w,h,top,left) {
	self.name = "main";
	pagewindow = window.open(url,"page","width=" + w + ",height=" + h + ",top=" + top + ",left=" + left + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
}

function basicPopupScroll(url,w,h,top,left) {
	self.name = "main";
	pagewindow = window.open(url,"page","width=" + w + ",height=" + h + ",top=" + top + ",left=" + left + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
}


function MM_openBrWindow(theURL,winName,features) 
	{
  window.open(theURL,winName,features);
	}
	
function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function makeFlashPlayer(swfsrc, swfid, width, height, bgcolor){
	document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ID=" + swfid + " WIDTH=" + width + " HEIGHT=" + height + ">" );
	document.write("<PARAM NAME=movie VALUE='"+ swfsrc +"'>\n");
	document.write("<PARAM NAME=menu VALUE=\"false\">\n");
	document.write("<PARAM NAME=quality VALUE=\"high\">\n");
	document.write("<PARAM NAME=wmode VALUE=\"opaque\">\n");
	document.write("<PARAM NAME=bgcolor VALUE=\""+ bgcolor+"\">\n");
	document.write("<EMBED NAME=\"" + swfid + "\" src='" + swfsrc + "' quality=high wmode=opaque menu=false bgcolor=" + bgcolor + " WIDTH=" + width + " HEIGHT=" + height + " TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>" );
}

function makeFlashPlayer2(swfsrc, swfid, width, height, bgcolor){
	document.write("<OBJECT classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' ID=" + swfid + " WIDTH=" + width + " HEIGHT=" + height + ">" );
	document.write("<PARAM NAME=movie VALUE='"+ swfsrc +"'>\n");
	document.write("<PARAM NAME=menu VALUE=\"false\">\n");
	document.write("<PARAM NAME=quality VALUE=\"high\">\n");
	document.write("<PARAM NAME=wmode VALUE=\"opaque\">\n");
	document.write("<PARAM NAME=bgcolor VALUE=\""+ bgcolor+"\">\n");
	document.write("<EMBED NAME=\"" + swfid + "\" src='" + swfsrc + "' quality=high wmode=opaque menu=false bgcolor=" + bgcolor + " WIDTH=" + width + " HEIGHT=" + height + " TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>" );
}

function validateEcardForm(form) {
    var valid = false;	
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if (!isNotEmpty(e)) {
			valid = false;
			return false
		} else {
			if (e.name.toLowerCase().indexOf("email") != -1){ 
				if (!isEMailAddr(e)) {
					valid = false;
					return false
				} else {
					valid = true;
				} 
			}
			valid = true;
		}
	}
	if (valid) {
		return true;
	} else {
		return false;
	}
}

function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Please verify \"" + elem.title + "\" is in the correct format.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.id + "')", 0);
        return false;
    } else {
        return true;
    }
}

function focusElement(formName, elemId) {
    var elem = document.getElementById(elemId);
    elem.focus( );
    elem.select( );
}

function isNotEmpty(elem) {
    var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        alert("All fields are required. Please fill in \"" + elem.title + "\".");
		setTimeout("focusElement('" + elem.form.name + "', '" + elem.id + "')", 0);
        return false;
    } else {
        return true;
    }
}
function validatePoll() {
	var frm = document.getElementById('pollForm');
	var chk = false;
	alert (frm.length());
	for (var i=0; i<frm.paid.length; i++) {
		if (frm.paid[i].checked) {
			chk = true;
		}
	}
	if (chk) {
		frm.submit();
		return true;
	} else {
		alert("Please select an answer to the poll before clicking the \"Vote Now\" button.");
		return false;
	}
}
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}
//  End -->

/* Cookie Handling */
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function scStrip(a) {
     a = a.split("|").join("");
     a = a.split("&").join("");
     a = a.split("'").join("");
     a = a.split("#").join("");
     a = a.split("$").join("");
     a = a.split("%").join("");
     a = a.split("^").join("");
     a = a.split("*").join("");
     a = a.split(":").join("");
     a = a.split("!").join("");
     a = a.split("<").join("");
     a = a.split(">").join("");
     a = a.split("~").join("");
     a = a.split(";").join("");
     a = a.split(" ").join("+");
     return a;
}
