window.onload = function ()
{
        externalLinks();
        if (document.popup == null) document.popup = new isPopup();
};

/* Das Attribut target ist in XHTML nicht mehr erwünscht, deshalb diese Funktion verwenden.
   statt target="_blank" nun rel="external" nutzen
*/
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}

function insertFlash(i_minVersion, i_path, i_name, i_width, i_height,i_bgcolor, i_fb,i_usemap,i_pagelink) {
	if ((i_path.length > 1) && isFlash(i_minVersion)) {
		if(i_pagelink) {
			if (i_path.indexOf("?")>0) {
				//i_pagelink="&config="+escape(i_pagelink);
				//i_pagelink="&"+escape(i_pagelink);
				i_pagelink="&"+i_pagelink;
			} else {
				//i_pagelink="?config="+escape(i_pagelink);
				//i_pagelink="?"+escape(i_pagelink);
				i_pagelink="?"+i_pagelink;
			}

			var linkarray=i_pagelink.split("/");
			i_pagelink=linkarray.join("%2F");
			i_path=i_path+i_pagelink;
		}
		document.write('<div class="flash"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write(' codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"');
		document.write(' ID="' + i_name + '" WIDTH="' + i_width + '" HEIGHT="' + i_height + '">');
		document.write(' <PARAM NAME=movie VALUE="' + i_path +'"> ');
		document.write(' <PARAM NAME=quality VALUE=high> ');
		document.write(' <PARAM NAME=wmode VALUE=transparent> ');
		document.write(' <PARAM NAME=menu VALUE=false> ');
		document.write(' <param name="allowFullScreen" value="true"> ');
		document.write(' <PARAM NAME=bgcolor VALUE=#' + i_bgcolor + '> ');
		document.write('<EMBED SRC="' + i_path +'"');
		document.write(' NAME=' + i_name + ' swLiveConnect="TRUE" WIDTH="' + i_width + '" HEIGHT="' + i_height + '" wmode="transparent"');
		document.write(' QUALITY="high" menu="false" allowfullscreen="true" BGCOLOR="#' + i_bgcolor + '"');
		document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
		document.write('</EMBED>');
		document.write('</OBJECT></div>');
	}else {
		document.write('<div class="flash"><img src="' + i_fb+'" width="'+i_width+'" height="'+i_height+'" border="0" usemap="#'+i_usemap+'"></div>');
	}
}

function isFlash(inVersion) {
	FlashMode =0;
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
		if (navigator.plugins && navigator.plugins["Shockwave Flash"] && (versionIndex = navigator.plugins["Shockwave Flash"].description.indexOf(".")) != - 1) {
			var versionString = navigator.plugins["Shockwave Flash"].description.substring(versionIndex-2, versionIndex);
			versionIndex = parseInt( versionString );
			if ( versionIndex >= inVersion ) {
				FlashMode = 1;
			}
		}
	} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )) {
		theStr='FlashMode = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+inVersion+'"))) \n';
		document.write('<SCRIPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write(theStr);
		document.write('</SCRIPT\> \n');
	}
	return FlashMode;
}

function _gel(a) {
	return document.getElementById ? document.getElementById(a) : null
}

function fireClickEvent(sElementID)
{
	if (document.all) {
		var oElement = _gel(sElementID);
		bFired = oElement.fireEvent("onclick");
	} else {
		var clickEvent = window.document.createEvent("MouseEvent");
		clickEvent.initEvent("click", false, true);
		_gel(sElementID).dispatchEvent(clickEvent);
	}
}
function enable()
{
	var oButton = _gel("submitbutton");
	var oInfo = _gel("submitinfo");
	if (oButton)
	{
		oButton.disabled = false;
		oButton.style.display = "block";
	}
	if (oInfo)
	{
		oInfo.style.display = "none";
	}
}

function disable()
{
	var oButton = _gel("submitbutton");
	var oInfo = _gel("submitinfo");
	if (oButton)
	{
		oButton.disabled = true;
		oButton.style.display = "none";
	}
	if (oInfo)
	{
		oInfo.style.display = "block";
	}
}

function trim(sString)
{
	return (sString.replace(/\s+$/,"").replace(/^\s+/,""));
}

function checkFormValues(sForm)
{
	var bEnable = true;
	var oInput = null;
	
	switch (sForm) {
		case "product":
			var aInputs = new Array(
				"machinetype",
				"machinename",
				"fdnumber",
				"color",
				"color_of_spare_part",
				"color_of_cogwheel",
				"color_of_drive_cogwheel",
				"power_switch"
			);
			break;
		case "contact":
			var aInputs = new Array(
				"firstname",
				"lastname",
				"street",
				"housenumber",
				"zip",
				"city",
				"country",
				"phone",
				"email"
			);
	}
	
	for (var i = 0; i < aInputs.length; ++i)
	{
		oInput = _gel(aInputs[i]);
		if (oInput)
		{
			if (trim(oInput.value) == "" || oInput.value == 0)
			{
				bEnable = false;
			}
		}
	}

	if (sForm == "contact")
	{
		oInput = _gel("generalterms");
		if (oInput)
		{
			if (oInput.checked == false)
			{
				bEnable = false;
			}
		}
	}
	
	if (bEnable == true)
	{
		enable();
	}
	else
	{
		disable();
	}
}

function checkContactValues()
{
	var bEnable = true;
	
	var oMachineType = _gel("customernumber");
	if (oMachineType)
	{
		if (trim(oMachineType.value) == "")
		{
			bEnable = false;
		}
	}
	
	var oItemNumber = _gel("machinename");
	if (oItemNumber)
	{
		if (trim(oItemNumber.value) == "")
		{
			bEnable = false;
		}
	}
	
	var oFDNumber = _gel("fdnumber");
	if (oFDNumber)
	{
		if (trim(oFDNumber.value) == "")
		{
			bEnable = false;
		}
	}
	
	var oColor = _gel("color");
	if (oColor)
	{
		if (trim(oColor.value) == "")
		{
			bEnable = false;
		}
	}
	
	var oColorOfSparePart = _gel("color_of_spare_part");
	if (oColorOfSparePart)
	{
		if (trim(oColorOfSparePart.value) == "")
		{
			bEnable = false;
		}
	}
	
	var oColorOfCogwheel = _gel("color_of_cogwheel");
	if (oColorOfCogwheel)
	{
		if (trim(oColorOfCogwheel.value) == "")
		{
			bEnable = false;
		}
	}
	
	var oColorOfDriveCogwheel = _gel("color_of_drive_cogwheel");
	if (oColorOfDriveCogwheel)
	{
		if (trim(oColorOfDriveCogwheel.value) == "")
		{
			bEnable = false;
		}
	}
	
	if (bEnable == true)
	{
		enable();
	}
	else
	{
		disable();
	}
}
