 function products(guid,information,stock)
  	{
     		this.guid = guid;
     		this.information = information;
     		this.stock = stock;
  	}

function mail()
{
  window.open("/se/kontrol/tipsa?product=true","available","menubar=0,resizable=0,width=567,height=567,scrollbars=1,top=20,left=250");
}

 function comment(x)
 	{
     		var urlqry = document.location.href;
     		window.open("/se/kontrol/usercomment/?sno="+x,"available","resizable=0,scrollbars=1,width=567,height=567,top=20,left=250");
  	}

 function extramaterial(material)
  	{
     		document.location.href=document.URL+"&material="+material;
  	}

 function toDetail(detailurl)
  	{
     		document.location.href=detailurl;
  	}

 function clearContents(inputbox,value,id)
  	{
     		if(inputbox.value == value)
        		inputbox.value = "";
     		document.getElementById(id+'error'). innerHTML='';
     		document.getElementById(id).style. border="none"; 
  	}

 function changeImg(id,src)
  	{
     		document.getElementById(id+'_img'). src="/gleerups/upload/images/templates/"+src+"over.gif";
  	}

 function BackImg(id,src)
  	{
     		document.getElementById(id+'_img'). src="/gleerups/upload/images/templates/"+src+".gif";;
  	}

 var popup = null;
 function popUp(url)
  	{
     		try
     		{
         		if(popup!=null)
           		popup.close();
     		}
     		catch(e){}
     		popup =  window.open(url,"available","menubar=0,scrollbars=yes,taskbar=0,resizable=0,left=300,top=160,width=400,height=215");
     		popup.focus();
  	}

 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 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");
 }
 var NoStock = '';
 var productInfo = new Array();
 function doAddProducts(no,serialno)
 	{
   		 var outofstock='';
    		 var str='';
    		 var ns = 0;
    		 var currenturl=document.location.href;
    		 var newurl=currenturl.split('?');
    		 NoStock = '';
    		 productInfo = new Array();
    		 for(i=1;i<=no;i++)
    			{
         			var count=document.getElementById("count"+i).value;
         			var stock =document.getElementById("stock"+i).value;   
         			var guid=document.getElementById("guid"+i).value;
         			var url='';
         			var pageurl='';
         			if(isNaN(count) || count=='' || count==null)
         			{
            				document.getElementById("count"+i). value='';
            				ns =ns +1;
            				if(isNaN(count))
             					document.getElementById("count"+i).style. border="solid 1px red";
         			}
         			else if(count!=0)
            			{
              				if(stock.toUpperCase() == 'FALSE')
              					{
                  					NoStock = NoStock + document.getElementById("serial"+i).value + ',';
              					}
              				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()); 
              				url=document.getElementById("url"+i).value;
              				var isbn=document.getElementById("isbn"+i).value;
              				var date=document.getElementById("date"+i).value;
              				var reseller=document.getElementById("reseller"+i).value;
                                        reseller=reseller==''?0:reseller;
              				var resellerpricewithvat=document.getElementById("resellerpricewithvat"+i).value;
                                        resellerpricewithvat=resellerpricewithvat==''?0:resellerpricewithvat;
              				var vat=document.getElementById("vat"+i).value;
                                        vat=vat==''?0:vat;
                                        
                                        reseller = priceFormat(reseller);
                                        resellerpricewithvat = priceFormat(resellerpricewithvat);
                                        vat = priceFormat(vat); 
              				pageurl=newurl[0]+url;
              				x=guid+"="+count+"+"+HtmlEncode('<options><pageurl>'+HtmlEncodeUrl(pageurl)+'</pageurl><url>'+HtmlEncodeUrl(url)+'</url><isbn>'+isbn+'</isbn><date>'+date+'</date><resellerprice>'+reseller+'</resellerprice><resellerpricewithvat>'+resellerpricewithvat+'</resellerpricewithvat><vat>'+vat+'</vat><course>0</course><time>'+time+'</time></options>');
              				str=str+x+','; 
              				productInfo[productInfo.length] = new products(guid,x,stock);
            			}
     			 }
     		if(ns != no)
     			 {
       				if(NoStock != '')
       					{
        					popUp("/gleerups/se/kontrol/popup_productlist/?serial" + "=" +NoStock);
       					}
       				else
       					{
         					document.getElementById('hiddenxml').value=str;  
         					document.getElementById('formxml').submit();
       					}
     			 }
 	}

 function doAddProductsPopup(returnValue)
 	{
     		if(returnValue != null)
     			{
      				if(returnValue.toLowerCase() == 'ok')
      					{
        					document.getElementById('hiddenxml').value ='';
        					for(i=0;i<productInfo.length;i++)
        						{
            							document.getElementById('hiddenxml').value= document.getElementById('hiddenxml').value + productInfo[i].information + ',';  
            
        						}
      					}
      				else if(returnValue.toLowerCase() == 'cancel')
      					{
        					document.getElementById('hiddenxml').value ='';
        					for(i=0;i<productInfo.length;i++)
        						{
           							if(productInfo[i].stock.toLowerCase() == 'true')
           								{
              									document.getElementById('hiddenxml').value= document.getElementById('hiddenxml').value + productInfo[i].information + ',';  
           
           								}
        						}
      					}
      				if(document.getElementById('hiddenxml').value != '')
					        document.getElementById('formxml').submit();
     			}
 	}
