﻿
function hideDocumentElement(id) 
{
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) 
{
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}

function applyImageWidth() 
{
	var figures = document.getElementsByClassName('figure'), figure, image;
	var i = 0;
	var captions, caption;
	
	// Adjust all figure elements to the width of the containing image
	for ( i = 0; i < figures.length; ++i ) {
		figure = figures[i];
		image = figure.getElementsByTagName("img")[0];
		figure.style.width = image.clientWidth + "px";
	}
	
	// IE check
	var ie = false
	try {
		ie = document.body.currentStyle.hasLayout;
	}
	catch(err) {
		// Nothing to do, everything works beautifully in standard browsers
	}
	
	// Make all figures visible
	for ( i = 0; i < figures.length; ++i ) {
		figures[i].style.visibility = "visible";
		if(ie) {
			captions = figures[i].getElementsByTagName("p");
			for (var j = 0; j < captions.length; ++j ) {
				caption = captions[j];
				caption.style.display = "inline-block"; 
			}
		}
	}
	


}

document.getElementsByClassName = function(clsName)
{
	var retVal = new Array();
	var elements = document.getElementsByTagName("*");
	for(var i = 0;i < elements.length;i++){
		if(elements[i].className.indexOf(" ") >= 0){
			var classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++){
				if(classes[j] == clsName)
					retVal.push(elements[i]);
			}
		}
		else if(elements[i].className == clsName)
   			retVal.push(elements[i]);
	}
	return retVal;
}

function dealerAreaVisibility(radio)
{

	if(radio.checked)
	{
		showDocumentElement('dealerArea');
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctrlCompanyNameValidator'), true); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyPhoneValidator'), true); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyStreetValidator'), true); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyZipCodeValidator'), true); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyCityValidator'), true); 
	}
	else
	{
		hideDocumentElement('dealerArea');
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctrlCompanyNameValidator'), false); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyPhoneValidator'), false); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyStreetValidator'), false); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyZipCodeValidator'), false); 
		ValidatorEnable(document.getElementById('ctl00_ctl00_MainContent_Content_ctlCompanyCityValidator'), false); 
	}


}


function controlLength(id)
{
	MaxLength = 200;

	if (document.getElementById(id).value.length >= MaxLength)
	{
		document.getElementById(id).value = document.getElementById(id).value.substring(0,MaxLength -1 )
	
		alert('Beskrivningen kan maximalt vara ' + MaxLength + ' tecken!');
		return false;
	}
	return true;
}

function createFlash(flashPath, width, height) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ width +'" height="'+ height +'" id="case_smooth" align="middle">' +
	'<param name="allowScriptAccess" value="sameDomain" />' +
	'<param name="movie" value="'+ flashPath +'" />' +
	'<param name="quality" value="best" />' +
	'<param name="bgcolor" value="#ffffff" />' +
	'<embed src="'+ flashPath +'" quality="best" bgcolor="#ffffff" width="'+ width +'" height="'+ height +'" name="case_smooth" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
	'</object>\n');
}




