var tdThAmountStatic = null;

function CalcMixedPayment(obj){ 

  var tdErr = document.getElementById("tdErr");
  tdErr.innerText = "";

  var rExp = new RegExp(".","gi");
  var tdAmount = document.getElementById("tdAmount");
  var tdThAmount = document.getElementById("tdThAmount");
  var tdCredCardAmt = document.getElementById("tdCredCardAmt");

  if(!tdThAmountStatic){
    tdThAmountStatic = tdThAmount.innerText;
  }

  
  try{
    if(parseFloat(obj.value)){
      var val = parseFloat(obj.value);    
      if(val > parseFloat(tdAmount.innerText)){
         val = parseFloat(tdAmount.innerText);  
      }
      else if(val < 0){
       val = 0; 
      }
    }
    else{
      val = parseFloat(tdAmount.innerText);  
    }
  }
  catch(e){
    val = 0;//parseFloat(tdAmount.innerText);
  }
  
  
  if(obj.value == ""){
    val = "0";
    // If amount > thaccount balance
    if(parseFloat(tdAmount.innerText) - parseFloat(val) > parseFloat(tdThAmountStatic)){
      tdErr.innerText = "TH account does not cover chosen transaction amount";
      val = (parseFloat(tdAmount.innerText) - parseFloat(tdThAmountStatic));
    }     
    tdThAmount.innerText = (parseFloat(tdAmount.innerText) - parseFloat(val));
    tdCredCardAmt.innerText = val;        
  }
  else{ 
    // If amount > thaccount balance
    if(parseFloat(tdAmount.innerText) - parseFloat(val) > parseFloat(tdThAmountStatic)){
      tdErr.innerText = "TH account does not cover chosen transaction amount";
      val = (parseFloat(tdAmount.innerText) - parseFloat(tdThAmountStatic));
    }    
    tdThAmount.innerText = (parseFloat(tdAmount.innerText) - parseFloat(val));
    tdCredCardAmt.innerText = val;
  }
  //obj.value = val;
  document.getElementById('TRANSAMOUNT').value = tdThAmount.innerText;
}    
      
function SubmitMixedPayment(obj,docid){
  var tdCredCardAmt = 0;
  try{
    var tdCredCardAmt = document.getElementById("tdCredCardAmt").innerText;   
  }
  catch(e){
    var tdCredCardAmt = 0;
  }
    
  if(parseFloat(tdCredCardAmt) > 0){          
  	if(post(obj) != -1){
    		window.open('?doc=WWW.DIBSFWD&amp;docid='+docid, 'paywin', 'status,scrollbars,width=550,height=600,top=300,left=200');
    		return false;
  	}
  	else{
    		return false;
  	}
  }
  else{
    document.location.href("Default.aspx?doc=WWW.THPAY&docid="+docid);
    return false;
  }
  
}       

function lnk(it,search){
  if(it == "") return;
  var linkIt = it;
  if(linkIt.indexOf("ART") < 0) linkIt = escape("ART/"+it);
  else linkIt = escape(linkIt);
  url = '?doc=WWW.PRODDETAIL&search='+escape(search)+'&it='+linkIt;
  if(GetQuery('nodelevel',null)) url = ReplaceQuery("nodelevel",GetQuery('nodelevel',null),url,"replace");
  if(GetQuery('docref',null)) url = ReplaceQuery("docref",GetQuery('docref',null),url,"replace");
  if(GetQuery('folderid',null)) url = ReplaceQuery("folderid",GetQuery('folderid',null),url,"replace");
  location.href=(url);
}

function hlink(docid,search,code1){
  if(readCookie("list")>""){
    var link = readCookie("list")+"#"+docid;
    eraseCookie("list");
    createCookie("list",link,7);
  }
  url = "?doc=WWW.LOT&L=" + docid + "&s=" + escape(search) + "&c1=" + code1;
  document.location.href = url;
}

function saveLink(docid){
  if(readCookie("list")>""){
    var link = readCookie("list")+"#"+docid;
    eraseCookie("list");
    createCookie("list",link,7);
  }
}  
      
function pg(offset, handle){
  url = String(document.location.search);
  url = ReplaceQuery("handle",handle,url,"replace");
  url = ReplaceQuery("offset",offset,url,"replace");
  document.location.replace(url);
}

function largeImg(url){
  window.open(url,"pop","height=600,width=800,status=0,toolbar=0,menubar=0,scrollbars=1,location=no",true);
}

