// JavaScript Document
function validateAll() {
	var ret = false;
	if (!validateColor(document.createForm.background_color.value, 'background color')) {
		return ret;
	}
	else if (!validateColor(document.createForm.text_color.value, 'text color')) {
		return ret;
	}
	else if (!validateColor(document.createForm.mask_color.value, 'grain color')) {
		return ret;
	}

	var flashWidth = document.createForm.width.value;
	if (flashWidth < 200 || flashWidth > 700) {
		alert('invalid width!');
		document.createForm.width.value = 435;
		return ret;
	}
	var message = validateEnglishAlphabets(document.createForm.text.value);
	document.createForm.text.value = message;
	
	if (message == '') {
		alert('You must enter your text.');
		return ret;
	}
	return true;
}
function getFlashVars() {
	var flashVars = 'text=' + escape(document.createForm.text.value) + '&';
	flashVars += 'background_color=' + document.createForm.background_color.value + '&';
	flashVars += 'text_color=' + document.createForm.text_color.value + '&';
	flashVars += 'mask_color=' + document.createForm.mask_color.value + '&';
	flashVars += 'text_font=' + selectedValue(document.createForm.text_font) + '&';
	flashVars += 'text_size=' + selectedValue(document.createForm.text_size) + '&';
	flashVars += 'is_transparent=' + selectedValue(document.createForm.is_transparent) + '&';
	var flashWidth = document.createForm.width.value;
	if (flashWidth != undefined && flashWidth != '435');
		flashVars += 'width=' + document.createForm.width.value + '&';
	return flashVars;
}

function getHtmlFromFlashVars(myFlashVars) {
	getHtmlFromFlashVars(myFlashVars, 435);
}

function getHtmlFromFlashVars(myFlashVars, width) {
	var html = '<br /><div style="white-space: nowrap; line-height:0px; vertical-align: baseline"><a href="http://www.stunme.com" target="_blank">' +
		  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +	
          'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" ' +
		  'width="' + width + '" height="140">' +
		  '<param name="movie" value="http://www.stunme.com/flash/glitter_text.swf" />' +
		  '<param name="quality" value="high" />' +
		  '<param name="menu" value="false" />' +
		  '<param name="wmode" value="transparent" />' +
		  '<param name="FlashVars" value="' + myFlashVars + '">' +
		  '<embed src="http://www.stunme.com/flash/glitter_text.swf" quality="high" menu="false"  wmode="transparent" ' +    
		  'pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" ' +
		  'type="application/x-shockwave-flash" width="' + width + '" height="140" ' +
		  'FlashVars="' + myFlashVars + '"></embed></object></a><br />';
	if (width == 435) {
		  html += '<a href="http://www.stunme.com" target="_blank"><img src="http://www.stunme.com/images/stunme_bar_435.gif" alt="Cool Widgets" width="435" height="18" border="0" /></a><br />';
	}
	else if (width == 250) {
		  html += '<a href="http://www.stunme.com" target="_blank"><img src="http://www.stunme.com/images/stunme_bar_250.gif" alt="Cool Widgets" width="250" height="18" border="0" /></a><br />';
	}
	else {
		var blackWidth = width - 190;
		html += '<a href="http://www.stunme.com" target="_blank"><img src="http://www.stunme.com/images/stunme_bar_90.gif" alt="Cool Widgets" width="90" height="18" border="0" /><img src="http://www.stunme.com/images/black.gif" alt="Stun Me" width="' + blackWidth + '" height="18" border="0" /><img src="http://www.stunme.com/images/stunme_bar_get_cool_widgets.gif" alt="Stun Me" width="100" height="18" border="0" /></a><br />';
	}
	html += '</div>';
	return html;
}
function getCode() {
	if (!validateAll()) {
		return;
	}
	var flashVars = getFlashVars();
	var flashWidth = document.createForm.width.value;
	document.createForm.embed_code.value = getHtmlFromFlashVars(flashVars, flashWidth);
	document.getElementById('gigya').src = '/widgets/glitter_text/gigya?width=' + flashWidth + '&flash_vars=' + escape(flashVars);	
	document.getElementById('code').style.display = 'block';
}
function preview() {
	if (!validateAll()) {
		return;
	}
	var flashVars = getFlashVars();
	var flashWidth = document.createForm.width.value;
	document.getElementById('preview').innerHTML = getHtmlFromFlashVars(flashVars, flashWidth);
}
