function pop(link,width,height) {

dim = 'height=' +height+ ',width=' +width;

var mywindow=open(link,'myWin', 'toolbar=no, directories=no, scrollbars=yes,location=no, status=no, menubar=no, titlebar=no, resizable=yes, width=' +width+ ', height=' +height);
}
var b_timer = null; // blink timer
var b_on = true; // blink state
var blnkrs = null; // array of spans

function blink() {
var tmp = document.getElementsByTagName("span");
if (tmp) {
blnkrs = new Array();
var b_count = 0;
for (var i = 0; i < tmp.length; ++i) {
if (tmp[i].className == "blink") {
blnkrs[b_count] = tmp[i];
++b_count;
}
}
// time in m.secs between blinks
// 500 = 1/2 second
blinkTimer(2000);
}
}

function blinkTimer(ival) {
if (b_timer) {
window.clearTimeout(b_timer);
b_timer = null;
}
blinkIt();
b_timer = window.setTimeout('blinkTimer(' + ival + ')', ival);
}

function blinkIt() {
for (var i = 0; i < blnkrs.length; ++i) {
if (b_on == true) {
blnkrs[i].style.visibility = "hidden";
}
else {
blnkrs[i].style.visibility = "visible";
}
}
b_on =!b_on;
}

function checksize() {




// var stock='$stock';


if (document.forms[1].size2) {

	if (document.forms[1].size2.selectedIndex == 0) {
	alert ('Please select a size for your item.');
	return;
	}


	var SIZE = document.forms[1].size2.value;
	var SIZE = SIZE.split(",");
	size = (SIZE[0]);
        sizeid = (SIZE[1]);
	stock = (SIZE[2]);
	document.forms[1].size.value = size;
        document.forms[1].sizeid.value = sizeid;

} else {
var stock = document.forms[1].stock.value;
}



if (stock < 1) {
	alert('Sorry, this item is currently out of stock.');
	return;
}

if (eval(document.forms[1].qty.value) > stock) {
	alert('Sorry, but there are currently only ' +stock+ ' of this item in stock.');
	return;

}


var max_qty = document.forms[1].max.value;
//alert(max_qty);
if (max_qty > 0)
 {
if (eval(document.forms[1].qty.value) > max_qty)
{
alert('Sorry, online orders of this item are limited to ' +max_qty+ ' Please call 1300 36 27 87 to place this order.');
return;
}
 }

if (document.forms[1].qty.value < 1) {
	alert('Please enter a quantity of 1 or more');
	document.forms[1].qty.focus();
	return;
}




document.forms[1].stock.value = stock;
document.forms[1].submit();

}

function chgcat() {
cat1 =document.forms[0].cat1.options[document.forms[0].cat1.selectedIndex].text;
location.href = '?cat1=' + cat1;
if (cat1=='Sale') {location.href = '?cat1=' + cat1 + '&head=Sale';}
}



function checkFields() {


	if (!document.forms[1].find.value) {
		alert ('Please enter some words to search.');
		document.forms[1].find.focus();
		return false;
	}
}

function changeitem(itemno,newqty) {
if (newqty < 1) {
alert('Please enter a quantity of 1 or more.');
return false;
}

link = '/basket?go=changeitem&itemno=' +itemno+ '&newqty=' +newqty;

// alert(link);

location.href=link;
}

function changeitem(itemno,newqty) {
if (newqty < 1) {
alert('Please enter a quantity of 1 or more.');
return false;
}
	location.href='/basket?go=changeitem&itemno=' +itemno+ '&newqty=' +newqty;
}



function getDel() {
document.forms[1].action ="/checkout2/index.php";
document.forms[1].submit();
}


function checkout_1() {
 
var newyr = eval(document.forms[1].yy.options[document.forms[1].yy.selectedIndex].text) + 2000;

var newmonth = eval(document.forms[1].mm.options[document.forms[1].mm.selectedIndex].text) - 1;

var newday = document.forms[1].dd.options[document.forms[1].dd.selectedIndex].text;


var laterdate = new Date(newyr,newmonth,newday); 
var todaydate = new Date(document.forms[1].todaydate.value);
var difference = laterdate.getTime() - todaydate.getTime();
var daysDifference = Math.floor(difference/1000/60/60/24);




    if (daysDifference < 0) {
    alert ("Date required is earlier than today's date.")
    return false;
    }


	if (!document.forms[1].approve.value) {
                alert ('Please enter the name of the person approving this order.');
		document.forms[1].approve.focus();
		return false;
	}

	if (!document.forms[1].address.value) {
		alert ('Please enter a delivery address.');
		document.forms[1].address.focus();
		return false;
	}
	
	if (document.forms[1].Postcode.value < 1171) {
		alert ('Please enter a valid postcode for delivery.');
		document.forms[1].Postcode.select();
		return false;
	}
	if (document.forms[1].office.value == 'Select your office...') {
		alert ('Please enter your office location.');
		return false;
	}

return true;

}

function checkout_2() {


	if (document.forms[1].delmeth.selectedIndex == 0) {
		alert ('Please select a delivery method.');
		return false;
	}



}
var nextid = '';
var backid = '';

function handleKeyPress(evt) {
  var nbr, chr;
  //if (window.Event) nbr = evt.which;
  //else 
  nbr = event.keyCode;

  if(nbr==39 && nextid) {
  location.href='edit.php?go=edit&id=' +nextid;
//	document.forms[1].save_action.value = 'next';
//	document.forms[1].next_id.value = nextid;
//document.forms[1].submit();
  }

  if(nbr==37 && backid) { 
  location.href='edit.php?go=edit&id=' +backid;
//	document.forms[1].save_action.value = 'next';
//	document.forms[1].next_id.value = backid;
//	document.forms[1].submit();

  } 
  else{return true;}
}

document.onkeydown = handleKeyPress;

cat1 = '';

function checkFields() {

if (!document.forms[1].name.value) {
	alert('Please enter a name for this item.');
	document.forms[1].name.focus();
	return false;
}


if (!document.forms[1].description.value) {
	alert('Please enter a description for this item.');
	document.forms[1].description.focus();
	return false;
}

if (document.forms[1].cat1.selectedIndex == 0) {
	alert('Please enter a category for this item.');
	return false;
}

if (cat1 != 'Special Orders') {

if (!document.forms[1].price.value) {
	alert('Please enter a price for this item.');
	document.forms[1].price.focus();
	return false;
}



if (!document.forms[1].code.value) {
	alert('Please enter a product code for this item.');
	document.forms[1].code.focus();
	return false;
}

}

}

function delRec() {

	if (confirm('Are you sure you want to delete this property? This cannot be undone.')) {
location.href = 'edit.php?go=delrec&id=&next_id=';
	}

}


function addCat() {

var dialog = window.prompt('Enter the name of a new category');

if (dialog) {
document.forms[0].cat1.options[1].text = dialog;
document.forms[0].cat1.options[1].value = dialog;
document.forms[0].cat1.selectedIndex = 1;
}

}

function addSubCat() {

var dialog = window.prompt('Enter the name of a new category');

if (dialog) {
document.forms[0].cat2.options[1].text = dialog;
document.forms[0].cat2.options[1].value = dialog;
document.forms[0].cat2.selectedIndex = 1;
}

}

function addSubCat2() {

var dialog = window.prompt('Enter the name of a new category');

if (dialog) {
document.forms[0].cat3.options[0].text = dialog;
document.forms[0].cat3.options[0].value = dialog;
document.forms[0].cat3.selectedIndex = 1;
}

}

