﻿// JScript File

		var popupLeft = 100;
		var popupTop = 100;
		var popupWidth  = 500;
		var popupHeight = 500;
		var popupAutoClose = true;
		if (parseInt(navigator.appVersion.charAt(0))>=4){
			var isNN=(navigator.appName=="Netscape")?1:0;
			var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
		}
		var optNN='width='+popupWidth+',height='+popupHeight+',left='+popupLeft+',top='+popupTop+',scrollbars=no';
		var optIE='width=150,height=100,left='+popupLeft+',top='+popupTop+',scrollbars=no';
		
		function PopupPic(imgURL, imgTitle){
			var theImg=imgURL;
			theImg=theImg.replace(/w=290/gi,'w=800').replace(/h=250/gi,'h=600');
			theImg=theImg.replace(/w=320/gi,'w=800').replace(/h=197/gi,'h=600');
			
	
			
			if (isNN){theWin=window.open('','',optNN);}
			if (isIE){theWin=window.open('','',optIE);}
			with (theWin.document){
				writeln('<html><head><title>maskinmarknaden.se</title><style>body{margin:0px;}</style>');
				writeln('	<'+'script>');
				writeln('		var isNN,isIE;');
				writeln('		if (parseInt(navigator.appVersion.charAt(0))>=4){');
				writeln('			isNN=(navigator.appName=="Netscape")?1:0;');
				writeln('			isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
				writeln('		function reSizeToImage(){');
				writeln('			if (isIE){');
				writeln('				window.resizeTo(300,300);');
				writeln('				width=300-(document.body.clientWidth-document.images[0].width);');
				writeln('				height=300-(document.body.clientHeight-document.images[0].height);');
				writeln('				window.resizeTo(width,height);}');
				writeln('			if (isNN){');       
				writeln('				window.innerWidth=document.images["mmImage"].width;');
				writeln('				window.innerHeight=document.images["mmImage"].height;}}');
				writeln('		function doTitle(){document.title="'+imgTitle+'";}');
				writeln('	</'+'script>');
				if (!popupAutoClose) 
					writeln('</head><body bgcolor="#ffffff" scroll="no" onLoad="reSizeToImage();doTitle();self.focus()">')
				else
					writeln('</head><body bgcolor="#ffffff" scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
				writeln('<img name="mmImage" src='+theImg+' style="display:block; cursor:pointer;" onclick="window.close();"></body></html>');
				close();		
			}
		}


    function showHide(elem)
    {
        var obj = document.getElementById(elem);
        if(obj.style.display == 'none')
        {
            obj.style.display = 'block';
        }
        else
        {
            obj.style.display = 'none';
        }
        
    }
    
    function HideWithTimer(elem)
    {
        
        var obj = document.getElementById(elem);  
        obj.style.display = 'block';
        setTimeout('document.getElementById(\'' + elem + '\').style.display = \'none\';',3000);
       
    }
    
    function checkTextOnFocus(text,controlid)
    {
        var ctrl = document.getElementById(controlid);
        
        if(ctrl.value == text)
            ctrl.value = '';
    }
    
    function checkTextOnBlur(text,controlid)
    {
        
        var ctrl = document.getElementById(controlid);
    
        if(ctrl.value == '')
            ctrl.value = text;
    }
    
    function RedirectToDetail(guid)
    {
        document.location="Search.aspx?adGUID=" + guid;
    }
    
    function RedirectToExportDetail(guid,type,custdistGUID,searchguid,page)
    {
        document.location="ExportDetail.aspx?" + type +"="+custdistGUID+"&adGUID=" + guid + "&searchguid=" + searchguid + "&dosearch=y&page="+page;
    }
    
    function hoverColor(obj)
    {
        obj.className = 'searchRowHover';
        
    }

    function outColor(obj)
    {
        obj.className = 'searchRow';
    }
    
    function changeMainImage(url,controlName)
    {
        var mainImage = document.getElementById(controlName);
        mainImage.src = url;
        
        
    }
    
    function countCompare()
    {
        var cntCheckedBoxes = 0;
        for (var i=0;i<document.forms[0].length;i++)
        {
            
            if (document.forms[0].elements[i].type=="checkbox")
            {
                if(document.forms[0].elements[i].checked)
                    cntCheckedBoxes++;
            }
        }
        
       if(cntCheckedBoxes <2)
       {
            alert('Du måste välja minst två objekt att jämföra');
            return false;
       }
        
        return true;
    }
    function searchHeadOut(obj){obj.className = 'inactive';}
    function searchHeadHover(obj){obj.className = 'active';}
    
    
    function validateInputs(name, phone, inValidName, inValidPhone)
    {
        var name = $get(name);
        var phone = $get(phone);

        retval = true;

        if(name.value == inValidName)
        {
            //visa div
            alert(name.value);
            retval = false;
        }
        
        if(phone.value == inValidPhone)
        {
            //visa div
            alert(phone.value);
            retval = false;  
        }
        
        return retval;
        
    }
    
 function GetViewportWidthHeight()
 {
 var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
}
 
 
 function showSearchDiv(text, beforetext)
{
var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
    
    //!!Divarna finns i SearchRes.ascx!!
    //Laddar in "snurr" bilden
    setTimeout('document.images["theSnurra"].src = "img/snurra.gif"', 1);
    var search = document.getElementById('divSearching');
    
    var divsearchtext = document.getElementById('divSearchText');
	//divsearchtext.style.position = 'absolute'
	var scrollpos = 0;
	//divsearchtext.style.left = '0px';
	if (document.documentElement && !document.documentElement.scrollTop)
         scrollpos = 0;
    else if (document.documentElement && document.documentElement.scrollTop)
        scrollpos = document.documentElement.scrollTop
    else if (document.body && document.body.scrollTop)
        scrollpos = document.body.scrollTop
    
    //Ställer in höjd, bredd, färg etc på "sök-diven"
    search.style.height = '1000px';
    search.style.position = 'absolute';
    search.style.backgroundColor = '#ffffff';
    search.style.top = '0px';
    search.style.left = '0px';
    search.style.display = 'block';
    search.style.width = '760px';
    //Sätter opacity på sök-diven
    search.style.filter = 'alpha(opacity=75)'; //IE
	search.style.mozOpacity = '.75'; //FF 1.0
	search.style.opacity = '.75'; //FF 
	
	
	var sr = document.getElementById('searchResult');

	var myArray = new Array();
	
	myArray = findPos(sr);
	searchresultYpos = myArray[1];
	
	//sätter position, storlek o text på söktext-diven
	//var searchtext = document.getElementById('searchtext');
	//searchtext.innerHTML = beforetext + ' ' + text;
	divsearchtext.style.display = 'block';
    divsearchtext.style.position = 'absolute';
    divsearchtext.style.width = '760px'
    divsearchtext.style.left = '0px';
    
	divsearchtext.style.top = (50)+'px';
	
}

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 doExpand(theDiv){
		var d=document.getElementById(theDiv);
		if(d){
			if((d.style.display=='none')||(d.style.display==''))
				d.style.display='block';
			else {
				d.style.display='none';
				}
		}
	}
	
		var cRow = null;
	function hRow(row_obj){
		if(cRow){row_obj.className=cRow.className.substr(0,cRow.className.length-5);cRow = null;}
		else{cRow = row_obj;cRow.className=cRow.className+'Hover';}
}