function search()
{  
  var url = String(document.location.search);  
  var strSearch = document.sForm.s.value;
  var strMode = document.sForm.sMode.value;  
  var rExp = new RegExp("'","gi");
  strSearch = strSearch.replace(rExp," ");   
  
  url = ReplaceQuery("lotno",null,url,"delete");       
  url = ReplaceQuery("s",escape(strSearch) ,url,"replace");   
  url = ReplaceQuery("doc","WWW.LOTMENU",url,"replace");     
  url = ReplaceQuery("handle","",url,"replace");     
  url = ReplaceQuery("offset","",url,"replace");     
  var strConditions = "";
  var strCondJs = "";
  var condArray = document.getElementsByName("fC");        
  if (condArray != null)
  {   
   for( var i = 0; i < condArray.length; i++)
   {
     var tmp = condArray[i];        
     
     if (tmp.checked == true)
     {
       strCondJs += "|" + tmp.value + "|";
       
       if (strConditions == "")
       	strConditions += tmp.value;              
       else
       	strConditions += "," + tmp.value;

     }
    }
  }  
   
  url = ReplaceQuery("cond",strConditions,url,"replace");     
  url = ReplaceQuery("condjs",strCondJs,url,"replace");     
  url = ReplaceQuery("smode",strMode,url,"replace");     
 
  document.location.href = url;
  return false;

}  
  
function folderLink(folder){
  var url = String(document.location.search);
  url = ReplaceQuery("include",folder,url,"replace");     
  url = ReplaceQuery("offset","",url,"replace");     
  url = ReplaceQuery("handle","",url,"replace");     
  document.location.href = url;
}   
  
function lotFilter(str, val){
  url = String(document.location.search);
  url = ReplaceQuery(str,val,url,"replace");
  url = ReplaceQuery("offset","",url,"replace");
  url = ReplaceQuery("handle","",url,"replace");
  url = escape(url);
  document.location.href=(url);
}

function lReplace(query,val){
  url = String(document.location.search);
  url = ReplaceQuery("offset",null,url,"delete");     
  url = ReplaceQuery("handle",null,url,"delete");   
  url = ReplaceQuery(query,val,url,"replace");
  document.location.replace(url); 
}

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) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); 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 go(node,folderid,docid,prog,url,type){
  if(!type){
    alert("Ingen presentasjons-visning valgt\nVelg en template fra rullegardinen i WebAdmin");
    return;
  }
  if(type && type.toUpperCase() != "URL" && prog == "?doc="){
    SubFolder(folderid, node);
    return;
  }
  if(String(folderid)=="") folderid = docid.substring(0,10);
  switch(type.toUpperCase()){
    case "URL" :
     // window.open(url,"_blank","height=500,width=800,status=0,toolbar=1,menubar=0,scrollbars=1,location=no,resizable=1");
    document.location.href=(url);
    break;
    default :
      var app = GetQuery('doc',prog);
      var code = GetQuery('code',prog);
      var mfr = GetQuery('mfr',prog);
      var url = document.location.search;
      if(!url || url == ""){
        url = '?folderid='+encodeURIComponent(folderid)+'&nodelevel='+node;
      }
      else{
      }
      url = ReplaceQuery("docid",null,url,"delete");
      url = ReplaceQuery("handle",null,url,"delete");
      url = ReplaceQuery("offset",null,url,"delete");
      url = ReplaceQuery("nodelevel",node,url,"replace");
      url = ReplaceQuery("folderid",encodeURIComponent(folderid),url,"replace");
      url = ReplaceQuery("docref",encodeURIComponent(docid),url,"replace");              
      if(code) url = ReplaceQuery("code",code,url,"replace");
      else url = ReplaceQuery("code",null,url,"delete");
      if(app != "") url = ReplaceQuery("doc",encodeURIComponent(app),url,"replace");
      else url = ReplaceQuery("doc",null,url,"delete"); 
      url = ReplaceQuery("search",null,url,"delete");     
      document.location.href=(url);
    break;
  }  
  return;
}

function g(lotid){
  var persist = document.getElementsByTagName("persist");
  var handle = persist[0].handle;
  var url = String(document.location);
  url = ReplaceQuery("handle",escape(handle),url,"replace");
  url = ReplaceQuery("doc","WWW.LOT",url,"replace");
  url = ReplaceQuery("l",lotid,url,"replace");
  document.location.href=(url);
}   
    
