var defaultEmptyOK = false;
var whitespace = " \t\n\r";
function isEmpty(s){return ((s == null) || (s.length == 0))}
function Zoom(photo){window.open("/zoom.cfm?photo=" + photo,'aaaaZOOMaa',"top=200,left=200,height=265,width=300");}
function ltrim(myString) {
i=0
do {i++}
while ( i < myString.length && (myString.charCodeAt(i)==32 || myString.charCodeAt(i)=='NaN') );
return myString.substr(i,myString.length)
}
//Right Trim
function rtrim(myString) {
i=myString.length
do {i--}
while (myString.charCodeAt(i)==32 || myString.charCodeAt(i)=='NaN' );
return myString.substr(0,i+1)
}

function  replace(string, substring1, substring2 , scope)
{if(!scope){scope='1'}
if(scope!='ALL'){scope='1'}
re = '/'+substring1
if(scope=='1'){re += '/'}
else{re +='/g'}
alert(re);
new_string = string.replace(eval(re),substring2)
return new_string}

function isDigit (c){return ((c >= "0") && (c <= "9"))}
function isNumber(s){
if (s =="") return false;
else{
   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c))
        return false;
    }
    return true;
}}

function isEmail(s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@")){i++}

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")){i++}

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isWhitespace (s)

{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}
function left(string,count) {return string.substr(0,count);}
function right(mystring,count){return mystring.substring(mystring.length-count,mystring.length);}
function trim(myString) {return rtrim(ltrim(myString));}
function arraylen(array){return eval(array).length}
function findnocase(mysubstring,mystring,mystart)
 {
 if(!mystart){var mystart=0;}
 else
 {mystart = mystart - 1;}
 mystring = mystring.toUpperCase()
 mysubstring = mysubstring.toUpperCase()
return mystring.indexOf(mysubstring, mystart)+1;
 }
 
 function listtoarray(list,delimiters) {
if(!delimiters){var delimiters=','}
_TempListSplitArray = list.split(delimiters)
return _TempListSplitArray
}

function GOODQTY(input){return isNumber(input.replace(/\./g,""));}

function PlaceOrder_(){
temp=listtoarray(FRM.IDS.value);
good=true;
n=0;
IDLEN=eval(arraylen(temp)-2);
for(I=0;I<=IDLEN;I++){
ID=temp[I];
QTY=FRM.elements["QTY" + ID].value;
if(QTY != "" && QTY != "0"){
	if(!GOODQTY(QTY)){good=false;}
	else{n++;}
}}
if(good && n > 0){FRM.submit(FRM);}
else{alert("Errors in QTY");}
}

function UpdateTotal(thisID){
temp=listtoarray(FRM.IDS.value);
total=0;
itemtotal=0;
cQTY=FRM.elements["QTY" + thisID].value;
if(cQTY != ""){if(GOODQTY(cQTY))itemtotal=eval(cQTY * FRM.elements["PRICE" + thisID].value);}
IDLEN=eval(arraylen(temp)-2);
for(I=0;I<=IDLEN;I++){
QTY=FRM.elements["QTY" + temp[I]].value;
PRICE=FRM.elements["PRICE" + temp[I]].value;
if(QTY != ""){
	if(GOODQTY(QTY)) total=total+eval(QTY * PRICE);
	else{
		alert("Please enter a valid qty in.");
		FRM.elements["QTY" + temp[I]].value="";
		FRM.elements["QTY" + temp[I]].focus();
		}
}}
FRM.TOTAL.value=total;
FRM.elements["ITEMTOTAL" + thisID].value=itemtotal;
}

function PrintOrder(OrderID){window.open("/printorder.cfm?OrderID=" + OrderID,"AAAA","height=600,width=800,scrollbars");}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function sendmsg(sUser,office){
  sDom = "Bill" + "Doran";
  ssub = "?sub" + "ject=" +  sDom + "." + "com: " + office;
  document.writeln('<a class="emaillink" href="mail' + 'to:' + sUser + '@' + sDom + '.' + 'com' + ssub + '">Email Us: ' + sUser + '@' + sDom + '.' + 'com</a>');
}