//*-------------------------------------------------------------------------
//* Handle setting up of the preloading button images
//* This file includes the login form validation and some other misc functions.
//*-------------------------------------------------------------------------

//	var form_domain = "www.twistedpixel.com/cd";  //*** Use this for testing request form from a test site. See reqform.js.
	var form_domain = "www.commercedesktop.com";  //*** This is the production domain.

    var homepage = 0; // default to not the home page

// Dynamically get the file name of the displayed page.
// Hence the "file" argument is not needed.
	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
	var filenm = location.href.substring(dir.length,location.href.length+1);
    var urlname = "www.commercedesktop.com"

// Have to use a slightly different page when it's the homepage since the index.jsp file
// is not in the /content directory.

    if (filenm.substring(0,5) == "index" || filenm == "" || filenm == urlname) homepage = 1;
 	if (homepage) {
 	   imagedir = "images";
 	   htmldir = "content/";
 	}
 	else {
	   imagedir = "../images";
	   htmldir = "../content/";
	}

if(document.images){
  	homeon 		= new Image(); homeon.src= imagedir + "/b-homeon.gif";
 	homeoff		= new Image(); homeoff.src= imagedir + "/b-homeoff.gif";

  	cdeskon 	= new Image(); cdeskon.src= imagedir + "/b-cdeskon.gif";
 	cdeskoff	= new Image(); cdeskoff.src= imagedir + "/b-cdeskoff.gif";

  	connon 		= new Image(); connon.src= imagedir + "/b-connon.gif";
 	connoff		= new Image(); connoff.src= imagedir + "/b-connoff.gif";
  	compon 		= new Image(); compon.src= imagedir + "/b-compon.gif";
 	compoff		= new Image(); compoff.src= imagedir + "/b-compoff.gif";
  	servon 		= new Image(); servon.src= imagedir + "/b-servon.gif";
 	servoff		= new Image(); servoff.src= imagedir + "/b-servoff.gif";

  	loginon 	= new Image(); loginon.src= imagedir + "/b-loginon.gif";
 	loginoff	= new Image(); loginoff.src= imagedir + "/b-loginoff.gif";
  	workson 	= new Image(); workson.src= imagedir + "/b-workson.gif";
 	worksoff	= new Image(); worksoff.src= imagedir + "/b-worksoff.gif";
  	liston 		= new Image(); liston.src= imagedir + "/b-liston.gif";
 	listoff		= new Image(); listoff.src= imagedir + "/b-listoff.gif";

   	bmodeon 	= new Image(); bmodeon.src= imagedir + "/b-bmodeon.gif";
 	bmodeoff	= new Image(); bmodeoff.src= imagedir + "/b-bmodeoff.gif";
   	imodeon 	= new Image(); imodeon.src= imagedir + "/b-imodeon.gif";
 	imodeoff	= new Image(); imodeoff.src= imagedir + "/b-imodeoff.gif";

 }
function flipImg(imgNam,imgTyp,onoff){

//*******************************************************************************
//	Do the mouse over image flipping.
//*******************************************************************************
  	if(document.images){
 		document.images[imgNam].src=eval(imgTyp+onoff+'.src');
  	}
}

function closeWin () {
//*******************************************************************************
//  Close the window -- Called from Copyright Window.
//*******************************************************************************
	window.close();
}

function copyright() {
//*******************************************************************************
//	Display a window with copyright info - This may not be used, a full page may be used instead.
//*******************************************************************************
 	if (homepage) {  cdir = "content/"; }
 	else { cdir = ""; }
	window.open(cdir + "copyright.html", "newwin", "width=570,height=640,scrollbars=yes,status=yes,resizable=yes");
}

function showpic( pic, w, h) {
//*******************************************************************************
//	Display a window with big pic
//*******************************************************************************

	var title="Commerce Desktop";
	var wsave = w;
	var h = h + 62;
	var w = w + 42;

	var data = '<html><head>';

 	data +='<link rel="stylesheet" href="cd.css">';
 	data +='</head>';
	data += '<title>' + title + '</title><body bgcolor="#000020" background="../images/bg-scan-gif" leftmargin=0 topmargin=0 marginheight=0>';
	data += '<center>';
	data += '';
	data += '<a href="javascript:self.close()" onMouseOver="self.status=\'Click on image to close window.\'; return true" onMouseOut="self.status=\'\'; return true">';
	data += '<img src="../images/' + pic + '" alt="Click on image to close window." border="1"></a></center>';
	data += '</td></tr></table><br>';
	data += '</body></html>';
	var newWindow = window.open('','newWin', "width=" + w + ",height=" + h + ",scrollbars=yes,status=yes,resizable=yes", "alwaysRaised");

	newWindow.document.write(data);
	newWindow.document.close('newWin'); //* Close the data stream
	newWindow.resizeTo(w,h);			//* Resize the window for latest image
	newWindow.focus(); 					//* Bring to front

}

function setCookie(name, value, expires, path, domain, secure) {
//*******************************************************************************
// Generic rtn to set a cookie.
//*******************************************************************************
       var curCookie = name + "=" + escape(value) +
           ((expires) ? "; expires=" + expires.toGMTString() : "") +
           ((path) ? "; path=" + path : "") +
           ((domain) ? "; domain=" + domain : "") +
           ((secure) ? "; secure" : "");
       document.cookie = curCookie;
}
function getCookie(name) {
       var dc = document.cookie;
       var prefix = name + "=";
       var begin = dc.indexOf("; " + prefix);
       if (begin == -1) {
         begin = dc.indexOf(prefix);
         if (begin != 0) return null;
       } else
         begin += 2;
       var end = document.cookie.indexOf(";", begin);
       if (end == -1)
         end = dc.length;
       return unescape(dc.substring(begin + prefix.length, end));
     }

//function makeArray(){
//    this.length = makeArray.arguments.length
//        for (var i = 0; i < this.length; i++)
//
//     }

function makeArray(){
    this.length = makeArray.arguments.length
        for (var i = 0; i < this.length; i++)
        this[i + 1] = makeArray.arguments[i]
}

function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1,
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}