function sGo(query,value){
  var url = String(document.location);
  var a = "";
  var c1 = "";

  url = ReplaceQuery("c1",null,url,"delete"); 
  url = ReplaceQuery("c2",null,url,"delete"); 
  url = ReplaceQuery("c3",null,url,"delete"); 
  url = ReplaceQuery("offset",null,url,"delete");     
  url = ReplaceQuery("handle",null,url,"delete");   
  
  var qArray = value.split(",");
  if(qArray.length == 2){
    url = ReplaceQuery("c1",qArray[1],url,"replace");
    url = ReplaceQuery("a",qArray[0],url,"replace");
  }
  else if(qArray.length == 1){
    url = ReplaceQuery(query,value,url,"replace");
  }
  else{
   url = ReplaceQuery(query,value,url,"replace");
  }
  document.location.href=(url);
}    

function c2Go(query,value){
  var url = String(document.location);
  url = ReplaceQuery("c3",null,url,"delete"); 
  url = ReplaceQuery(query,value,url,"replace");
  url = ReplaceQuery("offset",null,url,"delete");     
  url = ReplaceQuery("handle",null,url,"delete");   
  document.location.href=(url);
}    

function c3Go(query,value){
  var url = String(document.location);
  url = ReplaceQuery(query,value,url,"replace");
  url = ReplaceQuery("offset",null,url,"delete");     
  url = ReplaceQuery("handle",null,url,"delete");   
  document.location.href=(url);
}    
function SubFolder(docid, nodelevel){
    // 1.) open folder
    // 2.) close folder
    var chk = document.getElementById(docid);
    if(chk){
      chk.innerHTML = "";
      chk.removeNode();
      return;
    }
    else{
      var url = "default.aspx?doc=WWW.SUBFOLDER&nodelevel="+nodelevel+"&docid="+docid;
      //Send to server
      var xmlHttp = XmlHttp();
      xmlHttp.open("GET", url, false);
      xmlHttp.send();
      var obj = event.srcElement;
      var container = obj.parentElement.parentElement;
      var subLevel = document.createElement("folder");
      container.insertBefore(subLevel,obj.parentElement.nextSibling);
      subLevel.id = docid;
      subLevel.innerHTML = xmlHttp.responseText;
    }
}

function post(obj){
 var frm = null;
 if(obj && obj.tagName.toUpperCase() == "FORM") frm = obj;
 if(!frm){
   var area = obj;
   while(area.parentNode){
     if(area.tagName.toUpperCase() == "FORM"){
       frm = area;
       break;
     }
     area = area.parentNode;
   }
 }
 else if(!frm) frm = window.event.srcElement;

 var x = buildPOST(frm);
 return false;
}

function unescapeHtml(id){
 var p = document.getElementById(id);  
 var txtC = p.textContent; 
 p.innerHTML = p.innerText;   
 if( p.innerHTML == "undefined" ){
   p.innerHTML = txtC;
 }
} 

function formatField(id){
 var p = document.getElementById(id);  
 var str = p.value;
 str = str.replace(/(\r\n|\r|\n)/g,  "<br/>");
 p.innerHTML = str;
} 
    
// function to build POST requests 
function buildPOST(obj) {   
    var qs = "<envelope><post>";
    for(e=0;e<obj.elements.length;e++){ 
      if(!obj.elements[e].getAttribute("method")){
        var name = obj.elements[e].id;
        if(!name) continue;
        var value = "";
        if(obj.elements[e].type == "checkbox"){
          if(obj.elements[e].checked) value = encodeURIComponent(obj.elements[e].value);
        }
        else{
          var value = encodeURIComponent(obj.elements[e].value);
        }
        qs += "<"+name+">"+value+"</"+name+">";
      }
    }
    qs += "</post></envelope>";
    //Build url
    var url = String(document.location.search);
    // Find app:import
    var doc = GetQuery("doc",null);
    var app = obj.getAttribute("app");
    if(app) doc = app;
    if(doc){
      url = ReplaceQuery("doc",doc,String(document.location.search),"replace");
    }      
    url = "default.aspx"+url;
    //Send to server
    var xmlHttp = XmlHttp();
    var xml = null;
    xmlHttp.open("POST", url, false);
    xmlHttp.send(qs);
    // After effects...
    //var xml = xmlHttp.responseXML;
    
    var res = xmlHttp.responseText;
    if(res.indexOf("<detail><message>") > 0){ // An error occured
     var s = res.split("<detail><message>");
     s = s[1].split("</message>");     
     res = s[0];
     alert(res);
     return -1;
    }
    else{
      var url = "";
      var blnReplace = true; 

      // Check for redirects with rb:source values
      var redirectNode = xmlHttp.responseXML.documentElement.getElementsByTagName("redirect");
      if(redirectNode.length == 1){
        url = getInnerText(redirectNode.item(0));
        // extract redirect to url format
        var qArray = url.split("|");
        url = "default.aspx?";
        for(i=0;i<qArray.length;i++){
          if(qArray[i]=="") continue;
          if(i>0 && i<qArray.length) url += "&"; 
          url += qArray[i]
        }
        if(url != "") blnReplace = false;
      }
      // No uri given, use original location
      if(url==""){
        url = String(document.location); 
      }
      if(blnReplace){
        location.replace(url);
      }
      else{
        location.href=(url);
      }
      return false;
    }
}
    
