﻿ var popup = null;
//Function to clear the search field
function  clearText(id)
{
    if(document.getElementById(id).value == 'Sökord, titel, författare, ISBN') 
     document.getElementById(id).value = '';
}
//Function to search the products and news by using search word,title,author and ISBN
function checktext(id)
{
   var searchval = document.getElementById('searchtext').value; 
   if(searchval!='Sökord, titel, författare, ISBN' && searchval!="")
   {     
     var s = document.getElementById("searchframe");
     s.src = "/gothia/se/om_gothia/sok/default.aspx?search" + "=" +encodeURI(searchval)+"&sort=both";
   }
   if(id == 1)
     return false;
}  
//Function to search the products by using titles in IFRAME
function showapath1()
{
    var bfhome='/se/om_gothia/sok/titlar/?sort=A';
    document. cookie="home="+escape(bfhome)+";";
    var s = document.getElementById("searchframe");
    s.src = '/se/om_gothia/sok/titlar/?sort=A';
} 
//Function to search the authors in IFRAME
function showapath()
{
    if (location.href.indexOf("/forfattare") == -1){
        createCookie('gothiaurlproduct',document.location.href,1);	
    }
    var bfhome='/se/om_gothia/sok/forfattare/?wildparam1=name' + '=' + 'A*';
    document. cookie="home="+escape(bfhome)+";";
    var s = document.getElementById("searchframe");
    s.src = '/se/om_gothia/sok/forfattare/?wildparam1=lastname' + '=' + 'A*';
} 

function backproduct()
{
   document.location.href =  readCookie("gothiaurlproduct");
}

//Function to search the authors in IFRAME using the alphabets
function redirecttoauthor(hint)
{
  var s = document.getElementById("searchframe");
  s.src = '/se/om_gothia/sok/forfattare/?wildparam1=lastname' + '=' +hint+'*';
}
//Function to show the author details using their NAME and ID
function showAuthorDetailPage(authname,id)
{  
    if (location.href.indexOf("/om_gothia") != -1){
      window.location.href = '/gothia/se/om_gothia/sok/forfattare/?search' + '=' +escape(authname)+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
   }else if (location.href.indexOf("/utgivning/") != -1){
      window.location.href = '/gothia/se/utgivning/sok/forfattare/?search' + '=' +escape(authname)+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
   }else if (location.href.indexOf("/butik") != -1){
      window.location.href = '/gothia/se/butik/sok/forfattare/?search' + '=' +escape(authname)+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
   }else {
      window.location.href = '/gothia/se/om_gothia/sok/forfattare/?search' + '=' +escape(authname)+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
   }
}

function showauthor(authname,id)
{  
      createCookie('gothiaurlproduct',document.location.href,1);	
      document.location.href = document.location.href + '&search' + '=' +escape(authname)+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
}

function showauthordetail(authname,id)
{  
  var s = document.getElementById("searchframe");
 
  s.src = '/gothia/se/om_gothia/sok/forfattare/?search' + '=' +authname+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
}
function showauthordetail1(authname,id)
{  
  var s = document.getElementById("searchframe");
 
  s.src = '/gothia/se/om_gothia/sok/forfattare/?search' + '=' +escape(authname)+ '&ec_item_101_id' + '=' + id + '&sort' + '=' + 'author';
}


//Function from product list alphabetical order 
function show(letter)
 {
   var s = document.getElementById("searchframe");
   s.src = '/se/om_gothia/sok/titlar/?sort'+ '=' +letter;
 }
