//Input validation for the budget field in the Designing page

var num = '0123456789.,';

function isValid(parm,val) {
	if (parm == "") return false;
	for (i=0; i<parm.length; i++) {
		if (val.indexOf(parm.charAt(i),0) == -1) return false;
	}
	return true;
}

function isNum(parm){return isValid(parm,num);}

function checkInt(event){

	var	budgetField = document.getElementById('budget');
	var lastChar = budgetField.value.charAt(budgetField.value.length-1);
	
	if (!isNum(budgetField.value) && document.getElementById('fittobudget').checked){
		if(typeof event.preventDefault != "undefined")
		{
			event.preventDefault();
		}
		else //For internet explorer
		{
			event.returnValue=false;
		}
		
		if (!document.getElementById("error")){
			var strong = document.createElement("strong");
			var error = document.createElement("span");
			error.id = "error";
			error.appendChild(strong);

/*			if(budgetField.value==""){
				strong.appendChild(document.createTextNode("The field cannot be empty!"));
				budgetField.parentNode.appendChild(error);
			}
			else
			{*/
				strong.appendChild(document.createTextNode("Only numbers are allowed!"));
				budgetField.parentNode.appendChild(error);				
/*			}*/
		}
	}
}
function jsfAttachEvent(obj,evt,fnc)
{
	if(window.addEventListener)
	{
		obj.addEventListener(evt, fnc, false);
	}
	else if(window.attachEvent)
	{
		obj.attachEvent('on'+evt, fnc);
	}
	else if (obj.getElementById && evt=='load')
	{
		obj.onload = fnc;
	}
}

jsfAttachEvent(window,'load',checkBudget)

function checkBudget(){
	if (document.getElementById('build'))
	{
		jsfAttachEvent(document.getElementById('build'),'click',checkInt);
	}
}

// Function passes flash selection to form field
function flashSelectRegion(id){
	document.getElementById('place').value=id;
}

/* Flash detection script */
// This script will test up to the following version.
flash_versions = 10;
// Initialize variables and arrays
var flash = new Object();
flash.installed=false;
flash.version='0.0';
// Dig through Netscape-compatible plug-ins first.
if (navigator.plugins && navigator.plugins.length)
{
 for (x=0; x < navigator.plugins.length; x++)
 {
  if (navigator.plugins[x].name.indexOf('Shockwave Flash') != -1)
  {
   flash.version = navigator.plugins[x].description.split('Shockwave Flash ')[1];
   flash.installed = true;
   break;
  }
 }
}
// Then, dig through ActiveX-style plug-ins afterwords
else if (window.ActiveXObject)
{
 for (x = 2; x <= flash_versions; x++)
 {
  try {
   oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + x + "');");
   if(oFlash)
   {
    flash.installed = true;
    flash.version = x + '.0';
   }
  }
  catch(e) {}
 }
}
// Create sniffing variables in the following style: flash.ver[x]
flash.ver = Array();
for(i = 4; i <= flash_versions; i++)
{
 eval("flash.ver[" + i + "] = (flash.installed && parseInt(flash.version) >= " + i + ") ? true :  false;");
}

function includeFlash(flashFilePath, width, height, flashId, NotFlash)
{
	var flashDiv = document.getElementById(flashId);
	var noFlashDiv = document.getElementById(NotFlash);
	if(flash.installed)
		{
			if(noFlashDiv)
			{
				noFlashDiv.style.display="none";
			}
			flashDiv.innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"' ><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+flashFilePath+"' /><param name='quality' value='high' /><embed src='"+flashFilePath+"' quality='high' width='"+width+"' height='"+height+"' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
		}
}

function showResults()
{
	var message = document.getElementById("msgShow01");
	if(message != null) message.style.display = "block";
}
