function OpenDialogWithReturnValuesCustomer(strUrl,strHeight,strWidth,strTitle){
	var s = showModalDialog(WEBROOT + 'Customer/SpirelloSystem/Dialogs/dialogMain.aspx?Url='+ strUrl + '&Height=' + strHeight + '&Width=' + strWidth + '&Title=' + strTitle,window,'dialogHeight:' + strHeight + '; dialogWidth:' + strWidth + '; help: No; resizable: Yes; status: No; scroll: No;');
	return s;
}

function openDialog(strUrl,strHeight,strWidth,strTitle){
	window.open(strUrl +'&Title='+ strTitle, '_blank', 'height=' + strHeight + ',width=' + strWidth + ',status=no,toolbar=no,menubar=no,location=no,resizable=no');
}


// ------
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
  if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}

function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}


//popup for blueprints
function popupBluePrints(url, name)
{
	newwindow=window.open(url,name,'width=850, height=800, scrollbars=yes');
	if (window.focus){
		newwindow.focus();
	}
	return false;
}

//Function for adding flash by script to page
function flashMovie(version, filepath){
		var swf = '';
		swf += '<object id="flash"';
		swf += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		swf += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+',0,0,0">';
		swf += '<param name="movie" value="'+filepath+'">';
		swf += '<param name="wmode" value="transparent">';
		swf += '<embed src="'+filepath+'"';
		swf += ' wmode="transparent"';
		swf += ' type="application/x-shockwave-flash"';
		swf += ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
		swf += '<\/embed>';
		swf += '<\/object>';
		document.write(swf);	
}


function trackSelect(vpObj) {
	if(typeof vpObj != "undefined") { 
		var optionText = vpObj.options[vpObj.selectedIndex].text;
		if( typeof Instadia_sendEvent == "function"){ 
			Instadia_sendEvent("011k4", "Form Interaction", "form interaction/intresseanmälan/# projekt : " + optionText); 
		} 
	} 
	//window.setTimeout( function() { vpObj.submit(); }, 500 );
}

function SkipLinkInit(){
	//first determine the resolution
	var res = screen.availHeight;
	
	if(res <= 600){
		//check if there is a image or flash file
		if(document.getElementById("image-slides") != null){
			document.getElementById("skip-link").style.display = "block";	
		}
	}
}

function TrackStartPageImage(obj, pictureName){
	Instadia_sendEvent('011k4','Click on startpage # ' + pictureName);
}

var oldTab = null;
function InitTabs(){
	if(document.getElementById("TabMenu") != null){
		var TabObj = document.getElementById("TabMenu");
		var tabs = TabObj.getElementsByTagName("a");
		
		for(var i=0;i<tabs.length;i++){
			tabs[i].onclick = function(){
				var tabToShow = this.href;

				tabToShow = tabToShow.substring(tabToShow.indexOf("#")+1,tabToShow.length);
				
				switch(tabToShow){
					case "concept-apartment-tab":
						//hide other tab pages first
						for(var x=0;x<tabs.length;x++){
							
							if(tabs[x].parentNode.className == "selected")
								tabs[x].parentNode.className = "";
						}
						
						if(document.getElementById("apartments-tab") != null)
							document.getElementById("apartments-tab").style.display = "none";
						
						document.getElementById(tabToShow).style.display = "block";
						this.parentNode.className = "selected";
						
						//close popups
						ApartmentList.ClosePopup();
						return false;
					case "apartments-tab":
						//hide other tab pages first
						for(var x=0;x<tabs.length;x++){
							if(tabs[x].parentNode.className == "selected")
								tabs[x].parentNode.className = "";
						}
						
						if(document.getElementById("concept-apartment-tab") != null)
							document.getElementById("concept-apartment-tab").style.display = "none";
						
						document.getElementById(tabToShow).style.display = "block";
						this.parentNode.className = "selected";
						
						//close popups
						ApartmentList.ClosePopup();
						return false;
				}
			}
		}
	}
}
function InitSearchTable(){
	if(document.getElementById("search-list-current-projects") != null || document.getElementById("search-list-commin-projects") != null){
		var oTable = document.getElementsByTagName("table");
		for(var i=0;i<oTable.length;i++){
			if(oTable[i].className == "search-table"){
				var oTbody = oTable[i].getElementsByTagName("tbody");
				var oRows = oTbody[0].childNodes;
				for(var x=0;x<oRows.length;x++){
					oRows[x].onmouseover = function(){
						this.className = "hover";
					}
					oRows[x].onmouseout = function(){
						this.className = "";
					}
					oRows[x].onclick = function(){
						var aObj = this.getElementsByTagName("a");
						//window.location = aObj[0].href;
                                                window.open(aObj[0].href, "_blank");
						return false;
					}
				}
			}	
		}
	}
}
function AddInformation(){
	if(document.getElementById("project-list-info") != null){
		var chkBox = document.getElementsByTagName("input");
		var objDiv = document.getElementById("project-list-info");
		var ulObj =	document.createElement("ul");
		if (objDiv != null) {
			objDiv.style.display = "none";
			objDiv.innerHTML = "";
			document.getElementById(checkedArray).value = "";
			objDiv.appendChild(ulObj);
			for(var i=0;i<chkBox.length;i++){
				if(chkBox[i].className == "order-info-chkbox"){
					if(chkBox[i].checked){
						objDiv.style.display = "block";
						var liObj = document.createElement("li");
						var textObj = document.createTextNode(document.getElementById("proj-label-" + chkBox[i].id).innerHTML);
						document.getElementById(checkedArray).value += chkBox[i].id + "|";
						liObj.appendChild(textObj);
						ulObj.appendChild(liObj);
					}
					
					chkBox[i].onclick = function(){
						//remove content of div
						var objDiv = document.getElementById("project-list-info");
						var ulObj =	document.createElement("ul");
						objDiv.style.display = "none";
						objDiv.innerHTML = "";
						document.getElementById(checkedArray).value = "";
						objDiv.appendChild(ulObj);
						for(var x=0;x<chkBox.length;x++){
							if(chkBox[x].checked){
								objDiv.style.display = "block";
								var liObj = document.createElement("li");
								var textObj = document.createTextNode(document.getElementById("proj-label-" + chkBox[x].id).innerHTML);
								liObj.appendChild(textObj);
								ulObj.appendChild(liObj);
								document.getElementById(checkedArray).value += chkBox[x].id + "|";
							}
						}
					}
				}
			}
		}
	}
}