function getInnerText(node){
  if (typeof node.textContent != 'undefined') {
    return node.textContent;
  }
  else if (typeof node.innerText != 'undefined') {
     return node.innerText;
  }
  else if (typeof node.text != 'undefined') {
  return node.text;
  }
  else {
  switch (node.nodeType) {
    case 3:
    case 4:
    return node.nodeValue;
    break;
    case 1:
    case 11:
    var innerText = '';
    for (var i = 0; i < node.childNodes.length; i++) {
      innerText += getInnerText(node.childNodes[i]);
    }
    return innerText;
    break;
    default:
    return '';
    }
  }
}
    
    

function ReplaceQuery(name,value,loc,mode){ // mode : replace(insert) or delete
  if(loc == "") loc = "?";
  var queryString = String(loc);
  var n = (queryString.indexOf("?") + 1);
  if (queryString != ""){
    var data,aData,aOut
    var insert = false
    var outValue = "?";
    data = queryString.slice(n,queryString.length);
    aData = data.split("&");
    for(i=0;i<aData.length;i++){
      aOut = aData[i].split("=");
      if(aOut[0].toUpperCase() == name.toUpperCase()){
        if(mode != "delete"){
          if(outValue != "?") outValue += "&";
  	  outValue += name + "=" + value; 
	}
	insert = true;
      }
      else{
        if(outValue != "?") outValue += "&";	
        outValue += aData[i]; 				
      }
    }
    if(insert != true && mode != "delete"){
      if(outValue != "?") outValue += "&";
      outValue += name + "=" + value;
    }			
    return outValue;
  }
  else{
    return null;
  }
}

function GetQuery(name,url){
  var data,aData,aOut;
  var outValue = null;
  if(!url){
    url = unescape(document.location.search);
    data = url.slice(1,url.length);
  }
  else{
    pos = url.indexOf("?");
    data = url.slice((pos+1),url.length);
  }
  if(data != ""){
    aData = data.split("&");
    for(i=0;i<aData.length;i++){
      if(!aData[i]) continue;
      aOut = aData[i].split("=");
      if(aOut[0].toUpperCase() == name.toUpperCase()){
        outValue = aData[i].substring( aData[i].indexOf("=")+1, aData[i].length );
        break;
      }
    }
    return outValue;
  }
  else{
    return null;
  }
}

function CancelEvent(){
  window.event.cancelBubble = true;
  window.event.returnValue = false;
  return false;
}

function ShowAllTxt(){
  var clickObj = event.srcElement;
  var obj = document.getElementById("descr");
  if(!obj || !clickObj) return;
  if(clickObj.clicked == "Y"){
    clickObj.setAttribute("clicked","")
    obj.style.height = "200px";   
    obj.style.overflow = "hidden";   
  }
  else{
    clickObj.setAttribute("clicked","Y")
    obj.style.height = null;     
  }
}

/*************************************************/

function XmlHttp(){
  var xmlhttp=false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // JScript gives us Conditional compilation, we can cope with old IE versions.
  // and security blocked creation of the objects.
   try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
     xmlhttp = false;
    }
   }
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}


function FindInnerText(objControl, innerText, nestingLevel)
{
	//maybe microsoft already done the job for us?
	if (typeof objControl.innerText != "undefined")
		return objControl.innerText;
	
	//standard browser. check recursion limit:
	if ((typeof nestingLevel != "undefined")&&(nestingLevel > 100))
		return innerText;
	
	//set defaults:
	if (typeof innerText == "undefined")
		innerText = "";
	if (typeof nestingLevel == "undefined")
		nestingLevel = 0;
	
	//stop condition:
	if (!objControl)
		return innerText;
	
	var text=objControl.nodeValue;
	if (!text)
		text = "";
	
	//take into consideration line breaks:
	if (objControl.nodeName.toLowerCase() == "br")
		return "\n";
	
	//iterate child elements:
	for (var i=0; i<objControl.childNodes.length; i++)
	{
		text += FindInnerText(objControl.childNodes[i], objControl.childNodes[i].nodeValue, nestingLevel+1);
	}
	
	//all done.
	return text;
}