//Function to move between the pages in product search results
function formSubmit(inputName,orderby,order)
{
  var searchval = document.getElementById('searchtext').value;
  //document.getElementById(inputName).value=orderby;
  var s = document.getElementById("searchframe");
  s.src = "/gothia/se/om_gothia/sok/default.aspx?search" + "=" +searchval+"&sort=both&prod_currentpage" + "=" +orderby ;
}
function popUp(url)
 {
     try
     {
        if(popup!=null)
         popup.close();
     }
     catch(e){}
     popup = window.open(url,"available","menubar=0,taskbar=0,resizable=0,left=300,top=160,width=400,height=215");
     popup.focus();
 }
 function priceFormat(val)
 {
  val = val.toString();
   if(val.indexOf('.') > -1)
   {
     if((val.substring(val.indexOf('.')+1,val.length)).length < 2)
       return(val+"0"); 
     else
       return(val); 
   }
   else
     return(val+".00");
 }
  //Function to add the product to Cart which are listed in search 
  function AddtoCart(sno,stock,guid,date,isbn,oldisbn,price,vat,pricewithvat,url,pris1,pris1vat,pris1withvat,pris5,pris5vat,pris5withvat,pris20,pris20vat,pris20withvat,pris100,pris100vat,pris100withvat,pris1000,pris1000vat,pris1000withvat)
  { 
   price=price==''?0:price;
   pricewithvat=pricewithvat==''?0:pricewithvat;
   vat=vat==''?0:vat;

   price = priceFormat(price);
   pricewithvat = priceFormat(pricewithvat);
   vat = priceFormat(vat);

   var level1=0;
   var level5=0;
   var level20=0;
   var level100=0;
   var level1000=0;
   var pricexml='';
   if(pris1 !='')
   {
     level1=1;
     pris1 = priceFormat(pris1);
     pris1vat = priceFormat(pris1vat);
     pris1withvat = priceFormat(pris1withvat);
     pricexml+='<price1>'+pris1+'</price1><price1vat>'+pris1vat+'</price1vat><price1withvat>'+pris1withvat+'</price1withvat>';
   }
   else
   {
     level1=1;
     pricexml+='<price1>0.00</price1><price1vat>0.00</price1vat><price1withvat>0.00</price1withvat>';
   }
   if(pris5 !='')
   {
     level5=1;
     pris5 = priceFormat(pris5);
     pris5vat = priceFormat(pris5vat);
     pris5withvat = priceFormat(pris5withvat);
     pricexml+='<price5>'+pris5+'</price5><price5vat>'+pris5vat+'</price5vat><price5withvat>'+pris5withvat+'</price5withvat>';
   }
   if(pris20 !='')
   {
     level20=1;
     pris20 = priceFormat(pris20);
     pris20vat = priceFormat(pris20vat);
     pris20withvat = priceFormat(pris20withvat);
     pricexml+='<price20>'+pris20+'</price20><price20vat>'+pris20vat+'</price20vat><price20withvat>'+pris20withvat+'</price20withvat>';
   }
   if(pris100 !='')
   {
     level100=1;
     pris100 = priceFormat(pris100);
     pris100vat = priceFormat(pris100vat);
     pris100withvat = priceFormat(pris100withvat);
     pricexml+='<price100>'+pris100+'</price100><price100vat>'+pris100vat+'</price100vat><price100withvat>'+pris100withvat+'</price100withvat>';
   }
   if(pris1000 !='')
   {
     level1000=1;
     pris1000 = priceFormat(pris1000);
     pris1000vat = priceFormat(pris1000vat);
     pris1000withvat = priceFormat(pris1000withvat);
     pricexml+='<price1000>'+pris1000+'</price1000><price1000vat>'+pris1000vat+'</price1000vat><price1000withvat>'+pris1000withvat+'</price1000withvat>';
   }
   var count=document.getElementById("count"+sno).value;
   if(isNaN(count) || count < 1)
     document.getElementById("count"+sno). value='';
   else
     {
       if(stock.toLowerCase()=='false')
       {
         url=url.replace('ew_101','ew_1')
         url=url.replace('ew_101','ew_1');
         popUp("/gothia/se/kontroll/popup/"+url+"&toiframe=true");
       }
       else
       {
         var d = new Date();
         var time=checkTime(d.getYear());
         time=time+"/"+checkTime(d.getMonth()); 
         time=time+"/"+checkTime(d.getDate());
         time=time+"/"+checkTime(d.getHours());
         time=time+"/"+checkTime(d.getMinutes()); 
         time=time+"/"+checkTime(d.getSeconds()); 
         x=guid+"="+count+"%2b"+escape('<options><url>'+HtmlEncodeUrl(url)+'</url><availabledate>'+date+'</availabledate><isbn>'+isbn+'</isbn><oldisbn>'+oldisbn+'</oldisbn><resellerprice>'+price+'</resellerprice><vat>'+vat+'</vat><resellerpricewithvat>'+pricewithvat+'</resellerpricewithvat><level1>'+level1+'</level1><level5>'+level5+'</level5><level20>'+level20+'</level20><level100>'+level100+'</level100><level1000>'+level1000+'</level1000>'+pricexml+'<time>'+time+'</time></options>');
         var s = document.getElementById("searchframe");
         var src="/se/butik/?addproduct"+ "=" +x;
         if(document.getElementById("small_cart"))
           src=src+"&refreshcart=true";
         s.src =src;
       }      
     }
  }
 function HtmlEncode(text)
 {
   return text.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/\,/g,'\\,')
 }
 function HtmlEncodeUrl(text)
 {
   return text.replace(/&/g,'||');
 }
function checkTime(i)
{
 if (i<10) 
  { i="0" + i}
  return i
}
 function editfont(obj,i)
 {
   if(obj.value=='' || (obj.value < 1) || isNaN(obj.value))  
   { 
     document.getElementById("font"+i).style. color="#000";
     document.getElementById("img"+i).style. background="url('/gothia/upload/images/templates/book_img.gif' ) no-repeat right";
   }
   else
   {
     document.getElementById("font"+i).style. color="#EE8900";     
     document.getElementById("img"+i).style. background="url('/gothia/upload/images/templates/detail_book.gif') no-repeat right";
   }
 }
 function fontchange(obj,i)
 {
   if(obj.value=='' || (obj.value < 1) || isNaN(obj.value))  
   { 
     document.getElementById("font"+i). className='product_pad';
     document.getElementById("img"+i). className='product_book_img';
   }
   else
   {
     document.getElementById("font"+i). className='product_fontchange';
     document.getElementById("img"+i). className='product_book_sel_img';
   }
 }
 function callclear()
 {
   document.getElementById('currentpage').value='';
   document.getElementById('checksearchtest').value='1';
 }


      //creating cookie to store the url of current page       
         function showchange()
           {                   
              createCookie("showchange",location,1);
              document.location. href='/se/butik/showchange/';
           }
      //creating cookie to store the url of current page for direct order      
         function directorder()
           {         
              createCookie("directorder",location,1);
              document.location. href='/gothia/se/butik/directorder/';
           }
    //function to redirect to product detail view page  
     function DetailView(url,serial)
      {  
          url=url.replace('||','&');
          url=url.replace('||','&');
          if(url.indexOf('?') > -1){
            document.location. href='/se/butik/amnesomraden'+url+'&content=true&searchparam1=serial='+serial;
          }
          else{
            document.location. href='/se/butik/amnesomraden'+url+'?content=true&searchparam1=serial='+serial;
          }
      }

