//if (top.frames.length == 0) 
//top.document.location = "/sorry.cfm"; 

var phone_field_length=0;

function getZip(zip_field,province_field,city_field)	{
	
	var zip=document.getElementById(zip_field);
	
	// send data to CF
	DWRUtil.useLoadingMessage();
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'ax_getZip', zip.value, province_field, city_field, getZipResult);
}

// call back function
function getZipResult (r) {
	// set city and state
	var selProv = document.getElementById(r.province_field);
	var txtCity = document.getElementById(r.city_field);
	txtCity.value=r.city;
	
    for (var i = 0 ; i < selProv.options.length ; i++)
        if (selProv.options[i].value == r.state)
            selProv.selectedIndex = i;

}

function getProducts(keyword)	{
	
	// send data to CF
	DWRUtil.useLoadingMessage();
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'ax_getProducts', keyword, getProductsResult);
}

// call back function
function getProductsResult (r) {
	
	document.getElementById("div_products").innerHTML = r;

}

function createTarget(form) {
	_target = form.target;
	_colon = _target.indexOf(":");
	if(_colon != -1) {
		form.target = _target.substring(0,_colon);
		form.args = _target.substring(_colon+1);
	} else if(typeof(form.args)=="undefined") {
		form.args = "";
	}
	if(form.args.indexOf("{")!=-1) {
		_args = form.args.split("{");
		form.args = _args[0];
		for(var i = 1; i < _args.length;i++) {
			_args[i] = _args[i].split("}");
			form.args += eval(_args[i][0]) + _args[i][1];
	   }
	}
	form.args = form.args.replace(/ /g,"");
	_win = window.open('',form.target,form.args);
	if(typeof(focus)=="function")
		_win.focus();
	return true;
}


function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
			}
		}
	}
}

function GeneratePassword() {
    if (parseInt(navigator.appVersion) <= 3) {
        alert("Sorry this only works in 4.0+ browsers");
        return true;
    }
    var length=8;
    var sPassword = "";
    length = 6;
    var noPunction = "checked";
    var randomLength = "";
    if (randomLength) {
        length = Math.random();
        length = parseInt(length * 100);
        length = (length % 7) + 6
    }

    for (i=0; i < length; i++) {
        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        sPassword = sPassword + String.fromCharCode(numI);
		
    }
    document.myForm.c_password.value = sPassword
    return true;
}

function getRandomNum() {
    // between 0 - 1
    var rndNum = Math.random()
    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);
    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;
    return rndNum;
}

function checkPunc(num) {
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    return false;
}

function checkAll(elementName){
     var boolValue = elementName.checked;
     for (var i=0;i<document.orderList.elements.length;i++){
       var e = document.orderList.elements[i];
       if (e.name != elementName.name)
         e.checked = boolValue;
     }
}

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))+','+	//Min removed Jun 01, 2004
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function show(obj){	
	if(!document.all && document.getElementById) {
		if(document.getElementById(obj)) document.getElementById(obj).style.display='';
	}else {
        	if(document.all[obj]) document.all[obj].style.display='';
	}
}

function hide(obj){
	if(!document.all && document.getElementById) {
		if(document.getElementById(obj)) document.getElementById(obj).style.display='none';
	}
	else {	
		if(document.all[obj]) document.all[obj].style.display='none';
	}
}

function ccwin(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=230,height=180;,directories=no,status=no,scrollbars=no,resize=no,menubar=no" )
}
function newin1(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=500,height=350,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no" )
}
function newin2(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=700,height=600,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no" )
}
function newin3(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=500,height=200,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no" )
}
function newin4(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=200,height=120,left=790,top=200,directories=no,status=no,scrollbars=no,resizable=no,menubar=no" )
}
function newin5(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=500,height=100,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no" )
}
function newin6(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=500,height=600,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no" )
}
function newin7(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=695,height=650,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no" )
}
function newin8(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=800,height=600,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no" )
}
function newin9(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=600,height=500,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no" )
}
function newin10(url){
	newWindow = window.open(url,"NewWindow","toolbar=no,width=700,height=380,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no" )
}
// Set the horizontal and vertical position for the popup
PositionX = 400;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["Min"].width;');writeln('window.innerHeight=document.images["Min"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=ffffff scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="Min" src="'+imageURL+'" style="display:block"></body></html>');
close();		
}}