function show_photo(text,file,width,height){
	no=window.open("", "zoom", "left=5, top=5, width="+width+", height="+height+", toolbar=no, location=no, status=no, scrollbars=auto");
	with (no.document)
	{
		open();
		writeln('<body style="margin: 0px;"><a href="javascript:void window.close();"><img src="'+file+'" style="border: 0px;" /></a></body>');
		close();
		no.focus();
	}
}

function openWindow(text,file,width,height,type){
	if (type=='img'){
		no=window.open("", "zoom", "left=5, top=5, width="+width+", height="+height+", toolbar=no, location=no, status=no, scrollbars=auto");
		with (no.document)
		{
			open();
			writeln('<body style="margin: 0px;"><a href="javascript:void window.close();"><img src="'+file+'" alt="'+text+'"style="border: 0px;" /></a></body>');
			close();
			no.focus();
		}
	}
	if (type=='file'){
		window.open(file, "zoom", "left=5, top=5, resizable,toolbar=no, location=no, status=no, scrollbars=yes");
		
		
	}
	return false;
}

function changeImage (url,foto) {
	if (document.getElementById) {
    	//window.alert(foto);    
                document.getElementById('mainphoto').src = url;
                document.getElementById('largephoto').href = foto;
               // photo_id = fotka_id;
        }
        return false;
}

function showLargeImage(url,width,height,type) {
	if (screen.height) {
		screenY = screen.height
		screenX = screen.width
	}
	var top = ((screenY/2)-(height/2));
	var left = ((screenX/2)-(width/2));
	window.open(url,'','resizable=no,status=no,scrollbars=no,width='+width+',height='+height+',top=50,left=50');
	return false;
}

function newWindow(url){
	x = window.open(url, "new_win", "");
	if (x) return false;
}

function ajax(url,idElement){
	if (url != 0){
		if (window.ActiveXObject){
    		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
        else{
			httpRequest = new XMLHttpRequest();
		}
    	httpRequest.open("GET", url+'&popisek='+idElement, true);
        httpRequest.onreadystatechange= function () {processRequest(idElement); } ;
        httpRequest.send(null);
	}
	else{
		document.getElementById(idElement).innerHTML = "";
	}
	//setTimeout("alert('"+idElement+"')",10);
}

function processRequest(element){
	if (httpRequest.readyState == 4){
		if(httpRequest.status == 200){
			var vystup = document.getElementById(element);
			vystup.innerHTML = httpRequest.responseText;
		}
		else{
			alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
		}
	}
}

// vlozime id prvku jako parametr, pokud je viditelny, skryje se a naopak
function ShowORhidden(prvek){
	if (document.getElementById(prvek).style.display == 'none' || document.getElementById(prvek).style.display == '')
		document.getElementById(prvek).style.display='block';
	else
		document.getElementById(prvek).style.display='none'
}

// Funkce pro vypocet teras Deck Clic

function setMetricEqual(){

	choseLMetric = "";
	choseWMetric = "";
	
	choseLMetric = document.frmDIY.cmbboxLMetric.value;
	choseWMetric = document.frmDIY.cmbboxWMetric.value;
	
	if(choseLMetric != choseWMetric){
		alert("Please kindly make sure the Metric Measurements are both the same.");
		document.frmDIY.cmbboxLMetric.value = "cm";
		document.frmDIY.cmbboxWMetric.value = "cm";
		return false;
	}

}

function calculate(){ 
	productAreaChosen = document.getElementById("frmDIY").cmbboxProductSpec.value;
	
	//alert("calculate()");
	setMetricEqual();
	givenLength = 0;
	givenWidth = 0;
	givenLMetric = "";
	givenWMetric = "";
	//alert("calculate()1");
	givenLength = document.frmDIY.txtLength.value;
	givenLMetric = document.frmDIY.cmbboxLMetric.value;
	givenWidth = document.frmDIY.txtWidth.value;
	givenWMetric = document.frmDIY.cmbboxWMetric.value;
	//productAreaChosen = document.frmDIY.cmbboxProductSpec.value;
	
	if(productAreaChosen == "SA.4545.5"){
		productArea = "202500";
	}
	else if(productAreaChosen == "SB.4590.5"){
		productArea = "405000";
	} 
	else if(productAreaChosen == "SC.9090.10"){ 
			productArea = "810000";
	}       
	else if(productAreaChosen == "PA.4545.6"){
			productArea = "202500";
	}         
	else if(productAreaChosen == "PB.4590.6"){
		productArea = "405000";
	}         
	else if(productAreaChosen == "PC.9090.12"){
		productArea = "810000";
	}        
	else if(productAreaChosen == "EA.1.4545"){
		productArea = "202500";
	}         
	else if(productAreaChosen == "EA.2.4545"){
		productArea = "202500";
	}         
	else if(productAreaChosen == "EA.3.4545"){
		productArea = "202500";
	}         
	else if(productAreaChosen == "EA.44545"){ 
		productArea = "202500";
	}        
	else if(productAreaChosen == "EA.5.4545"){ 
		productArea = "202500";
	}        
	else if(productAreaChosen == "EB.1.4590"){ 
		productArea = "405000";
	}        
	else if(productAreaChosen == "EB.2.4590"){  
		productArea = "405000";
	}       
	else if(productAreaChosen == "EC.1.9090"){ 
		productArea = "810000";
	}        
	else if(productAreaChosen == "EC.2.9090"){  
		productArea = "810000";
	}
	
	// Conversion - Length
	if(givenLMetric == "cm"){
		convertedLength = givenLength * 10;
	}	
	//alert("calculate()2");
	if(givenLMetric == "m"){
		convertedLength = givenLength * 1000;
	}	
	
	if(givenLMetric == "inch"){
		convertedLength = givenLength * 25.4;
	}	
	
	if(givenLMetric == "feet"){
		convertedLength = givenLength * 304.5;
	}	
	
	// Conversion - Width
	if(givenWMetric == "cm"){
		convertedWidth = givenWidth * 10;
	}	
	
	if(givenWMetric == "m"){
		convertedWidth = givenWidth * 1000;
	}	
	
	if(givenWMetric == "inch"){
		convertedWidth = givenWidth * 25.4;
	}	
	
	if(givenWMetric == "feet"){
		convertedWidth = givenWidth * 304.5;
	}	
	
	totalGivenArea = convertedLength * convertedWidth;
	
	calSolution = Math.round(totalGivenArea / productArea);
	//alert ("calSolution="+calSolution+",totalGivenArea="+totalGivenArea+",productArea="+productArea);
	if (productArea!=0)
		document.frmDIY.txtSolution.value = calSolution;
	else
		document.frmDIY.txtSolution.value = 0;
}
