﻿
//eraseCookie('s8_en30_En2');

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 createCookieWithPath(name,value,days,path) {
	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=/" + 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 Set_Cookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

	

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//Smá hreynsunar starf úr Snöru 4

    del_cookie('s5_dais2');
    del_cookie('s5_isl2');
    del_cookie('s5_stor2');
    del_cookie('s5_staf2');
    del_cookie('s5_nofn2');
    del_cookie('s5_bey2');
    del_cookie('s5_isda2');
    del_cookie('s5_dais2');
    del_cookie('s5_daislo2');
    del_cookie('s5_isen2');
    del_cookie('s5_enisjpv2');
    del_cookie('s5_enis2');
    del_cookie('s5_fris2');
    del_cookie('s5_spis2');
    del_cookie('s5_mast2');
    del_cookie('s5_nanna2');
    del_cookie('s5_sam2');
    del_cookie('s5_saga2');
    del_cookie('s5_hkl2');
    del_cookie('s8_isl2');
    del_cookie('s8_stor2');
    del_cookie('s8_staf2');
    del_cookie('s8_nofn2');
    del_cookie('s8_bey2');
    del_cookie('s8_isda2');
    del_cookie('s8_dais2');
    del_cookie('s8_daislo2');
    del_cookie('s8_isen2');
    del_cookie('s8_enisjpv2');
    del_cookie('s8_enis2');  
    del_cookie('s8_enwn2');     
    del_cookie('s8_fris2');
    del_cookie('s8_spis2');
    del_cookie('s8_isit2');    
    del_cookie('s8_mast2');
    del_cookie('s8_nanna2');
    del_cookie('s8_sam2');        
    del_cookie('s8_kort2');
    del_cookie('s8_atlas2');    
    del_cookie('s8_deis2');
    //del_cookie2('ActiveCustomerId2', '/vefbaekur');
    //del_cookie2('CustomerKey2', '/vefbaekur');    
function del_cookie(name) {
    if (readCookie(name)){        
        eraseCookie(name);
    }        
}
function del_cookie2(name,path) {
    alert(name);
    Set_Cookie(name, '', -1, path);//, domain, secure )
    //if (Get_Cookie(name)){        
        //alert(name); 
        //createCookie(name,"",-1);
    //}        
}

/*function s5go(){
    document.forms["form1"].submit()
}*/

function doOnly(name){
    uncheckall();
    checkthisbox(name);
    createCookie('headInfoCount', 1, 30);
    createCookie('thedb', '', 30);
    __doPostBack('btn','');
}

function doOnly2(name){
    uncheckall();
    checkthisbox(name);
    createCookie('headInfoCount', 1, 30);
    createCookie('thedb', '', 30);
    //__doPostBack('btn','');
}

function noThing(){
    uncheckall();
    createCookie('headInfoCount', 1, 30);
    createCookie('thedb', '', 30);
    __doPostBack('btn','');
}

function addThis(name){        
    var checks = readCookie('dbchecked');        
    if (!checks){checks='';}    
    var obj = document.getElementById(name)
    if(checks.indexOf(name,0)<0){
        //er að haka við
        document.getElementById(name).checked=true;
        checks += name + '.';         
    }else {
        //er að taka hakið af
        document.getElementById(name).checked=false;
        checks = checks.replace(name + '.', '').replace(name + '.', '').replace(name + ',', '');
    };    
    createCookie('dbchecked', checks, 100);       
    /*var cookievalue = readCookie(name);
    if (cookievalue==null){cookievalue='checked'};   
    if (cookievalue=='checked'){cookievalue='off';document.getElementById(name).checked=false;}
    else {cookievalue='checked';document.getElementById(name).checked =true;}
    createCookie(name, cookievalue, 100); 
    createCookie('headInfoCount', 1, 30);
    createCookie('thedb', '', 30);     
    */
    createCookie('headInfoCount', 1, 30);
    createCookie('thedb', '', 30); 
}

function checkthisbox(name){    
    var obj = document.getElementById(name)
    if (obj){obj.checked =true;}
    var checks = readCookie('dbchecked');
   
    if (!checks){checks='';}
    checks += name + '.'; 
    createCookie('dbchecked', checks, 100);       
}
function uncheckthisbox(name){    
    try
    {
        //document.getElementById(name).checked =false;
        var obj = document.getElementById(name)
        if (obj){obj.checked =false;}
        var checks = readCookie('dbchecked');
        if (!checks){checks='';}
        checks = checks.replace(name + '.', '').replace(name + '.', '').replace(name + ',', '');
        createCookie('dbchecked', checks, 100);       
    }
    catch(err)
    {        
        alert(name);
    }    
}


function checkall(){
    checkthisbox('s8_isl2');
    checkthisbox('s8_stor2');
    checkthisbox('s8_alfrord2');
    //checkthisbox('s8_alfrbok2');
    checkthisbox('s8_staf2');
    checkthisbox('s8_nofn2');
    checkthisbox('s8_bey2');
    checkthisbox('s8_isda2');
    checkthisbox('s8_dais2');
    checkthisbox('s8_daislo2');
    checkthisbox('s8_isen2');
    checkthisbox('s8_isen_s2');
    checkthisbox('s8_enisjpv2');
    checkthisbox('s8_enis2');    
    checkthisbox('s8_enwn2');   
    checkthisbox('s8_fris2');
    checkthisbox('s8_spis2');
    checkthisbox('s8_isit2');
    checkthisbox('s8_mast2');
    checkthisbox('s8_nanna2');
    checkthisbox('s8_sam2');
    
    checkthisbox('s8_kort2');
    checkthisbox('s8_atlas2');
    checkthisbox('s8_deis2');
        
    /* checkthisbox('s8_en30_En2');   
    checkthisbox('s8_en30_Dk2');       
    checkthisbox('s8_en30_No2');   
    checkthisbox('s8_en30_Sv2');   
    checkthisbox('s8_en30_Fi2');   
    checkthisbox('s8_en30_De2');   
    checkthisbox('s8_en30_Es2');   
    checkthisbox('s8_en30_Fr2');   
    checkthisbox('s8_en30_It2');   
    checkthisbox('s8_en30_Pl2');   */
    checkthisbox('s8_en30_All2');   
}

function uncheckall(){
    uncheckthisbox('s8_isl2');
    uncheckthisbox('s8_stor2');
    uncheckthisbox('s8_alfrord2');
    uncheckthisbox('s8_alfrbok2');
    uncheckthisbox('s8_staf2');
    uncheckthisbox('s8_nofn2');
    uncheckthisbox('s8_bey2');
    uncheckthisbox('s8_isda2');
    uncheckthisbox('s8_dais2');
    uncheckthisbox('s8_daislo2');
    uncheckthisbox('s8_isen2');
    uncheckthisbox('s8_isen_s2');
    uncheckthisbox('s8_enisjpv2');
    uncheckthisbox('s8_enis2');  
    uncheckthisbox('s8_enwn2');     
    uncheckthisbox('s8_fris2');
    uncheckthisbox('s8_spis2');
    uncheckthisbox('s8_isit2');    
    uncheckthisbox('s8_mast2');
    uncheckthisbox('s8_nanna2');
    uncheckthisbox('s8_sam2');        
    uncheckthisbox('s8_kort2');
    uncheckthisbox('s8_atlas2');    
    uncheckthisbox('s8_deis2');
    /* uncheckthisbox('s8_en30_En2');       
    uncheckthisbox('s8_en30_Dk2');       
    uncheckthisbox('s8_en30_No2');   
    uncheckthisbox('s8_en30_Sv2');   
    uncheckthisbox('s8_en30_Fi2');   
    uncheckthisbox('s8_en30_De2');   
    uncheckthisbox('s8_en30_Es2');   
    uncheckthisbox('s8_en30_Fr2');   
    uncheckthisbox('s8_en30_It2');   
    uncheckthisbox('s8_en30_Pl2');   */
    uncheckthisbox('s8_en30_All2');   
}

function checkIs(){
    uncheckall();
    checkthisbox('s8_isl2');
    checkthisbox('s8_stor2');
    checkthisbox('s8_alfrord2');
    //checkthisbox('s8_alfrbok2');
    checkthisbox('s8_staf2');
    checkthisbox('s8_nofn2');
    checkthisbox('s8_bey2');    
    checkthisbox('s8_sam2');    
    checkthisbox('s8_kort2');    
    checkthisbox('s8_atlas2');    
}

function checkEn(){
    uncheckall();
    checkthisbox('s8_isen2');
    checkthisbox('s8_isen_s2');
    checkthisbox('s8_enisjpv2');
    checkthisbox('s8_enis2');   
    checkthisbox('s8_enwn2');       
}

/*function checkEn30(){
    uncheckall();    
     checkthisbox('s8_en30_En2');   
    checkthisbox('s8_en30_Dk2');   
    checkthisbox('s8_en30_No2');   
    checkthisbox('s8_en30_Sv2');   
    checkthisbox('s8_en30_Fi2');   
    checkthisbox('s8_en30_De2');   
    checkthisbox('s8_en30_Es2');   
    checkthisbox('s8_en30_Fr2');   
    checkthisbox('s8_en30_It2');   
    checkthisbox('s8_en30_Pl2');   
    checkthisbox('s8_en30_All2');       
}*/

function checkDa(){
    uncheckall();
    checkthisbox('s8_isda2');
    checkthisbox('s8_dais2');
    checkthisbox('s8_daislo2');    
    //__doPostBack('btn','');
}

function checkSp(){
    uncheckall();    
    checkthisbox('s8_spis2');    
    //__doPostBack('btn','');      
}

function checkDe(){
    uncheckall();        
    checkthisbox('s8_deis2');    
}



function checkFr(){
    uncheckall();
    checkthisbox('s8_fris2');    
    //__doPostBack('btn','');
}

function checkIt(){
    uncheckall();
    checkthisbox('s8_isit2');    
    //__doPostBack('btn','');
}

function checkMa(){
    uncheckall();
    checkthisbox('s8_mast2');
    checkthisbox('s8_nanna2');    
    //__doPostBack('btn','');
}


/*function checkAlfraedi(){
    uncheckall();    
    __doPostBack('btn','');
}*/

/*function checkLyklar(){
    uncheckall();
    checkthisbox('s8_saga2');
    checkthisbox('s8_hkl2');
    __doPostBack('btn','');
}*/

function search(sw){
    document.getElementById('sw').value = sw    
    /*document.getElementById('st_0').checked = true;
    document.getElementById('st_1').checked = false;*/
    if (document.getElementById('st_0').checked){
        __doPostBack('btn','');
       }else{
        __doPostBack('btn','doOrdSearch');
    }    
}

function searchfromtxt(sw){
    document.getElementById('sw').value = sw        
    __doPostBack('btn','doOrdSearch');
}

function search_enwn(type, i, t){
    var pins = readCookie('bookpins');        
    if (pins.indexOf('enwn,')==-1){createCookie('bookpins', 'enwn,', 30)}        
    createCookie('enwn_type', type, 100);
    createCookie('enwn_i', i, 100);
    search(t);
}

function postwith (to,p) {
  var myForm = document.createElement("sform");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}

function getSelText()
{    
    try{
        if (window.getSelection)
        {return window.getSelection();}
        else if (document.getSelection)
        {return document.getSelection();}
        else if (document.selection)
        {return document.selection.createRange().text;}
        else return;       
    }catch (err){}
}

function getSelText2()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
    return txt;
}