//funksjon for C% kunne submitte en form ved hjelp av enter tasten og uten submitknapp
function submitenter(myform,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myform.form.submit();
   post(myform);
   return false;
   }
else
   return true;
}

//funksjon for C% laste mini handlekurv
function loadshopcartmini(objname){
  return;
   var chk = document.getElementById(objname);
//   alert(chk.outerHTML);
   var url = "default.aspx?doc=WWW.SHOPCARTMINI";
   var xmlHttp = XmlHttp();
   xmlHttp.open("GET", url, false);
   xmlHttp.send();
   chk.innerHTML = xmlHttp.responseText;
}

//funksjon for aa poste forms uten C% laste location.href ettepaa
function post2(obj){
 var frm = null;
 if(obj && obj.tagName.toUpperCase() == "FORM") frm = obj;
 if(!frm){
   var area = obj;
   while(area.parentNode){
     if(area.tagName.toUpperCase() == "FORM"){
       frm = area;
       break;
     }
     area = area.parentNode;
   }
 }
 else if(!frm) frm = window.event.srcElement;
 var x = buildPOST2(frm);
 CancelEvent();    
}

// function to build POST requests 
function buildPOST2(obj) {   
    var qs = "<envelope><post>";
    for(e=0;e<obj.elements.length;e++){ 
      if(!obj.elements[e].getAttribute("method")){
        var name = obj.elements[e].id;
        if(!name) continue;
        var value = encodeURIComponent(obj.elements[e].value);
        qs += "<"+name+">"+value+"</"+name+">";
      }
    }
    qs += "</post></envelope>";   
    //Build url
    var url = String(document.location.search);
    // Find app:import
    var doc = GetQuery("doc",null);
    var app = obj.getAttribute("app");
    if(app) doc = app;
    if(doc){
      url = ReplaceQuery("doc",doc,String(document.location.search),"replace");
    }      
    url = "default.aspx"+url;
    //Send to server
    var xmlHttp = XmlHttp();
    var xml = null;
    xmlHttp.open("POST", url, false);
    xmlHttp.send(qs);
    // After effects...
    var xml = xmlHttp.responseXML;
    var errmsg = xml.getElementsByTagName("message");
    if(errmsg.length){ // An error occured
      alert(FindInnerText(errmsg[0]));
      return false;
    }
    else{
//      var url = String(document.location);
//      location.replace(url);
    }
}

function findPos(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
	        curleft += obj.offsetLeft
	        curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}  

function showImage(source, offsetX, offsetY, imageDivName, imageDivImgName, imageUrl)
{              
    var imageDiv = document.getElementById(imageDivName);            
    var coors = findPos(source);
    
    imageDiv.style.top = (coors[1] + offsetY) + 'px';
    imageDiv.style.left = (coors[0] + offsetX) + 'px';                
    
    var imageDivImg = document.getElementById(imageDivImgName);
    
    imageDivImg.src = imageUrl;    
    imageDivImg.style.visibility = "visible";
    
    imageDiv.style.visibility = "visible";
}

function hideImage(source, imageDivName, imageDivImgName)
{   
    var imageDiv = document.getElementById(imageDivName);
    imageDiv.style.visibility = "hidden";
    
    var imageDivImg = document.getElementById(imageDivImgName);   
    
    imageDivImg.src = "images/space.gif";
    imageDivImg.style.visibility = "hidden";
}
    
function changeBigImage(source, imageTagId, imageNr, imageUrl)
{   
    var imageTag = document.getElementById(imageTagId);            
    imageTag.src = imageUrl;
    
    var imageArrow = document.getElementById("TOP" + imageNr);    
    if (imageArrow != null)
    {
        imageArrow.src = "g/arrow_top.gif";        
    }
    var i = 0;
    while (true)
    {
        var imageNonArrow = document.getElementById("TOP" + i);    
        if (imageNonArrow != null)
        {
            if (i != imageNr)
            {
                imageNonArrow.src = "g/s.gif";        
            }
        }
        else
        {
            break;
        }
        i++;
    }
}

