// JavaScript Document
var loaderWin;
function loadLoader(theURL, winName, windowFeatures) { 
	var winLeft = (screen.width / 2) - 125;
	var winTop = (screen.height / 2) - 125;
	windowFeatures = windowFeatures + "left=" + winLeft + ",top=" + winTop;
  windowFeatures = windowFeatures + ",width=200,height=150";
	loaderWin = window.open(theURL,loaderWin,windowFeatures);
}
function unloadLoader() {
	if (typeof(loaderWin) != "undefined") {
		if (loaderWin.closed == false) {
			loaderWin.close();
		}
	}
}
function loadNewWindow(theURL,winName,features) { //v2.0
	var avW = screen.availWidth-20;
	var avH = screen.availHeight-20;
	if (avW > 1000) avW = 1000;
	if (avH > 760) avH = 760;
  features = features + ',width=' + avW + ',height=' + avH;
	window.open(theURL,winName,features);
	return false;
}
function addToBasket(pid) {
	var form = document.products;
	var tQ = eval('form.q_' + pid + '.value');
	if (tQ < 1) {
		alert("The quantity must be at least 1.");
		return false;
	}
	form.productID.value = pid;
	form.quantity.value = tQ;
	form.submit();
	return true;
}
function setQuantity(pid) {
	var form = document.products;
	var tQ = eval('form.q_' + pid + '.value');
	form.productID.value = pid;
	form.quantity.value = tQ;
}
function updateBasketQuantity(pid, sid, did, bought, minCred) {
	var form = document.basketForm;
	var thisBasket = eval('form.bQ_' + pid + '_' + sid);
	if (did == 3 && bought == 0) {		// We're trying to change the quantity of site credits being ordered.
		if (thisBasket.value < minCred) {
			alert("The minimum number of credits you can buy for a new site is " + minCred);
			return false;
		}
	}
	if (thisBasket.value <= 0) {
		alert("The quantity must be a positive number.");
		return false;
	} 
	var conf = confirm("Are you sure you wish to change the quantity of the item?\nClick OK to confirm or Cancel to return.");
	if (!conf) {
		return false;
	} else {
		form.action = "actions/process.php";
		form.task.value = "changeBasketQuantity";
		form.updateProductID.value = pid;
		form.updateSiteID.value = sid;
		form.basketQuantity.value = thisBasket.value;
		form.submit();
	}
	return true;
}
function deleteBasketItem(pid, sid) {
	var form = document.basketForm;
	var conf = confirm("Are you sure you wish to delete this item from your basket?\nClick OK to confirm or Cancel to return.");
	if (!conf) {
		return false;
	} else {
		form.action = "actions/process.php";
		form.task.value = "deleteBasketItem";
		form.updateProductID.value = pid;
		form.updateSiteID.value = sid;
		form.submit();
	}
	return true;
}
function checkLogin(logFrm, lt) {
	var typetext = "";
	if (lt == 'owner') {
		typetext = "your email address ";
	} else {
		typetext = "the site name ";
	}
	if (logFrm.Name.value == "" || logFrm.Password.value == "") {
		alert("Please enter " + typetext + "and password in the appropriate fields.");
		return false;
	}
	return true;
}
function confirmLogout() {
	var validate = confirm("Are you sure you want to log out? Click to confirm, Cancel to return.");
	if (validate) return true;
	return false;
}
function validateSummary() {
	var form = document.summaryForm;
	if (form.gv_b1.value.length > 0 || form.gv_b2.value.length > 0 || form.gv_b3.value.length > 0) { 
		if (form.gv_b1.value.length != 4 || form.gv_b2.value.length != 4 || form.gv_b3.value.length != 4) { 
			alert('Invalid gift code');
			return false;
		} else { 
			form.action = "checkout.php?action=summary";
		}
	}
	if (form.terms.checked == false) {
		alert('Please check the box to confirm you have read and agree to the terms and conditions.');
		form.terms.focus();
		return false;
	}
	return true;
}
function checkChangeTheme(tid, tName) {
	var validate = confirm("Are you sure you wish to apply the theme '" + tName + "' to your site?\n Click OK to continue, Cancel to return.");
	if (validate) {
		document.otherThemes.newThemeID.value = tid;
		document.otherThemes.submit();
		return true;
	}
	return false;
}
function validateUpdateWelcome() {
	var validate = confirm("Are you sure you wish to update the welcome message?\n Click OK to continue, Cancel to return.");
	if (validate) {
		return true;
	}
	return false;
}
function setDirection(d) {
	var form = document.curStage;
	form.direction.value = d;
	form.submit();
}
function setRadioButton(thumb) {
	if (document.curStage) {
		var element;
		var numberControls = document.curStage.length;
		for (var c=0; c<numberControls; c++) {
			element = document.curStage[c];
			if (element.type == "radio") {
				if (element.value == thumb) {
					element.checked = true;
				} else {
					element.checked = false;
				}
			}
		}
	}
}
function checkDelete(filler) {
	var returnvalue = false;
	returnvalue = confirm("You have chosen to delete this " + filler + ". \nClick OK to confirm this action or Cancel to return.");
	return returnvalue;
}
function checkMove(filler) {
	var returnvalue = false;
	returnvalue = confirm("You have chosen to move this " + filler + " to another album. \nClick OK to confirm this action or Cancel to return.");
	return returnvalue;
}
function checkSequence(filler, dir) {
	var returnvalue = false;
	returnvalue = confirm("You have chosen to move this " + filler + " " + dir + ". \nClick OK to confirm this action or Cancel to return.");
	return returnvalue;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
