var nextSib;

var newwindow;

function displayParkingSpace(request, id, address, type, width, height, scale)
{
	//var obj = document.forms(0);			
	var param = '?Request='+request+'&ID='+id+'&Type='+type+'&Width='+width;
	param = param+'&Height='+height+'&Scale='+scale+'&Address='+address;
	document.getElementById('mapFrame').src = 'http://gi.wspgroup.se/shemparkeringswebb/MapPage.aspx'+param;
}

function ToggleDiv(DivName) { 
    with (document.getElementById(DivName).style) { 
        if (display == "none") {
            display = "";
        } else {
            display = "none"; 
        }
    }
}

function poptastic(url)
{
	var newwindow=window.open(url,'name','resize','height=480,width=640');
	if (newwindow) newwindow.focus();
}

function popnewwindow(url,name,params)
{
	var newwindow=window.open(url,name,params);
	if (newwindow) newwindow.focus();
}

function popApartment(img, address){
  var generator=window.open('','apartmentImage','height=480,width=640,menubar=yes');   
  
  generator.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n');
  generator.document.write('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n');
  generator.document.write('<html lang="sv">\n<head>\n<title>' + address + '</title>\n');
  generator.document.write('<link rel="stylesheet" type="text/css" media="screen" href="/PageUI/Styles/default.css">\n');
  generator.document.write('</head>\n<body>\n');
  generator.document.write('<br/>\n');    
  generator.document.write("<div style=\"margin-left:10px;\"><img src='" + img + "' alt='" + address + "'/>\n");
  generator.document.write('<p style=\"margin-top:3px;\">' + address + '<a style=\"float: right; margin-top: -1.4em; margin-right: 10px;\" href="#" onclick=\"window.close()\"> St&auml;ng detta f&ouml;nster</a></p></div>\n');
  generator.document.write('<br/>\n');  
  generator.document.write('</body>\n</html>');
  generator.document.close();
  if (generator) generator.focus();
}

function closeInfoBox(obj)
{
	nextSib.className = "popup-module";
	nextSib.style.visibility = "hidden";
	return false;
}

function showInfoBox(obj)
{		
	if(nextSib)
		nextSib.style.visibility = "hidden";
		
	
	
	// Find next sibling
	nextSib = obj.nextSibling;
	while(nextSib.nodeName != "DIV" && nextSib.nextSibling != undefined)
	{
		nextSib = nextSib.nextSibling;		
	}
	
	// position object		
	//var x = obj.offsetLeft;
	//var y = obj.offsetTop;
	
	//var alignObj = obj;
	//var tempObj = alignObj;
	
	/*while (tempObj.offsetParent.tagName != "BODY"){
		x += tempObj.offsetLeft;
		y += tempObj.offsetTop;
		tempObj = tempObj.offsetParent;			
	}
	
	x += tempObj.offsetLeft;
	y += tempObj.offsetTop;*/
					
	nextSib.className = "popup-module-active";
					
	//nextSib.style.left = (x - 20) + "px";
	
	//nextSib.style.top = (y + 25) + "px";
	nextSib.style.visibility = "visible";
	
	return false;
}

function clearInputField(field, value)
{
	if(field.value == value)
		field.value = "";	
}


function getElementByPartialId(strPartialId, tagName)
{
	if(typeof strPartialId != "string") 
		return null;
	var tagName = tagName || "*";
	var coll = document.getElementsByTagName(tagName);
	for(i=0; i<coll.length; i++)
	{
		if(coll[i].id.indexOf(strPartialId) > -1)	
			return coll[i];
	}
	return null;
}

function getElementsByPartialId(strPartialId, tagName)
{
	var ary = [];
	if(typeof strPartialId != "string") 
		return ary;
	var items = 0;	
	var tagName = tagName || "*";
	var coll = document.getElementsByTagName(tagName);
	for(i=0; i<coll.length; i++)
	{
		if(coll[i].id.indexOf(strPartialId) > -1)
		{
			ary[items] = coll[i];
			items++;
		}
	}
	return ary;
}

$(document).ready( function() {
    $('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
    TextDocumentLinksRemoveTranslation();
    RemoveGoogleTranslationSourceTextForMainHeader();
});


//Fix so google translate doen´t translate linked documents
function TextDocumentLinksRemoveTranslation() {
	var regExp = new RegExp('http://.*/translate_c?.*u=(.*.(pdf|txt|doc|xls|docx))&.*');
	jQuery.each($('#content-area a'), function() {
		var href = $(this).attr('href');
		var match = regExp.exec(href);
		if (match != null) {
			$(this).attr('href', match[1]);
		}
    });
}

function RemoveGoogleTranslationSourceTextForMainHeader() {
	$("h1 .google-src-text").replaceWith("");
}