function createPopupLotMenu(source, menuDivId, evtId, group, evtClass)
{   
    if(evtClass == "ONLINE") menuDivId = "lotmenudivonline";
    else menuDivId = "lotmenudiv"; 
    
    var menu = document.getElementById(menuDivId);
               
    //set correct hrefs in menu
    if(evtClass == "ONLINE"){  
      var onlineCatHref = document.getElementById("auctionOnlineCatalogueMenuHref");     
      onlineCatHref.href = "?doc=WWW.LOTMENU&a=" + evtId + "&c1=" + group;
    }
    else{
      var onlineCatHref = document.getElementById("auctionCatalogueMenuHref");     
      onlineCatHref.href = "?doc=WWW.LOTMENU&a=" + evtId + "&c1=" + group;      
    }
   
    if(evtClass == "ONLINE"){
    	var auctConHref = document.getElementById("auctionOnlineConditionsMenuHref");
    	auctConHref.href = "?doc=WWW.CONDITIONS";
    }
    else{
    	var auctConHref = document.getElementById("auctionConditionsMenuHref");
    	auctConHref.href = "?doc=WWW.CONDITIONS";
    }
    
    var auctionPricesHref4 = document.getElementById("auctionPricesHref4");
    if(evtClass == "COMBINED"){     
      auctionPricesHref4.href = "?doc=WWW.LOTRESULT&mode=TEMPORARY&a=" + evtId + "&cond=" + group + "&c1=" + group;   
      hideLotMenu("lotmenudivonline");
    }
    else hideLotMenu("lotmenudiv");

    //place menu in correct position
    var coors = findPos(source);
    
    menu.style.top = (coors[1] + 14) + 'px';
    menu.style.left = (coors[0] + 0) + 'px';                
   
    menu.style.visibility = "visible"; 
    clearHideLotMenu();
}

function createPopupLotMenuEnded(source, menuDivId, evtId, group)
{   
    var menu = document.getElementById(menuDivId);
    
               
    //set correct hrefs in menu
    var auctionInfoHref= document.getElementById("auctionInfoHref");     
    auctionInfoHref.href = "?doc=WWW.EVTINFO&a=" + evtId + "&c1=" + group;

    var auctionCatalogueHref = document.getElementById("auctionCatalogueHref");
    auctionCatalogueHref.href = "?doc=WWW.LOTMENU&include=ENDED&a=" + evtId + "&cond=" + group + "&c1=" + group;   
    
    var auctionPricesHref = document.getElementById("auctionPricesHref");
    auctionPricesHref.href = "?doc=WWW.LOTRESULT&a=" + evtId + "&cond=" + group + "&c1=" + group;   


    var auctionUnsoldHref = document.getElementById("auctionUnsoldHref");
    auctionUnsoldHref.href = "?doc=WWW.LOTRESULT&include=UNSOLD&a=" + evtId + "&cond=" + group + "&c1=" + group;   

    var auctionHitHref = document.getElementById("auctionHitHref");
    auctionHitHref .href = "?doc=WWW.HITLIST&include=ENDED&a=" + evtId + "&cond=" + group + "&c1=" + group;  
                                                       
    var auctionConditionsHref= document.getElementById("auctionConditionsHref");
    auctionConditionsHref.href = "?doc=WWW.CONDITIONS";
    

    //place menu in correct position
    var coors = findPos(source);
    
    menu.style.top = (coors[1] + 14) + 'px';
    menu.style.left = (coors[0] + 0) + 'px';                
   
    menu.style.visibility = "visible"; 
    clearHideLotMenu();
}


function hideLotMenu(menuDivId)
{    
    var menu = document.getElementById(menuDivId);            
    menu.style.visibility = "hidden";
}

function clearHideLotMenu(menuDivId)
{              
    if (typeof delayhide!="undefined")
    {           
        clearTimeout(delayhide);
        delayhide = undefined;
    }            
}

function delayHideLotMenu(menuDivId)
{   
    if (typeof delayhide=="undefined")
    {
        delayhide=setTimeout("hideLotMenu('" + menuDivId + "')",500);               
    }            
}

function changeBigImage(source, imageTagId, imageNr, imageUrl, width)
{   	
    var bigImage = document.getElementById(imageTagId);            
    bigImage.src = imageUrl;
    
    var imageArrow = document.getElementById("TOP" + imageNr);    
    if (imageArrow != null)
    {
        imageArrow.src = "g/arrow_top.gif";        
    }
    var i = 0;
    while (true)
    {
        var imageNonArrow = document.getElementById("TOP" + i);    
        
        if (imageNonArrow != null)
        {          
            if (i != imageNr)
            {
                imageNonArrow.src = "g/s.gif";        
            }
        }
        else
        {
            break;
        }
        i++;
    }
}