/*Function to calculate stock avialable date */
 function findavailableWeek(date,no)
	 {
			var res1=date.split("-");
			if(res1 !='')
				{ 
					var today = new Date();
					res1[1]--;
					Year = parseInt(res1[0]);
					Month = parseInt(res1[1]);
					Day = parseInt(res1[2]);
					now = Date.UTC(Year,Month,Day+1,0,0,0);
					var Firstday = new Date();
					Firstday.setYear(Year);
					Firstday.setMonth(0);
					Firstday.setDate(1);
					then = Date.UTC(Year,0,1,0,0,0);
					var Compensation = Firstday.getDay();
					if (Compensation > 3) Compensation -= 4;
					else Compensation += 3;
					NumberOfWeek = Math.round((((now-then)/86400000)+Compensation)/7);
					avildate='v.'+NumberOfWeek +'/'+ res1[0].substring(2);
					document.getElementById("week"+no).innerHTML=avildate;

				}

	 }
/*Function to change the image of the tool tips*/
 function changebgimg(no,a)
     {
	       document.getElementById(no). className='symbolgreen';   
       	       document.getElementById(a).style. display="inline";
     }
 function bgimg(no,a)
     {
               document.getElementById(no). className='symbolblack';
               document.getElementById(a).style.display ="none" ;   
     }
/*Funtion to view the product functionality*/
/*function viewcontent(id,cat)
{
  var browserName=navigator.appName;
  if(cat=="author")
	
   {
	
 	if(browserName=='Microsoft Internet Explorer')		
        {
	   document.getElementById('pagecontent').src="/se/kontrol/product_functionality?wildparam1=name="+escape(id)+"&view="+cat;
	} 	
       else
	{
    		
	  document.getElementById('pagecontent').src="/se/kontrol/product_functionality/default.asp?wildparam1=name="+escape(id)+"&view="+cat;
        }
   }
  else
    {
	if(browserName=='Microsoft Internet Explorer')		
	{
		
	  document.getElementById('pagecontent').src="/se/kontrol/product_functionality?searchparam1= isbn="+id+"&view="+cat;
        }
       else
	{
	  document.getElementById('pagecontent').src="/se/kontrol/product_functionality/default.asp?searchparam1= isbn="+id+"&view="+cat;	
	}
   }

}*/

function viewcontent(id,cat)
{
  var browserName=navigator.appName;
  if(cat=="author"){
	createCookie('urlproduct',document.location.href,1);

 	if(browserName=='Microsoft Internet Explorer')		
        {
	document.location.href = document.location.href + "&wildparam1=name="+escape(id) +"&view="+cat;
	} 	
       else
	{
    		
	document.location.href = document.location.href + "&wildparam1=name="+ id +"&view="+cat;
        }
   }
  else{
    document.getElementById('pagecontent').src="/se/kontrol/product_functionality/?searchparam1= isbn="+id+"&view="+cat;
  }
}

function backproduct(){
   document.location.href =  readCookie("urlproduct");
}

function viewauthor(id,cat) 
{
  document.getElementById('pagecontent').src="/se/kontrol/product_functionality/?wildparam1= name="+id+"&view="+cat;
}  
function back()
{
  document.getElementById('groupdetail').style.display="block";
  document.getElementById('showcontent').style. display="none";
}



//Trim Function 
function trim(str)
{ return str.replace(/^\s*|\s*$/g,'');
}




//* Function to open new window as per the Smakprov property  **//
function splitfunction(Smakprov)
{
	var check_pdf = Smakprov.indexOf("pdf");
	if(check_pdf != -1){
					
	   window.open('http://webbshop.gleerups.se/gleerups/upload/files/smakprov/'+Smakprov);
	}
	else
	{
		if(Smakprov.indexOf(",") == -1)
		{
			window.open('http://'+Smakprov);
		}
		else
		{
			var item=Smakprov.split(",");
			openMyPaper(trim(item[0]),trim(item[1]));
		}
	}
}


function openMyPaper(isbn,type)
{ 	

	isbn=isbn.replace(/'/gi, "");
	var res_height,res_width,resOK,errorUrl,cookieOK 	
	resOK = false; 	res_height = screen.height; 	
	res_width = screen.width; 	
	if(res_width >= 1024 && res_height >= 768) 	
	resOK = true; 	 	
	if(resOK != true)
	{ 		
			if(type==1) 
			{ 		
				window.open('http://www.mypaper.se/show/smakprov/show.asp?ref=3&isbn='+isbn,'mypaper'+isbn,'width=780,height=540,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); 		
			} 
			else
			{ 		
				window.open('http://www.mypaper.se/show/smakprov/show.asp?ref=3&action=maximize&isbn='+isbn,'mypaper'+isbn,'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no'); 		
			} 	
	} 
	else 
	{ 		
		if(screen.width==1024)
		{ 			
			window.open('http://www.mypaper.se/show/smakprov/show.asp?ref=3&action=maximize&isbn='+isbn,'mypaper'+isbn,'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no'); 		
		}
		else 
		{ 		
			window.open('http://www.mypaper.se/show/smakprov/show.asp?ref=3&isbn='+isbn,'mypaper'+isbn,'width=1020,height=745,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no'); 		
		} 
	}
}

function popPaper(isbn)
{
	openMyPaper(isbn,2);
}