function validateDataForMailSending(){
	var formValid = true;
	var errorDiv = document.getElementById("error-messages");
	errorDiv.innerHTML = "";
	if(document.getElementById(checkedArray).value == ""){
		formValid = false;
		errorDiv.innerHTML += projChkError + "<br/>";
	}
	
	var strEmail = document.getElementById(emailField).value;
	pattern = new RegExp( "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$", "i" );
	if (!strEmail.match(pattern)){
		document.getElementById(emailField).className = "error";
		formValid = false;
		errorDiv.innerHTML += notValidEmail+ "<br/>";
	}
	
	if(formValid){
		return true;
	}
	else{
		return false;
	}
}

function showSearchHelp(){

	if (document.getElementById("search-help") != null || document.getElementById("search-help-textblock") != null){
		var searchHelp = document.getElementById("search-help");
		var searchHelpBlock = document.getElementById("search-help-textblock")
		searchHelp.onmouseover = function(){
			searchHelpBlock.style.display = 'block';
		}
		searchHelp.onmouseout = function(){
			searchHelpBlock.style.display = 'none';
		}
	}
}

window.onload = function(){
	var AllInputs = document.getElementsByTagName("input");
	for(var i=0;i<AllInputs.length;i++){
		if(AllInputs[i].className == "projectButton"){
			AllInputs[i].onclick = function(){
				var SelectList = document.getElementsByTagName("select");
				for(var x=0; x<SelectList.length;x++){
					if(SelectList[x].className == "projectContactTextBox"){
						trackSelect(SelectList[x]);
						return true;
					}
				}
			}
		}
	}
	
	if(document.getElementById("startPageImage1") != null){
		var obj = document.getElementById("startPageImage1");
		var imgElement = obj.getElementsByTagName("img");
		imgElement[0].onclick = function(){
			TrackStartPageImage(obj, "Picture 1");
		}
	}
	if(document.getElementById("startPageImage2") != null){
		var obj = document.getElementById("startPageImage2");
		var imgElement = obj.getElementsByTagName("img");
		imgElement[0].onclick = function(){
			TrackStartPageImage(obj, "Picture 2");
		}
	}
	if(document.getElementById("startPageImage3") != null){
		var obj = document.getElementById("startPageImage3");
		var imgElement = obj.getElementsByTagName("img");
		imgElement[0].onclick = function(){
			TrackStartPageImage(obj, "Picture 3");
		}
	}
	
	
	//NEW PRODUCTION PAGE
	//start slideshow
	if(Slides.slideShowTopImageArray != "")
		Slides.StartSlideShow();
	
	InitTabs();
	ExpandingHeadings.Init();
	ApartmentList.Init();
	SkipLinkInit();
	InitSearchTable();		
	CreateNPTopMenu();
	AddInformation();
	showSearchHelp();
}