var headerImage = '';
var headerName = '';
var headerText = '';
var headerByline = '';
var headerLayout = '1';
var myImages = new Array();
var myLoads = new Array();
var myProtocol = location.protocol.slice(0,-1);
var myServer = window.location.host;
var myPath = window.location.pathname.slice(0, window.location.pathname.lastIndexOf("/") + 1);


if (navigator.appName != "microsoft internet explorer")
{
	self.focus();
}
else
{
	var version = parsefloat(navigator.appVersion)
	if(version >= 4) self.focus();
}

self.name = "so_main";


function ViewHelp()
{
	window.open("", 'so_help', 'history=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=400,height=400');
}


function ViewAssistance()
{
	window.open("", 'so_assistance', 'history=no,toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=400,height=400');
}


function CheckMenuChoice(MenuObject)
{
	if(MenuObject.options[0].selected == false)
		document.forms[0].submit();
}


// load images from myImages array
function preloadImages(){
   myPosition = 0;
   while (myPosition < myImages.length){
	eval("var Preloaded" + myPosition + " = new Image()");
	eval("Preloaded" + myPosition + ".src = myImages[" + myPosition + "]");
	myPosition++;
   }
}


// execute statements from myLoads array
function execOnload(){
   for (myPosition = 0; myLoads.length > myPosition; myPosition++) eval(myLoads[myPosition]);
}


// determine if "Enter" has been pressed
function pressEnter(myCall){
   if (navigator.appName != 'Microsoft Internet Explorer') return false;
   if (navigator.platform.indexOf("Win") == '-1') return false;

   if (window.event.keyCode != 13) window.event.returnValue = true;
   else {
	eval(myCall);
	window.event.returnValue = false;
   }
}


// simulate "press button" event
function pressButton(myButtonName,myButtonValue){
   myForm = document.forms[0];
   myForm._RESERVED_.value = myButtonValue;
   myForm._RESERVED_.name = myButtonName;
   myForm.submit();
}


// build URL of an image considering protocol and preview state
function makeImageURL(myImageURL){
   if ((PreviewState == 'preview') && (myImageURL.substr(0,8) == '/members')) myImageURL = '/preview' + myImageURL;
   if (myImageURL.substr(0,4) != 'http') myImageURL = 'http://www.storesonline.com' + myImageURL;
   return myImageURL;
}


// build an IMG tag for images displayed through image wrapper
function makeImage(myImageURL,myMaxWidth,myMaxHeight,myAttributes){
   if (!myImageURL) return false;

   myImageURL = makeImageURL(myImageURL);

   if (myImageURL.match(/gif$/i)) myImageFormat = '&output=gif';
   else myImageFormat = '';
   
   myMaxHeight = (myMaxHeight) ? '&picture.height.max=' + myMaxHeight : '';
   myMaxWidth = (myMaxWidth) ? '&picture.width.max=' + myMaxWidth : '';

   if (!myAttributes) myAttributes = '';
   else myAttributes = " " + myAttributes;

   theImage = '<IMG SRC="' + myProtocol + '://www.storesonline.com/images/common/imagewrap.img?picture.image.url=' + myImageURL + myImageFormat + myMaxHeight + myMaxWidth +'"' + myAttributes + '>';
   return theImage;
}


// build spacer image
function drawSpacer(myWidth,myHeight){
	if (!myWidth) myWidth = '1';
	if (!myHeight) myHeight = '1';
	mySpacer = "<IMG SRC=" + myProtocol + "://www.storesonline.com/images/common/shim.gif BORDER=0 WIDTH=" + myWidth + " HEIGHT=" + myHeight + ">";
	return mySpacer;
}


// build number image for form elements
function drawFormNumber(inNumber,inNumColor,inBgColor,inStageColor){
	var myAttributes = '';
	if (inNumber) myAttributes += 'label.text=' + inNumber + '&';
	if (inNumColor) myAttributes += 'label.fill.color=' + inNumColor + '&';
	if (inBgColor) myAttributes += 'background.fill.color=' + inBgColor + '&';
	if (inStageColor) myAttributes += 'stage.color=' + inStageColor + '&';
	var myNumber = '<IMG BORDER=0 SRC='+ myProtocol + '://www.storesonline.com/images/common/number.img?' + myAttributes + '>';
	return myNumber;
}


// split <A HREF>Link</A> syntax into HREF and Link
function splitLink(myCombValue){
   if (!myCombValue || (myCombValue == '')) return false;
   var myURL = myCombValue.slice(9, myCombValue.indexOf(">") - 1);
   var myName = myCombValue.slice(myCombValue.indexOf(">") + 1, myCombValue.indexOf("</A>"));
   return Array(myURL,myName);
}


// build complete SELECT tag of a fixed-width drop-down box
function makeDropBox(myDropBox,myDelimiter,myWidth){
   if ((myDropBox == '') || (myDelimiter == '') || (myWidth == '')) return false;

   myDelimiter = Number(myDelimiter);
   myWidth = Number(myWidth);
   myDropBox = unescape(myDropBox);

   myDropBox = myDropBox.slice(myDropBox.indexOf(">")+1);
   myDropBox = myDropBox.slice(0,myDropBox.indexOf("</SELECT>"));
   myOptions = myDropBox.split("</OPTION>")
   myDropBox = '<SELECT NAME=EDIT_BROWSE WIDTH=' + myWidth + ' CLASS=formDText ONCHANGE="pressButton(\'NV-CMD-BROWSE\',\'Go\')">';

   for (var i in myOptions){
	  var Option = myOptions[i];
	  if (Option != ''){
	   myComponents = Option.split(">");
	   myComponents[0] = myComponents[0] + ">";
	   if (myComponents[1].length > myDelimiter) myComponents[1] = myComponents[1].slice(0,myDelimiter) + "...";
	   myDropBox += myComponents[0] + myComponents[1] + "</OPTION>";
	  }
   }

   myDropBox += "</SELECT>";
   return myDropBox;
}


// build opening Form tag for form.html page
function OpenFormTag(myServer,myPreview,myEntry){
	if (window.location.host.indexOf('.solint.net') >= 0){
		return "<FORM NAME=FORM_FORM METHOD=POST ACTION=https://" + myServer + "/" + myPreview + myEntry + ">";
	} else {
		return "<FORM NAME=FORM_FORM METHOD=POST ACTION=https://www.storesonline.com/" + myPreview + myEntry + ">";
	}
}

//pop up window
function OpenDaWindow(theURL,winName,features) 
{ 
	window.open(theURL,winName,features);
}

function recordStats(inAccount, inLocation)
{	
	var proto	 = window.location.protocol.slice(0, -1);
	var host	 = window.location.host;
	var time 	 = new Date();
	var referrer = window.document.referrer;
	var title	 = window.document.title;
	var location = inLocation  ? inLocation : window.location;
	var data	 = "";
	
	if(document.forms[0])
	if(document.forms[0].ST_DATA)
	if(document.forms[0].ST_DATA.value)
		data = document.forms[0].ST_DATA.value;
	
	var url 	 = proto + "://" + host + "/stats/" + inAccount + "/" + time.getTime() + "?" +
				  (PreviewState 		? "&p=" + PreviewState : "") +
				  (location 			? "&l=" + escape(location) : "") +
				  (referrer 			? "&r=" + escape(referrer) : "") +
				  (title	 			? "&t=" + escape(title) : "") +
				  ((data.length > 0)	? "&ST_DATA=" + data : "");
			    
	document.write('<img src="'+ url +'" width=1 height=1 border=0>');
}