function startCountDown(countDownControlId, secondsRemaining, finishedMessage)
{	        
    var tmpCalc, days, hours, minutes, seconds;

    secondsRemaining--;
    tmpCalc = secondsRemaining;

    days = Math.floor(tmpCalc / 86400);
    tmpCalc -= days * 86400;

    hours = Math.floor(tmpCalc / 3600);
    tmpCalc -= hours * 3600;

    minutes = Math.floor(tmpCalc / 60);
    tmpCalc -= minutes * 60;

    seconds = tmpCalc;

    var message = '';

    if(secondsRemaining > 0) 
    {		
	    if(days > 0) {message = message + days + ' d ';}
	    if(hours > 0) {message = message + hours + ' t ';}
	    if(minutes >0) {message = message + minutes + ' m ';}
	    message = message + seconds + ' s';
    }
    else
    {	    
    
           var uri =  document.location.search;
           uri = "default.aspx"+uri;
           document.location.replace(uri);
	    message = finishedMessage;
    }

    var countDownControl = document.getElementById(countDownControlId);
    if (countDownControl != null)
    {
	    document.getElementById(countDownControlId).innerHTML = message;
    }	

    if(secondsRemaining > 0) 
    {	    
	    setTimeout("startCountDown('" + countDownControlId + "'," + secondsRemaining + ",'" + finishedMessage + "')", 1000);    	
    }	
}

function thaUserRegValidateForm (step)
{                    
    valid = true;
    
    if (step == 1)
    { 
        var emailValidation = document.getElementById("emailValidationError");
        var interestValidation = document.getElementById("interestValidationError");
    
        var emailInput = document.getElementById("email");                
        if ( emailInput.value == "" || !((emailInput.value.lastIndexOf(".") > emailInput.value.indexOf("@")) && (emailInput.value.indexOf("@") > 0)))
        {                   
            valid = false;            
            emailValidation.style.display = "block";            
        }  
        else
        {
           emailValidation.style.display = "none";
        }
      
        
        var interestChecked = false;
        var interestArray = document.getElementsByName("collect");        
        for( var i = 0; i < interestArray .length; i++)
        {
            var tmp = interestArray [i];        
            if (tmp.checked == true)
            {
                interestChecked = true;
            }
        }
        
        if (interestChecked == false)
        {
           valid = false;            
           interestValidation.style.display = "block";
        }
        else
        {
           interestValidation.style.display = "none";
        }

    }
    else if (step == 3)
    {
       var validationErrorMessage = document.getElementById("validationErrorMessage");
       
    	var validationUsernameEmpty = document.getElementById("validationUsernameEmptyError");
    	var validationUsernameInvalid = document.getElementById("validationUsernameInvalidError");
	var validationPassword = document.getElementById("validationPasswordError");
	var validationPasswordMismatch = document.getElementById("validationPasswordMismatchError");
	var emailValidation = document.getElementById("emailValidationError");	
	var validationName = document.getElementById("validationNameError");
	var validationAddr = document.getElementById("validationAddrError");
	var validationPostalcode = document.getElementById("validationPostalcodeError");
	var validationCity = document.getElementById("validationCityError");   
    
       var usernameInput = document.getElementById("username");        
       if ( usernameInput.value == "")
       {                   
            valid = false;            
            validationUsernameEmpty.style.display = "block";            
       }  
       else
       {
           validationUsernameEmpty.style.display = "none";
       }
       
       if ( usernameInput.value.indexOf(" ") >= 0)
       {                   
            valid = false;            
            validationUsernameInvalid.style.display = "block";            
       }  
       else
       {
           validationUsernameInvalid.style.display = "none";
       }

       var passwordInput = document.getElementById("password");        
       var passwordconfInput = document.getElementById("passwordconf");               
       if ( passwordInput.value == "" || passwordInput.value.length < 8 || passwordInput.value.indexOf(" ") >= 0)
       {                   
            valid = false;            
            validationPassword.style.display = "block";            
       }  
       else
       {
           validationPassword.style.display = "none";
       }
       
       if ( passwordInput.value != passwordconfInput.value)
       {                   
            valid = false;            
            validationPasswordMismatch.style.display = "block";            
       }  
       else
       {
           validationPasswordMismatch.style.display = "none";
       }

	var emailInput = document.getElementById("email");        
       if ( emailInput.value == "" || !((emailInput.value.lastIndexOf(".") > emailInput.value.indexOf("@")) && (emailInput.value.indexOf("@") > 0)))
       {                   
            valid = false;            
            emailValidation.style.display = "block";            
       }  
       else
       {
           emailValidation.style.display = "none";
       }

	var lastnameInput = document.getElementById("lastname");        
       if ( lastnameInput.value == "")
       {                   
            valid = false;            
            validationName.style.display = "block";            
       }  
       else
       {
           validationName.style.display = "none";
       }
    
    	var addrInput = document.getElementById("addr1");        
       if ( addrInput.value == "")
       {                   
            valid = false;            
            validationAddr.style.display = "block";            
       }  
       else
       {
           validationAddr.style.display = "none";
       }
       
       var pocodeInput = document.getElementById("pocode");        
       if ( pocodeInput.value == "")
       {                   
            valid = false;            
            validationPostalcode.style.display = "block";            
       }  
       else
       {
           validationPostalcode.style.display = "none";
       }
       
	var cityInput = document.getElementById("city");        
       if ( cityInput.value == "")
       {                   
            valid = false;            
            validationCity.style.display = "block";            
       }  
       else
       {
           validationCity.style.display = "none";
       }
       
       
       if (valid == false)
       {
           validationErrorMessage.style.display = "Block";
       }
 
    }
            
    if (valid == true)
    { 
       post(document.Regform1);        
    	//Regform1.submit();
    }    
}

