var atSell=false;
function get_object(o) {
	if (document.getElementById && document.getElementById(o) != null)
		return document.getElementById(o);
	else if (document.layers && document.layers[object] != null)
		return document.layers[o];
	else if (document.all)
		return document.all[o];
}
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 resetChecked(theRadioOrCheckbox) {
	for (i=0;i<theRadioOrCheckbox.length;i++) {
		theRadioOrCheckbox[i].checked=false;
	}
}
function doScroll(theId) {
	o=get_object(theId);
	var desty=o.offsetTop;
	var thisNode=o;
	while (thisNode.offsetParent && (thisNode.offsetParent != document.body)) {
		thisNode=thisNode.offsetParent;
		desty+=thisNode.offsetTop;
	}
	window.scrollTo(0,desty);
}
function popupImg(theImg) {
	window.open('popup.cfm?theImg='+theImg,'','width=100,height=100,menubar=0,scrollbars=0,status=0,location=0,directories=0,resizable=0,titlebar=0,toolbar=0');
}
function openPopupArticle(pid) {
	var popupWidth=650;
	var popupHeight=600;
	if (window.screen) {
		w=window.screen.availWidth;
		h=window.screen.availHeight;
		if (w > popupWidth)
			popupLeft=parseInt(w/2-(popupWidth/2));
		else
			popupLeft=0;
		if (h > popupWidth)
			popupTop=parseInt(h/2-(popupHeight/2));
		else
			popupTop=0;
	} else {
		popupLeft=0;
		popupTop=0;
	}
	window.open('popupArticle.cfm?pid='+pid,'','status=no,toolbar=no,location=no,menu=no,resizable=yes,scrollbars=yes,top='+popupTop+',left='+popupLeft+',width='+popupWidth+',height='+popupHeight);
}
function getCheckedRadioValue(theRadio) {
	for (i=0;i<theRadio.length;i++) {
		if (theRadio[i].checked)
			return theRadio[i].value;
	}
	return '';
}
function getCheckedValues(theCheckbox,theReturnType) {
	switch (theReturnType) {
		case 'list':
			var theList='';
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked) {
						if (theList.length > 0)
							theList=theList+',';
						theList=theList+theCheckbox[i].value;
					}
				}
			else if (theCheckbox.checked)
				theList=theCheckbox.value;
			return theList;
		break;
		case 'count':
			var checkedCount=0;
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked)
						checkedCount++;
				}
			else if (theCheckbox.checked)
				checkedCount++;
			return checkedCount;
		break;
		case 'boolean':
			if (theCheckbox[0])
				for (i=0;i<theCheckbox.length;i++) {
					if (theCheckbox[i].checked) {
						return true;
						break;
					}
				}
			else if (theCheckbox.checked)
				return true;
		break;
	}
	return false;
}
function checkCheckbox(theCheckbox,theValue) {
	if (theCheckbox[0]) {
		for (i=0;i<theCheckbox.length;i++) {
			if (theCheckbox[i].value == theValue) {
				theCheckbox[i].checked=true;
				break;
			}
		}
	} else if (theCheckbox.value == theValue) {
		theCheckbox.checked=true;
	}
}
Array.prototype.inArray=function (value,caseSensitive) {
	var i;
	for (i=0;i<this.length;i++) {
		if (caseSensitive) {
			if (this[i].toLowerCase() == value.toLowerCase())
				return true;
		} else {
			if (this[i] == value)
				return true;
		}
	}
	return false;
}
function doArticleHelp(theId) {
	o=get_object('div_articleHelp_'+theId);
	o.style.display=(o.style.display == 'none')?'block':'none';
}
function doMenuLink(theHref) {
	if (atSell)
		doSellUnlink(theHref);
	else
		window.location.href=theHref;
}
function isConfirmed(theMessage) {
	if (confirm(theMessage))
		return true;
	else
		return false;
}
function restoreInteger(theField) {
	theField.value=theField.value.replace(/[^\d]/g, "");
}
function restoreNumeric(theField) {
	theField.value=theField.value.replace(",",".");
	theField.value=theField.value.replace(/[^\d.]/g, "");
}
function setFieldHelp(theField,theAction,theHelp) {
	switch (theAction) {
		case 'clear':
			if (theField.value == theHelp)
				theField.value='';
		break;
		case 'fill':
			if (theField.value.length == 0)
				theField.value=theHelp;
		break;
	}
}
// Removes leading whitespaces
function LTrim(value) {
	var re=/\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim(value) {
	var re=/((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim(value) {
	return LTrim(RTrim(value));
}
function addOption(theSelect,theValue,theText) {
	var theOption=new Option(theText, theValue, false, false)
	var selectLength=theSelect.length;
	theSelect.options[selectLength]=theOption;
}
function emailValidation(theEmail) {
	emailLength=theEmail.length;
	indexOfAlpha=theEmail.indexOf('@');
	lenBetweenAlphaAndNextDot=theEmail.indexOf('.',indexOfAlpha)-indexOfAlpha-1;
	lenDomain=emailLength-theEmail.lastIndexOf('.')-1;
	//the email address lenght must be at least 8 characters (ab@cd.ef)
	if (emailLength < 8) {
		return false;
	//the @ can occur at index 2 as earliest, -1 is returned if it don't exist at all
	} else if (indexOfAlpha < 2) {
		return false;
	//the first . after @ must occur at least 2 indexes later
	} else if (lenBetweenAlphaAndNextDot < 2) {
		return false;
	//the domain name must be at least 2 characters
	} else if (lenDomain < 2) {
		return false;
	} else {
		return true;
	}
}
function idExist(theID) {
	if (document.all) {
		if (document.all[theID])
			return true;
		else
			return false;
	} else if (document.getElementById) {
		if (document.getElementById(theID))
			return true;
		else
			return false;
	} else {
		return false;
	}
}
function isInt(theValue) {
	if (theValue.length == 0)
		return false;
	else if (isNaN(theValue) || theValue.indexOf(',') > 0 || theValue.indexOf('.') > 0)
		return false;
	else
		return true;
}
function replaceBadMSWordCharacter(theField) {
	theField.value=theField.value.replace(/\u201A/g,"'");//baseline single quote
	theField.value=theField.value.replace(/\u0192/g,'<i>f</i>');//florin (small letter f with hook)
	theField.value=theField.value.replace(/\u201E/g,'"');//baseline double quote
	theField.value=theField.value.replace(/\u2026/g,'...');//ellipsis (3 horisontal ellipsis)
	theField.value=theField.value.replace(/\u2020/g,'&sup1');//dagger (cross)
	theField.value=theField.value.replace(/\u2021/g,'&sup2');//double dagger (cross with two horisontal lines)
	theField.value=theField.value.replace(/\u02C6/g,'^');//circumflex accent
	theField.value=theField.value.replace(/\u2030/g,'o/oo');//permile (as procent sign, but with double zeros)
	theField.value=theField.value.replace(/\u0160/g,'Sh');//S Hacek
	theField.value=theField.value.replace(/\u2039/g,'"');//left single guillemet (single left-pointing angle quotation mark)
	theField.value=theField.value.replace(/\u0152/g,'OE');//OE ligature
	theField.value=theField.value.replace(/\u2018/g,"'");//left single quote
	theField.value=theField.value.replace(/\u2019/g,"'");//right single quote
	theField.value=theField.value.replace(/\u201C/g,'"');//left double quotation mark
	theField.value=theField.value.replace(/\u201D/g,'"');//right double quotation mark
	theField.value=theField.value.replace(/\u2022/g,"*");//bullet
	theField.value=theField.value.replace(/\u2013/g,"-");//endash
	theField.value=theField.value.replace(/\u2014/g,"--");//emdash
	theField.value=theField.value.replace(/\u02DC/g,'~');//tilde accent
	theField.value=theField.value.replace(/\u2122/g,'<sup>TM</sup>');//trademark ligature
	theField.value=theField.value.replace(/\u0161/g,'sh');//s Hacek
	theField.value=theField.value.replace(/\u203A/g,'"');//right single guillement  (single right-pointing angle quotation mark)
	theField.value=theField.value.replace(/\u0153/g,'oe');//oe ligature
	theField.value=theField.value.replace(/\u0178/g,'Y');//Y Dieresis
}

Array.prototype.removeItems=function(itemsToRemove) {
	if (!/Array/.test(itemsToRemove.constructor))
		itemsToRemove=[itemsToRemove];
	var j;
	for (var i=0;i<itemsToRemove.length;i++) {
		j=0;
		while (j < this.length) {
			if (this[j] == itemsToRemove[i])
				this.splice(j,1);
			else
				j++;
		}
	}
}

function enterKey(e) {
	if (e.keyCode == 13)
		return true;
	else
		return false;
}
function cloneArray(arr,removeBlankSpots) {
	var newArr=new Array();
	if (removeBlankSpots)
		for (var i=0;i<arr.length;i++) {
			if (arr[i].length > 0)
				newArr[i]=arr[i];
		}
	else
		for (var i=0;i<arr.length;i++) {
			newArr[i]=arr[i];
		}
	return newArr;
}
var activeHelpDivName='';
function doHelp() {
	if (activeHelpDivName != '')
		get_object(activeHelpDivName).style.visibility='hidden';
	if (doHelp.arguments[0]) {
		activeHelpDivName=doHelp.arguments[0];
		evt=doHelp.arguments[1];
		var positionOnRightSideOfMouse=false;
		if (doHelp.arguments[2])
			positionOnRightSideOfMouse=true;
		o=get_object(activeHelpDivName);
		o.style.visibility='visible';
		o.style.top=(parseInt(mouseY(evt))+offY-Math.ceil(o.offsetHeight/2))+'px';
		//document.onmousemove=follow;
		if (positionOnRightSideOfMouse)
			o.style.left=(parseInt(mouseX(evt))-offX-10-o.offsetWidth)+'px';
		else
			o.style.left=(parseInt(mouseX(evt))+offX)+'px';
	} else {
		activeHelpDivName='';
	}
}
var offX=22;
var offY=0;
function mouseX(evt) {
	if (!evt)
		evt=window.event;
	if (evt.pageX)
		return evt.pageX;
	else if (evt.clientX)
		return evt.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);
	else
		return 0;
}
function mouseY(evt) {
	if (!evt)
		evt=window.event;
	if (evt.pageY)
		return evt.pageY;
	else if (evt.clientY)
		return evt.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop);
	else
		return 0;
}
/*
function stopFollow() {
	document.onmousemove=null;
	helpActive=false;
	get_object(activeHelpDivName).style.visibility='hidden';
}
// // Simple follow the mouse script
// copyright Stephen Chapman, 30th September 2005
// you may copy this script provided that you retain the copyright notice
function follow(evt) {
	o=get_object(activeHelpDivName);
	o.style.left=(parseInt(mouseX(evt))+offX)+'px';
	o.style.top=(parseInt(mouseY(evt))+offY-Math.ceil(o.offsetHeight/2))+'px';
	//get_object('debug').innerHTML=o.offsetHeight;
}
*/
function doLink() {
	var theURL=doLink.arguments[0];
	var openInNewWindow=false;
	if (doLink.arguments[1])
		openInNewWindow=doLink.arguments[1];
	if (window.location.href.indexOf('/sell.cfm') != -1)
		confirmLeaveAd(theURL,openInNewWindow);
	else if (openInNewWindow)
		window.open(theURL);
	else
		window.location.href=theURL;
}
function FormatSEK(amount,CommaDelimiter) {
   try 
   {
  
        amount = parseInt(amount);

        var samount = new String(amount);

        if (samount.length < 3) { return 0; }  

        samount =  samount.substring(0,samount.length -2);
             
        for (var i = 0; i < Math.floor((samount.length-(1+i))/3); i++)
        {
           samount = samount.substring(0,samount.length-(4*i+3)) + CommaDelimiter + samount.substring(samount.length-(4*i+3));
         }

   }
    catch (exception) { AlertError("Format Comma",e); }
    return samount;
}
function FormatClean(num) {
     var sVal='';
     var nVal = num.length;
     var sChar='';
     
   try
   {
       for(i=0;i<nVal;i++)
      {
         sChar = num.charAt(i);
         nChar = sChar.charCodeAt(0);
         if ((nChar >=48) && (nChar <=57))  { sVal += num.charAt(i);   }
      }
   }
    catch (exception) { AlertError("Format Clean",e); }
    return sVal;
}
function getFormated(theNum) {
	var num=theNum;
	var sVal='';
	var minus='';
	var Decimal=','
	var dot='.';
	if (num.lastIndexOf("-") == 0) { minus='-'; }
	if (num.lastIndexOf(Decimal) < 0) { num = num + '00'; }
	num = FormatClean(num);
	sVal = minus + FormatSEK(num,dot);
	return sVal;
}
function openInstruction(theSwf,theWidth,theHeight) {
	window.open(theSwf,'','width='+theWidth+',height='+theHeight+',resizable=yes');
}


//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}




