// JavaScript Document
var StarNR = 0;

var BackVar = '';var testCheckVal = 0
var the_fontSize;
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
//if (!IE) document.captureEvents(Event.MOUSEMOVE)

var tempX = 0
var tempY = 0

var sideRSIDS = '';

document.onmousemove = function (event) {
if (!event) { 
event = window.event;
}
tempX = event.clientX;
tempY = event.clientY + document.documentElement.scrollTop;
}

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = update_mouse_coords()

function validateEmail(str){
	//var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var emailReg = ".+@.+\\.[a-z]+";
	var regex = new RegExp(emailReg);
	return regex.test(str);
}

function goPage(pageNR){
	document.getElementById('PageNr').value = pageNR;
	document.getElementById('doSort').submit();	
}
function getMouseX(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  
  return tempX
  
}

function getMouseY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  
  //return tempX
  return tempY
  
}


	function ErrorReportSize(){
		document.getElementById('theFeil').style.top = (document.body.offsetHeight / 2) - 200;
		document.getElementById('theFeil').style.left = (document.body.offsetWidth / 2) - 200;
	}
	function ShowErrorReport(){
		ErrorReportSize();
		document.getElementById('theFeil').style.display = 'block';
	}
function changeCurrency(theCurrency){
	var y = -1
	for (x in myCurrency2){
		if(theCurrency == myCurrency2[x]){
			y = x;		
		}
	}
	if (y > -1){
	for (i=0; i<document.all('RS_val').length; i++) {
		if(document.all('RS_val',i)){
			if(y==0)
			{document.all('RS_val',i).innerHTML = formatCurrency(document.all('RS_val2',i).value,false);
			document.getElementById('CurrencyFormat').innerHTML = myCurrency2[y];
			}
			else
			{document.all('RS_val',i).innerHTML = formatCurrency( Math.round((document.all('RS_val2',i).value / (myCurrency[y]/100))*100)/100 );
			document.getElementById('CurrencyFormat').innerHTML = myCurrency2[y] + ' à kurs ' + myCurrency[y];
			}
		}
	}
	}
}


function showHelpBox(inText){
	var HelpBox = document.getElementById('HelpBox');	
	HelpBox.innerHTML = inText;
	
	if(inText=='')
		{HelpBox.style.display = 'none';}
	else
		{
			HelpBox.style.display = 'block';
			HelpBox.style.top = tempY+20  + 'px';
			HelpBox.style.left = tempX+10 + 'px';
		}
}

function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}


function formatCurrency(num,showCent) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	num = num + ''
	num = num.replace(/,/,'.')
	
	if(num=='0'){sign=1}
	
	if(showCent==false)
	return (((sign)?'':'-') + '' + num);
	else
	return (((sign)?'':'-') + '' + num);
}

function testCheck(){
	testCheckVal = 0;
	if(document.all){
	for (i=0; i<document.all('RSID').length; i++) {
		if(document.all('RSID',i)){
			if(document.all('RSID',i).checked == true){
				testCheckVal++	
			}
		}
	}

	if(testCheckVal<1){
		document.getElementById('samanlikna').disabled = true;
	}else{
		document.getElementById('samanlikna').disabled = false;
	}
	}
	else
	{
		
		document.getElementById('samanlikna').disabled = false;	
	}
}
	
function changeImg(theElement,newImg) {
  var elementCount = document.all(theElement).length;
  for (i=0; i<elementCount; i++) {
    document.all(theElement,i).src = newImg;
	//alert('imgNr:' + i)
  }
}
function changeStar(theLink,theImg,newHref,newImg,ListNr,OBID) {
	for(i=0;i<100;i++){
		if(document.getElementById(theLink + '_' + i)){
			document.getElementById(theLink + '_' + i).href = "javascript:FavClick('" + OBID + "','" + ListNr + "','" + newHref + "')";
			document.getElementById(theImg + '_' + i).src = newImg;
		}
	}
}


function FavClick(OBID,ListNr,action){
	var theLink = 'list' + ListNr + '_' + OBID + '_link';
	var theImg = 'list' + ListNr + '_' + OBID + '_img';
	
	if(action=='add')
	{
	var newImg = 'images/star' + ListNr + '_on.png'
	if(ListNr=='10'){newImg='images/starSl.png'}
	var newHref = 'remove'
  	var temp2 = "changeStar('" + theLink + "','" + theImg + "','" + newHref + "','" + newImg + "','" + ListNr + "','" + OBID + "')"
	var temp = setTimeout(temp2,250);	
	}
	else if(action=='remove')
	{
	var newImg = 'images/star' + ListNr + '_off.png'
	if(ListNr=='10'){newImg='images/starSl.png'}
	var newHref = 'add'
	changeStar(theLink,theImg,newHref,newImg,ListNr,OBID);
	}
	AjaxGet('includes/theList.asp?OBID=' + OBID + '&ListNr=' + ListNr + '&action=' + action, 'theList','');
	

	
	//alert(temp2)

}

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	var theLenght = Len(charSearchFor);
	
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, theLenght))
	    {
			return i;
	    }
	}
	return -1;
}

function Mid(str, start, len)
{
		if (start < 0 || len < 0) return "";

		var iEnd, iLen = String(str).length;
		if (start + len > iLen)
				iEnd = iLen;
		else
				iEnd = start + len;

		return String(str).substring(start,iEnd);
}

function Len(str)
{  return String(str).length;  }



function getkey()
{
	return event.keyCode;
}


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function elementExists(elemName)
{
	if (document.getElementById(elemName))
		{return true}
	else
		{return false}
}







function getMouseX_OLD(e){
	var tempX = event.clientX + document.body.scrollLeft
	if (tempX < 0){tempX = 0}
	return tempX;
}
function getMouseY_OLD(e){
	var tempY = event.clientY + document.body.scrollTop
	if (tempY < 0){tempY = 0}
	return tempY;	
}

function isdefined(property) {
  return (typeof property != 'undefined');
}



function getElementHeight(Elem) {
	
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		
		xPos = elem.offsetHeight;
		
		return xPos;
	
}


function regReplace(inString,inRegExpr,inReplace) {
  var re = new RegExp(inRegExpr, "gi");
  return inString.replace(re,inReplace);
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

if(readCookie('fontSize') == null){
	createCookie('fontSize',10,7);
}else{
	the_fontSize = readCookie('fontSize');
}




function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}