function setConditionCheckboxValues()
{
  
   var cond = GetQuery("condjs", null);
   if (cond!= null)
   {
	   if (cond.indexOf("|**|") != -1)
	   {
	     var chkBoxSs = document.getElementById("fcss");            
	     chkBoxSs.checked = true;
	   }
	   if (cond.indexOf("|Klip|") != -1)
	   {
	     var chkBoxKlip = document.getElementById("fcklip");            
	     chkBoxKlip.checked = true;   
	   }
	   if (cond.indexOf("|*|") != -1)
	   {
	     var chkBoxS = document.getElementById("fcs");            
	     chkBoxS.checked = true;   
	   }
	   if (cond.indexOf("|B|") != -1)
	   {
	     var chkBoxB = document.getElementById("fcb");            
	     chkBoxB.checked = true;
	   }
 	   if (cond.indexOf("|o|") != -1)
	   {
	     var chkBoxO = document.getElementById("fco");            
	     chkBoxO.checked = true;
	   }
	   if (cond.indexOf("|P|") != -1)
	   {
	     var chkBoxP = document.getElementById("fcp");            
	     chkBoxP.checked = true;
	   }
	   if (cond.indexOf("|LOC/100005|") != -1)
	   {
	     var chkBoxP = document.getElementById("100005");            
	     chkBoxP.checked = true;
	   }
	   if (cond.indexOf("|LOC/100006|") != -1)
	   {
	     var chkBoxP = document.getElementById("100006");            
	     chkBoxP.checked = true;
	   }
	   if (cond.indexOf("|LOC/100004|") != -1)
	   {
	     var chkBoxP = document.getElementById("100004");            
	     chkBoxP.checked = true;
	   }
   }
}

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);
}

function readListHref(){
   var link = readCookie("list");
   if(!link){
     link = "?doc=WWW.LOTMENU";
   }
   document.location.href = link;
}

//RB MAIL
function rbMail(){
  setTimeout(function(){ rbMail() },30000);
  var obj = document.getElementById("lotpop");
  if(obj && obj.innerHTML != "") return;
  var left,top;
  left = ((document.body.clientWidth/2)-150);
  top = 70;
  url = "default.aspx?doc=WWW.LOTPOP";
  var http =  XmlHttp();
  http.Open('GET',url,false);
  http.Send();
  if(http.responseText.length<500) return false;
   
  var action = document.createElement("div");
  obj.insertBefore(action,null);
  action.id = "action";
  action.style.position = "absolute";
  action.style.backgroundColor = "#fbe797";
  action.style.border = "solid black 1px";
  action.style.padding = "4px";
  
  action.style.width = 300;
  action.style.height = 150;
  action.style.zIndex = 40;
  action.style.pixelLeft = left;
  action.style.pixelTop = top;
  action.innerHTML = http.responseText;
}

function ClosePop(id){
  if(document.getElementById(id)){
    var obj = document.getElementById(id);
    obj.innerHTML = "";
    return true;
  }
  else return false;
}
