// JavaScript Document

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];}
}

//Timed and Response Functions
function loadpage (id) {
	//alert(id);

	functions.location.replace("monitor.php?app="+id);
	document.getElementById('flashbody').style.top='-1000000px';
	document.getElementById('flashbody').style.left='-1000000px';
	if (id == "calendar") {
		top.location.replace("https://elfontheshelf.com/indexnf.php?id=calendar");
 			//templates.location.replace("/copy/load.php?page=calendar_id");	
	} else if (id == "calendar_id") {
			templates.location.replace("https://elfontheshelf.com/copy/eventcal.php");
			showdiv('header');
			fadein('htmldisp');
			showdiv('htmldisp');
	} else if (id == "gift") {
		top.location.replace("https://elfontheshelf.com/indexnf.php");
//		templates.location.replace("/copy/load.php?page=gift_id");
	} else if (id == "gift_id") {
		templates.location.replace("/copy/gift.php");
		showdiv('header');
		fadein('htmldisp');
		showdiv('htmldisp');
	} else if (id == "about") {
		top.location.replace("/indexnf.php?id=about");
		//templates.location.replace("/copy/load.php?page=about_id");
	} else if (id == "about_id") {
		templates.location.replace("/copy/aboutus.php");
		showdiv('header');
		fadein('htmldisp');
		showdiv('htmldisp');
	} else if (id == "legal") {
		templates.location.replace("/copy/aboutus.php?legal=yes");
		showdiv('header');
		fadein('htmldisp');
		showdiv('htmldisp');
	} else if (id == "buy") {
		templates.location.replace("/copy/load2.php?page=buy_id");
	} else if (id == "buy_id") {
		
		var shoptop = parseInt(window.outerHeight) - 850;
		var shopleft = parseInt(window.outerWidth)-900;
		//var shop = window.open("https://elfontheshelf.com/copy/shop.php","SHOPPING","height=700px,width=800px,top="+shoptop+"px,left="+shopleft+",fullscreen=no");
		 if(shop) {
		  	shop.focus();
		 } else {
			//window.location.replace("https://elfontheshelf.com/copy/shop.php","SHOPPING","height=700px,width=800px,top="+shoptop+"px,left="+shopleft+",fullscreen=no");
		 }
	} else if (id == "product") {
		templates.location.replace("/copy/load2.php?page=product_id");
	} else if (id == "product_id") {
			fadein('htmlbody');
	templates.location.replace("/copy/product.php");
	} else if (id == "faq") {
		templates.location.replace("/copy/load2.php?page=faq_id");
	} else if (id == "legal_id") {
		templates.location.replace('/copy/legal.php');
		fadein('htmlbody');
	} else if (id == "terms_id") {
		templates.location.replace('/copy/terms.php');
		fadein('htmlbody');
	} else if (id == "privacy_id") {
		templates.location.replace('/copy/privacy.php');
		fadein('htmlbody');
	} else if (id == "submission_id") {
		templates.location.replace('/copy/submission.php');
		fadein('htmlbody');
	} else if (id == "faq_id") {
		templates.location.replace("/copy/faq.php");
		fadein('htmlbody');
	} else if (id == "locate") {
		templates.location.replace("/copy/load2.php?page=locate_id");
	} else if (id == "locate_id") {
		templates.location.replace("/copy/locations.php");
		fadein('htmlbody');
	} else if (id == "media") {
		templates.location.replace("/copy/load2.php?page=media_id");
	} else if (id == "media_id") {
		templates.location.replace("/copy/media.php");
		fadein('htmlbody');
	} else if (id == "seen") {
		templates.location.replace("/copy/load2.php?page=seen_id");
	} else if (id == "seen_id") {
		templates.location.replace("/copy/seenon.php");
		fadein('htmlbody');
	} else if (id == "tradition") {
		templates.location.replace("/copy/load2.php?page=tradition_id");
	} else if (id == "tradition_id") {
		templates.location.replace("/copy/tradition.php");
		fadein('htmlbody');
	} else if (id == "bios") {
		templates.location.replace("/copy/load2.php?page=bios_id");
	} else if (id == "bios_id") {
		templates.location.replace("/copy/bios.php");
		fadein('htmlbody');
	} else if (id == "news") {
		templates.location.replace("/copy/load2.php?page=news_id");
	} else if (id == "news_id") {
		templates.location.replace("/copy/news.php");
		fadein('htmlbody');
	} else if (id == "contact") {
		templates.location.replace("/copy/load2.php?page=contact_id");
	} else if (id == "contact_id") {
		templates.location.replace("/copy/contact.php");
		fadein('htmlbody');
	} else if (id == "registry_register") {
		templates.location.replace("/copy/register.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "workshop_crayons") {
		templates.location.replace("/copy/workshop_crayons.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "workshop_dresstheelf") {
		templates.location.replace("/copy/workshop_dresstheelf.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "workshop_crafts") {
		templates.location.replace("/copy/workshop_dollhouse.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "color_santa") {
		templates.location.replace("/copy/color_santa.php");
	} else if (id == "color_workshop") {
		templates.location.replace("/copy/color_workshop.php");
	} else if (id == "workshop_games") {
		templates.location.replace("/copy/workshop_games.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "elf_memory") {
		templates.location.replace("/copy/elf_memory.php");
		//window.open("copy/register.php",id,"menubar=no,width=960,height=480,toolbar=no");	
	} else if (id == "elf_hide") {
		templates.location.replace("/copy/elf_hide.php");
	} else if (id == "workshop_dollhouse") {
		templates.location.replace("/copy/workshop_dollhouse.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "workshop_clock") {
		templates.location.replace("/copy/workshop_clock.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "stables_sleigh") {
		templates.location.replace("/copy/stables_sleigh.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "school_map") {
		templates.location.replace("/copy/school_map.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_lesson1") {
		templates.location.replace("/copy/schoolhouse_lesson1.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_lesson2") {
		templates.location.replace("/copy/schoolhouse_lesson2.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_lesson3") {
		templates.location.replace("/copy/schoolhouse_lesson3.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "stables_barrel") {
		templates.location.replace("/copy/stables_barrel.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "stables_rudolph") {
		templates.location.replace("/copy/stables_rudolph.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "stables_reindeer") {
		templates.location.replace("/copy/stables_reindeer.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_art") {
		templates.location.replace("/copy/comingsoon.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "stables_jinglebells") {
		templates.location.replace("/copy/stables_jinglebells.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "reindeer_ornament") {
		templates.location.replace("/copy/stables_ornament.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "gum_drop") {
		templates.location.replace("/copy/stables_gumdrop.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "stables_puzzle") {
		templates.location.replace("/copy/stables_puzzle.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "elf_jigsaw") {
		templates.location.replace("/copy/jigsaw_puzzle.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "main_slide") {
		templates.location.replace("/copy/slide_puzzle.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "kitchen_cookbook") {
		templates.location.replace("/copy/kitchen_cookbook.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "kitchen_cookie") {
		templates.location.replace("/copy/kitchen_cookie.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "kitchen_cappucino") {
		templates.location.replace("/copy/schoolhouse_math.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_music") {
		templates.location.replace("/copy/schoolhouse_music.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "school_abacus") {
		templates.location.replace("/copy/schoolhouse_mathfun.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_math") {
		templates.location.replace("/copy/schoolhouse_math.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "schoolhouse_writing") {
		templates.location.replace("/copy/schoolhouse_writing.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "registry_wiseelf") {
		templates.location.replace("/copy/registry_wiseelf.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "registry_frames") {
		templates.location.replace("/copy/registry_frames.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "registry_talking") {
		templates.location.replace("/copy/registry_talking.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "registry_plaques") {
		templates.location.replace("/copy/registry_plaques.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "registry_topten") {
		templates.location.replace("/copy/registry_topten.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "registry_quiz") {
		templates.location.replace("/copy/registry_quiz.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_gifts") {
		templates.location.replace("/copy/tree_gifts.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_elf") {
		templates.location.replace("/copy/tree_elf.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_star") {
		templates.location.replace("/copy/commercial.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_crayons") {
		templates.location.replace("/copy/tree_crayons.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_lights") {
		templates.location.replace("/copy/tree_light.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_decorate") {
		templates.location.replace("/copy/tree_decorate.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else if (id == "tree_quiz") {
		templates.location.replace("/copy/tree_quiz.php");
		fadein('northpolebody');
		showdiv('northpolehtml');
	} else {
		templates.location.replace("/copy/comingsoon.php");
		fadein('northpolebody');
		showdiv('northpolehtml');

		//alert('WARNING!  Link for '+id+' not yet active!');
		//document.getElementById('flashbody').style.top='';
		//document.getElementById('flashbody').style.left='';
}



}
function unload () {
	templates.location.replace("/copy/innerload.php");
	document.getElementById('flashbody').style.top='';
	document.getElementById('flashbody').style.left='';
	fadeout('htmldisp');
	fadeout('northpolebody');
	hidediv('header');
	hidediv('htmldisp');
	hidediv('northpolehtml');
}
//Basic Functions
function formcheck(){
	if (document.getElementById('family_name').value != ''){
		if (document.getElementById('city').value != ''){
			if (document.getElementById('state').value != ''){
				if (document.getElementById('elf_name').value != ''){
					var good = 1;
				}
			}
		}
	}
		
	if (good == undefined){
		document.getElementById('submit').disabled = true;
	} else {
		document.getElementById('submit').disabled = false;
	}
}

function centerobj (id) {
	var winw = window.outerWidth;
	var windif = parseInt(winw)-1024;
	if (windif > 0) {
		var winpad = parseInt(windif)/2;
	}
	parent.document.getElementById(id).style.paddingLeft=winpad+"px"
}

function fadein(id) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = 1;
	while (x < 11) {
		setTimeout("fade('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)+10;
		var time = time +55;
		var x = x + 1;
	}
}
function delayfade(id) {
		setTimeout("fadein('"+id+"')",400);
}
function fadeout(id) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = 100;
	while (x < 11) {
		setTimeout("fade('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)-10;
		var time = time +55;
		var x = x + 1;
	}
}
function fade(id,point) {
	if (point > 99) {
		document.getElementById(id).style.opacity=1;
	} else {
		document.getElementById(id).style.opacity="."+point;
	}
	document.getElementById(id).style.filter="alpha(opacity="+point+"0)";
}



function showdiv(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
		obj.style.display="";
}
function hidediv(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	obj.style.display="none";
}
function toggle(name){
	var obj = (document.getElementById)? document.getElementById(name) : eval("document.all[name]");
	if (obj.style.display != "none") {
		obj.style.display="none";
	} else {
		obj.style.display="";
	}
}
function transfer(orgid,newid,id){
	var secdata=templates.document.getElementById(orgid).innerHTML;
    var replace = document.getElementById(newid);
    var wrappingDiv = document.createElement('div');
    wrappingDiv.className="text/html";
    var divdata = ""+ secdata;
    wrappingDiv.innerHTML = ""+divdata;
    replace.innerHTML= '';
	replace.appendChild(wrappingDiv);
}
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	else 
	countfield.value = maxlimit - field.value.length;
	}
function addsection(newid, orgid,number){
var secdata=parent.document.getElementById(orgid).innerHTML;
	while (secdata.indexOf( "_####" ) > -1 )
		secdata = secdata.replace( "_####",number);

	var replace = parent.document.getElementById(newid);
	var wrappingDiv = parent.document.createElement('div');
	wrappingDiv.className="text/html";
	var divdata = ""+ secdata;
	wrappingDiv.innerHTML = ""+divdata;
	replace.appendChild(wrappingDiv);
}

function Mod10(ccNumb) { // v2.0
var valid = "0123456789" // Valid digits in a credit card number
var len = ccNumb.length; // The length of the submitted cc number
var iCCN = parseInt(ccNumb); // integer of ccNumb
var sCCN = ccNumb.toString(); // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,''); // strip spaces
var iTotal = 0; // integer total set at zero
var bNum = true; // by default assume it is a number
var bResult = false; // by default assume it is NOT a valid cc
var temp; // temp variable for parsing string
var calc; // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
temp = "" + sCCN.substring(j, j+1);
if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
/*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length
if((len == 0)&&(bResult)){ // nothing, field is blank AND passed above # check
bResult = false;
} else{ // ccNumb is a number and the proper length - let's see if it is a valid card number
if(len >= 15){ // 15 or 16 for Amex or V/MC
for(var i=len;i>0;i--){ // LOOP throught the digits of the card
calc = parseInt(iCCN) % 10; // right most digit
calc = parseInt(calc); // assure it is an integer
iTotal += calc; // running total of the card number as we loop - Do Nothing to first digit
i--; // decrement the count - move to the next digit in the card
iCCN = iCCN / 10; // subtracts right most digit from ccNumb
calc = parseInt(iCCN) % 10 ; // NEXT right most digit
calc = calc *2; // multiply the digit by two
// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
switch(calc){
case 10: calc = 1; break; //5*2=10 & 1+0 = 1
case 12: calc = 3; break; //6*2=12 & 1+2 = 3
case 14: calc = 5; break; //7*2=14 & 1+4 = 5
case 16: calc = 7; break; //8*2=16 & 1+6 = 7
case 18: calc = 9; break; //9*2=18 & 1+8 = 9
default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers
}
iCCN = iCCN / 10; // subtracts right most digit from ccNum
iTotal += calc; // running total of the card number as we loop
} // END OF LOOP
if ((iTotal%10)==0){ // check to see if the sum Mod 10 is zero
bResult = true; // This IS (or could be) a valid credit card number.
} else {
bResult = false; // This could NOT be a valid credit card number
}
}
}
// change alert to on-page display or other indication as needed.
if(bResult) {
	if (document.purchaseelf.ccexp1.value != "" & document.purchaseelf.ccexp2.value != "" & document.purchaseelf.ccv2.value != "" & document.purchaseelf.fccname.value != "" & document.purchaseelf.lccname.value != "" & document.purchaseelf.ccaddr.value != "" & document.purchaseelf.billcity.value != "" & document.purchaseelf.billzip.value != "" & document.purchaseelf.email.value != "") {
		document.purchaseelf.Purchase.disabled=false;
	}
	//alert("This IS a valid Credit Card Number!");
}
if(!bResult){
alert("This is NOT a valid Credit Card Number!");
		document.purchaseelf.Purchase.disabled=true;

}
return bResult; // Return the results
}

function shiftup(id,pixxy) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = parseInt(document.getElementById(id).style.top);
	while (x < parseInt(pixxy)) {
		setTimeout("push('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)-5;
		var time = time +15;
		var x = x + 1;
	}
	
}
function shiftdown(id,pixxy) {
	var x = 0;
	var time = 0;
	var mover = 0;
	var pix = parseInt(document.getElementById(id).style.top);
	parent.document.getElementById('top').value = pix;
	while (x < parseInt(pixxy)) {
		setTimeout("push('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)+5;
		var time = time +15;
		var x = x + 1;
	}
}
function shiftleft(id,pixxy) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = parseInt(document.getElementById(id).style.left);
	while (x < parseInt(pixxy)) {
		setTimeout("pushover('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)-5;
		var time = time +15;
		var x = x + 1;
	}
	
}
function shiftright(id,pixxy) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = parseInt(document.getElementById(id).style.left);
	while (x < parseInt(pixxy)) {
		setTimeout("pushover('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)+5;
		var time = time +15;
		var x = x + 1;
	}
}
function shiftrightex(id,pixxy,key) {
	var adjust = parent.document.getElementById(key).value;
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = parseInt(document.getElementById(id).style.left);
	parent.document.getElementById('right').value = pix;
	var pixxy = parseInt(pixxy)+parseInt(adjust);
	while (x < parseInt(pixxy)) {
		setTimeout("pushover('"+id+"','"+pix+"');",time);
		var pix = parseInt(pix)+5;
		var time = time +15;
		var x = x + 1;
	}
}
function squeeze(id) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = parseInt(document.getElementById(id).width);
	while (pix > 0) {
		var pix = parseInt(pix)-1;
		setTimeout("expsque('"+id+"','"+pix+"');",time);
		var time = time +15;
	}
}
function grow(id) {
	var x = 0;
	var time = 0;
	var mover = 0;
	pix = parseInt(document.getElementById(parent.document.getElementById('currentdisp').value+"_mv").width);
	parent.showdiv(parent.document.getElementById('currentdisp').value+"_thumb");
	while (pix < 101) {
		var pix = parseInt(pix)+1;
		setTimeout("expsque('"+parent.document.getElementById('currentdisp').value+"','"+pix+"');",time);
		var time = time +15;
	}
}


function expsque(id,point) {
	document.getElementById(id).style.width=point+'px';
}

function push(id,point) {
	document.getElementById(id).style.top=point+'px';
}
function pushover(id,point) {
	document.getElementById(id).style.left=point+'px';
}
