if( document.implementation.hasFeature("XPath", "3.0") )
{
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

}

var base = document.getElementsByTagName ("base");
var httpUrl = base[0].href + 'isapi/isapi.dll';
var xmlHttp;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function BuildXmlHttpReference ()
{
	if (typeof (XMLHttpRequest) != 'undefined')
		xmlHttp = new XMLHttpRequest();
	else 
	{
		try 
		{
			xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch (e) 
		{
			try 
			{
				xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert (e.message);
			}
		}
	}
}

function round_decimal (number, precision) {
	var value,i

	value = Math.round (number * Math.pow(10,precision))
	value = ""+value

	len = value.length
	if (len <= precision) {
		for (i=0; i<precision-len; i++)
			value = "0"+value
		value = "0." + value
	} else
		value = value.substring(0,len-precision)+"."+value.substring(len-precision,len)

	return value
}

function check_price (obj) {
	price = parseFloat (obj.value);
	if (isNaN(price) || price < 0) {
		alert (invalid_price);
	} else
		obj.value = round_decimal(price,2)
}

function confirm_delete (delete_message) {
	return confirm(delete_message);
}

function row_changed (theform,row) {
	theform.elements['row_changed_'+row].value = "yes";
}

function goto_page(theform,page) {
	theform.current_page.value = page;
	theform.submit();
}

function add_product (theform)
{
	var total_product = parseInt (theform.total_product.value, 10);
	var selected_product = -1;

	if (arguments.length > 1)
	{
		selected_product = arguments[1];
		theform.elements['add_'+selected_product].disabled = true;
	}

	for (i=0; i<total_product; i++)
	{
		if (theform.elements['qty_'+i].value != "")
		{
			quantity = parseFloat (theform.elements['qty_'+i].value);
			if (isNaN (quantity) || quantity <= 0)
			{
				alert (invalid_quantity);
				if (selected_product >= 0)
				{
					theform.elements['add_'+selected_product].disabled = false;
				}
				return false;
			}
		}

		if (selected_product == i)
		{
			if (theform.elements['qty_'+i].value == "")
			{
				alert (invalid_quantity);
				theform.elements['add_'+selected_product].disabled = false;
				return false;
			}
		}
	}

	if (selected_product >= 0)
	{
		theform.elements['add_'+selected_product].disabled = false;
	}

	return true;
}

function isCreditCard(st) {
	if (st.length > 19)
		return (false);
	if (st.length < 13)
		return false;

	var sum = 0; var mul = 1; var l = st.length;
	var tproduct; var digit; var i;
	for (i = 0; i < l; i++) {
			digit = st.substring(l-i-1,l-i);
			tproduct = parseInt(digit ,10)*mul;
			if (tproduct >= 10)
				sum += (tproduct % 10) + 1;
			else
				sum += tproduct;
			if (mul == 1)
				mul++;
			else
				mul--;
	}

	if ((sum % 10) == 0)
			return (true);
	else
			return (false);
}

function stripCharsInBag (s, bag)
{
	var i;
	var returnString = "";

		for (i = 0; i < s.length; i++)
		{
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}

		return returnString;
}

function copyValue (f) {
	if (typeof(document.all("editorctl")) != "undefined") {
		var string = editorctl.DocumentHTML;
		if (arguments.length > 1)
		{
			string = string.replace (/\'/g,"&#039");
			string = string.replace (/\r\n/g, "");
		}
		f.elements.description.value = string;
		return true;
	} else
		return false;
}

function format_number (number, sep)
{
	n = number.toString().split ('.');

	p1 = n[0];
	if (n.length == 1)
		p2 = '00';
	else
		p2 = n[1];
	p3 = '';
	len = p1.length;
	j = 0;

	for (i=len-1; i>=0; i--)
	{
		p3 =  p1.charAt (i) + p3;
		j++;
	
		if (j % 3 == 0 && i > 0)
		{
			p3 = sep + p3;
		}
	}

	if (sep == '.')
	{
		p3 += ',' + p2;
	} else
		p3 += '.' + p2;

	return p3;
}

function get_banner (banner_num) {
	
	var url = httpUrl + '?get_banner&banner_num='+banner_num;
	BuildXmlHttpReference ();

	if (xmlHttp)
	{
		xmlHttp.open ("GET", url, false);
		xmlHttp.send (null);
		var xmldoc = xmlHttp.responseXML;

		var id, file_type, file_name, target, width, height, alt;

		if (xmldoc.selectSingleNode ("/root/banner") != null)
		{
			if( document.implementation.hasFeature("XPath", "3.0") ) {
				id = xmldoc.selectSingleNode ("/root/id").textContent;
				file_type = xmldoc.selectSingleNode ("/root/banner/file_type").textContent;
				file_name = xmldoc.selectSingleNode ("/root/banner/file_name").textContent;
				if (xmldoc.selectSingleNode ("/root/banner/width") != null)
				{
					width = xmldoc.selectSingleNode ("/root/banner/width").textContent;
				}
				if (xmldoc.selectSingleNode ("/root/banner/height") != null)
				{
					height = xmldoc.selectSingleNode ("/root/banner/height").textContent;
				}
				if (xmldoc.selectSingleNode ("/root/banner/alt") != null)
				{
					alt = xmldoc.selectSingleNode ("/root/banner/alt").textContent;
				}
				if (xmldoc.selectSingleNode ("/root/banner/target") != null)
				{
					target = xmldoc.selectSingleNode ("/root/banner/target").textContent;
				}

			} else {
				id = xmldoc.selectSingleNode ("/root/banner/id").text;
				file_type = xmldoc.selectSingleNode ("/root/banner/file_type").text;
				file_name = xmldoc.selectSingleNode ("/root/banner/file_name").text;
				if (xmldoc.selectSingleNode ("/root/banner/width") != null)
				{
					width = xmldoc.selectSingleNode ("/root/banner/width").text;
				}
				if (xmldoc.selectSingleNode ("/root/banner/height") != null)
				{
					height = xmldoc.selectSingleNode ("/root/banner/height").text;
				}
				if (xmldoc.selectSingleNode ("/root/banner/alt") != null)
				{
					alt = xmldoc.selectSingleNode ("/root/banner/alt").text;
				}
				if (xmldoc.selectSingleNode ("/root/banner/target") != null)
				{
					target = xmldoc.selectSingleNode ("/root/banner/target").text;
				}
			}

			if (file_type == "image")
			{
				document.write ("<a href="+httpUrl+"?clickad&id="+id);
				if (alt != "")
				{
					document.write (' alt="'+alt+'"');
				}

				if (target != "")
				{
					document.write (' target="'+target+'"');
				}
				
				document.write ("><img border=0 src="+base[0].href+"banners/"+file_name+"></a>");
			} else {
				document.writeln ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0" width="'+width+'" height="'+height+'">');
				document.writeln ('<param name="movie" value="'+base[0].href+'banners/'+file_name+'"/>');
				document.writeln ('<embed src="'+base[0].href+'banners/'+file_name+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed></object>');
			}
		}
	}
}


function init_pos ()
{
	var content = document.getElementById ("content");
//	var content_wrapper = document.getElementById ("content_wrapper");
//	content_wrapper.style.height = content.offsetHeight+50;
}
