window.onresize= supersizeme;

function supersizeme() {
  if(document.getElementById("product_x").style.visibility =='visible') {
	  scrollArr = new Array();
	  scrollArr = getPageSizeWithScroll(); 
	  document.getElementById("vail_layer").style.height = scrollArr[1]+'px';
	  document.getElementById("vail_layer").style.width = scrollArr[0]+'px';
	  
	  currentArr = new Array(); 
	  currentArr = getSize()
	  
	  iHeight = document.documentElement.scrollTop
	  iHeight = iHeight + (currentArr[1]/2) - 200;
			     				 
	  iCurrentWidth = document.documentElement.scrollLeft
	  iCurrentWidth = iCurrentWidth + (currentArr[0]/2) -375;	  
	  
	  document.getElementById("product_x").style.position ='absolute'; 
	  document.getElementById("product_x").style.top = iHeight+'px';
	  document.getElementById("product_x").style.left = iCurrentWidth+'px';
  }	  
}


/* start ajax */

var http_request = false;
   function postRequest(url, parameters) {      	
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	  
      http_request.onreadystatechange = returnProduct;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   /* end */

   function returnProduct() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {         	            
         	         	     	
         	/** Høyde/bredde med scroll */
         	scrollArr = new Array();
         	scrollArr = getPageSizeWithScroll();         	
			
         	/** Høyde/bredde current, kanskje :p */
         	currentArr = new Array(); 
         	currentArr = getSize()
         	
         	
            result = http_request.responseText.split('|');          
            result[0] = result[0].replace(/^\s+|\s+$/g, '') ;
            
            
             iHeight = document.documentElement.scrollTop
		     iHeight = iHeight + (currentArr[1]/2) - 200;
		     				 
		     iCurrentWidth = document.documentElement.scrollLeft
		     iCurrentWidth = iCurrentWidth + (currentArr[0]/2) -375;
		    
		     document.getElementById("vail_layer").style.height = scrollArr[1]+'px';
		     document.getElementById("vail_layer").style.width = scrollArr[0]+'px';
			 document.getElementById("vail_layer").style.visibility='visible';
			 
			 document.getElementById("product_x").style.position ='absolute'; 
			 document.getElementById("product_x").innerHTML =result[0];
			 document.getElementById("product_x").style.top = iHeight+'px';
			 document.getElementById("product_x").style.left = iCurrentWidth+'px';
			 document.getElementById("product_x").style.visibility='visible';
            
         } else {
            alert('Skriptet kunne ikke kjøres.');
         }
      }
   }   
 	
	function fetchProduct(id,target, spraak) {	
		//legg til eller fjern produkt fra forsidevisning		
		poststr="PId="+id+"&p_target="+target+"&p_spraak="+spraak;		
		postRequest('/webshop/product/fetchproduct.php', poststr);	
	}
	
	function fetchMuseumProduct(id,target, spraak) {	
		//legg til eller fjern produkt fra forsidevisning		
		poststr="PId="+id+"&p_target="+target+"&p_spraak="+spraak;		
		postRequest('/museum/fetchproduct.php', poststr);	
	}
	

function toggleOff () {
	   
	document.getElementById("vail_layer").style.visibility='hidden';
	document.getElementById("product_x").style.visibility='hidden';
}


function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX -17; // -17 > firefox scrollbar		
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		//yWithScroll = document.body.offsetHeight;		
		//xWithScroll = document.body.offsetWidth;
		yWithScroll = document.documentElement.scrollHeight;		
		xWithScroll = document.documentElement.scrollWidth;			
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);	
	return arrayPageSizeWithScroll;
}


function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  arrayPageSize = new Array(myWidth,myHeight);	
  return arrayPageSize;
  
}


function getRegion(id) {
	document.getElementById("activeRegion").value = id;
	document.getElementById("frmregionlist").submit();
}
