//---Generic Functions

//make test appear Bold face
function rollonB(what){
what.style.fontWeight = 'bold'
}

//return text to normal face
function rolloff(what){
what.style.fontWeight = 'normal'
what.style.color = '#000000'
}

//Change a picture to name with _o prefix
function rollonpic(what){
	var newsrc,newsrclen,exten;
	newsrc = what.src;
	newsrclen = newsrc.length - 4
	exten = newsrc.substr(newsrclen, newsrc.length)
	newsrc = newsrc.substr(0,newsrclen) + "_o" + exten
	what.src= newsrc;
}

//Return a picture to name without _o prefix
function rolloffpic(what){
	var newsrc,newsrclen, exten;
	newsrc = what.src;
	newsrclen = newsrc.length - 6
	exten = newsrc.substr(newsrclen + 2, newsrc.length)
	newsrc = newsrc.substr(0,newsrclen) + exten
	what.src= newsrc;
}

//Change picture to name with _o and associated text to Bold face
function rollonTextPic(bulletName, what){
what.style.fontWeight = 'bold'
if (document.images){
var newsrc,newsrclen, exten;
	newsrc = document.images[bulletName].src
	newsrclen = newsrc.length - 4
	exten = newsrc.substr(newsrclen, newsrc.length)
	newsrc = newsrc.substr(0,newsrclen) + "_o" + exten
	document.images[bulletName].src = newsrc;
}
}

//Return picture to name without _o and associated text to normal face
function rolloffTextPic(bulletName, what){
what.style.fontWeight = 'normal'
if (document.images){
var newsrc,newsrclen, exten;
	newsrc = document.images[bulletName].src
	newsrclen = newsrc.length - 6
	exten = newsrc.substr(newsrclen + 2, newsrc.length)
	newsrc = newsrc.substr(0,newsrclen) + exten
	document.images[bulletName].src = newsrc;
}
}

//Check that control contains a valid Quantity
function isNumber(what){
if  (isNaN(what.value )) {
alert("The Quantity should be a number!");
what.focus();
what.select();
return;
}
}



//Check that control contains a number of given length
function isNumberSize(what, thelen, ctrlname){
var dataSize = what.value
//alert(dataSize.length);
if (dataSize.length ==0){
return;
}

if  (isNaN(what.value )) {
alert("Please enter a " + thelen + " digit number");
what.focus();
what.select();
return;
}


if  (dataSize.length != thelen) {
alert("Please enter a " + thelen + " digit number for the " + ctrlname + " No.");
what.focus();
what.select();
return;
}
}






//Convert a controls contents to uppercase
function setuppercase(what){
what.value = what.value.toUpperCase();
}



//Check an EAN13 Barcode Number is correct
function checkean13(what){
var bcodeNo = what.value
if (bcodeNo =="")
{ return;
}

if  (isNaN(bcodeNo )) 
{
alert("The Barcode number must be made up of numerical digits only!");
what.focus();
what.select();
return;
}
if (bcodeNo.length != 13)
{
alert ("Barcode Number must be 13 digits in length. You have entered " + bcodeNo.length + " digits");
what.focus();
what.select();
return;
}
var firstTotal = parseInt(bcodeNo.substr(1,1)) + parseInt(bcodeNo.substr(3,1)) + parseInt(bcodeNo.substr(5,1)) + parseInt(bcodeNo.substr(7,1))  + parseInt(bcodeNo.substr(9,1))   + parseInt(bcodeNo.substr(11,1))
firstTotal = firstTotal * 3
var secondTotal = parseInt(bcodeNo.substr(0,1)) + parseInt(bcodeNo.substr(2,1)) + parseInt(bcodeNo.substr(4,1)) + parseInt(bcodeNo.substr(6,1))  + parseInt(bcodeNo.substr(8,1))  + parseInt(bcodeNo.substr(10,1))
secondTotal = secondTotal +  firstTotal;

secondTotal = 10 - secondTotal % 10
//alert (secondTotal);
if (secondTotal == 10){
secondTotal = 0
}
var chkdigit = parseInt(bcodeNo.substr(12,1));
if (secondTotal != chkdigit) {
alert("The last digit which is the Barcode Check digit should be " + secondTotal + ". Please make sure the number was typed in correctly.")
what.focus();
what.select();
}

}

//Convert a control contents to a currency
function currency(what) {
   anynum= what.value
   
   anynum= anynum.replace("£","")
   
   if  (isNaN(anynum)){
	alert("The Price should be a valid sterling price!");
	what.focus();
	what.select();
	return;
	}
if  (what.value == '') {
	return;
	}

   anynum=eval(anynum)
   workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
   if (workStr.indexOf(".")==-1){workStr+=".00"}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))
   while (pStr.length<3){pStr+="0"}

   if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }

   if (dNum>=1000000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   }
   retval = dStr + pStr 
   if (anynum<0) {retval="("+retval+")"}
   what.value= "£" + retval
}






//---Functions specific to this App


function checkToClear(){
if (document.OrderFrm.PONo.value == ""){
clearfrm();
}
}


function clearfrm(){
for (var i = 1; i<document.OrderFrm.elements.length; i++)
        { document.OrderFrm.elements[i].value = ""; }
       				}



function placeorder(){
var detailsArray = new Array()
var transdata = ''
var custRefce = document.OrderFrm.PONo.value		
if(custRefce =='')
{
alert("Please enter a Ref/Po Number");
document.OrderFrm.PONo.focus();
return;
}

for (var i = 0; i<document.OrderFrm.elements.length; i++)
        { 
         detailsArray[i] = document.OrderFrm.elements[i].value; 
         transdata = transdata  + detailsArray[i] + "?"
         }
window.location.href =  'OrderConfirmation.asp?' + transdata 

}









//function clearfrm(){
//for (var i = 1; i<document.OrderFrm.elements.length; i++)
  //      { document.OrderFrm.elements[i].value = ""; }
    //   				}



function verifySizes(what,ind){
var curSize = what.value;
if (curSize ==""){
return;
}
if(ind!=1){
for(i=1;i<9;i++){
	if(i != ind){
	ctrlSize = eval("document.OrderFrm.size" + i + ".value")
	if (curSize == ctrlSize){
		alert("Size " + curSize + " has already been used with this order. Please select a different size.");
		what.focus()
		return;
				}
		}
	}
}
}







