
function previewImage(img_name,obj) {
  var pic = "../../transp.gif";
  if(obj.selectedIndex != 0)
	pic = obj.options[obj.selectedIndex].text;
  preLoad = new Image();
  eval('preLoad.src = "/images/products/small/'+pic+'";');
  eval('document.images.'+img_name+'.src = preLoad.src;');
}

function getURL(frame,url) {
	eval('top.'+frame+'.location=\''+url+'\';');
}

var unhighlight;

function highlightRow(objID, color) {
  if(!color) color = 'dddddd';
  var normal_color = 'ffffff';
  if( unhighlight && unhighlight != objID )
  	highlightRow(unhighlight, normal_color);
  //
  objStyle = (document.getElementById) ? document.getElementById(objID).style : (document.all) ? document.all[objID].style : document.layers[objID];
  objStyle.background = '#'+color;
  unhighlight = objID;
  // if( objStyle.background == 'none') objStyle.display = 'block';

}

function toggleElement(objID) {
  objStyle = (document.getElementById) ? document.getElementById(objID).style : (document.all) ? document.all[objID].style : document.layers[objID];
  // objStyle.visibility = (isShow) ? 'visible' : 'hidden';
  if( objStyle.display == 'none') objStyle.display = 'block';
  else objStyle.display = 'none';
  // objStyle.display = (objStyle.display) ? 'none' : 'block';
}

function ShowHideElement(objID, show) {
  objStyle = (document.getElementById) ? document.getElementById(objID).style : (document.all) ? document.all[objID].style : document.layers[objID];
  // objStyle.visibility = (isShow) ? 'visible' : 'hidden';
  if( show ) objStyle.display = 'block';
  else objStyle.display = 'none';
  // objStyle.display = (objStyle.display) ? 'none' : 'block';
}

function confirmBox(msg, url) {
	if( !confirm(msg) ) return;
	document.location = url;
}

function setValue(field,value) {
	eval('document.forms.product.'+field+'.value = \''+value+'\';');
}


/** creates a new FileUploader
 * @arg aInserID a page element ID to insert the FileUploader into.
 * @arg aFormInputURL a URL of an html file containing a form.
 * @arg aSelectElementID a page element ID of a select list to insert an option in to, on success
 */
function FileUploader(aInsertID, aFormInputURL, aSelectElementID) {
	window.selectElementID = aSelectElementID;
	this.insertID = aInsertID;
	this.formInputURL = aFormInputURL;
	this.selectElementID = aSelectElementID;
	this.build();
}

function init_selectBox(aSelectElementID) {
	window.selectElementID = aSelectElementID;
}

FileUploader.prototype.build 			= FileUploader_build;

function FileUploader_build() {
	//todo:
	this.iframe = document.createElement("iframe");
	this.iframe.style.width 	= 350;
	this.iframe.style.height	= 25;
	this.iframe.name = "iframe" + new Date().getTime();
	this.iframe.style.border	= "none";
	this.iframe.frameborder		= 0;
	this.iframe.style.overflow  = "hidden";
	$(this.insertID).appendChild(this.iframe);
	if (BrowserDetect.browser=="Explorer") {
		this.iframe.src = this.formInputURL;
    } else {
   		window.frames[this.iframe.name].location.href = this.formInputURL;
    }
}

function addFileElementToSelect(field_name, value, label) {
	var option = document.createElement("option");
	option.value = value;
	option.innerHTML = label;
	/*
	// var obj = field_name + 'Uploader';
	// eval('$('+obj+'.selectElementID).appendChild(option);');
	$(window.selectItems[field_name]).appendChild(option);
	*/
	$(window.selectElementID).appendChild(option);
}

function ElementSelect(field_name, value) {
	if( confirm(value + ' uploaded, select it?') ) {
		$(field_name).value = value;
		// $(window.selectElementID).value = value;
	}
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


/**
 * Handles the selection of an element on the HTML monitor/browser
 * and sends the POST request back to the server to update the page
 *
 */
function __doPostBack(changed_element, eventArgument) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.item_browser;
	
	} else {
		theform = document.forms["item_browser"];
	}
	theform._ChangedElement.value = changed_element.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}
	
	