// JavaScript Document
function validateAll() {
	var ret = false;
	if (!validateColor(document.createForm.heart_color.value, 'heart color')) {
		return ret;
	}
              if (!validateColor(document.createForm.background_color.value, 'background color')) {
		return ret;
	}
	var message = validateEnglishAlphabets(document.createForm.message.value);
	document.createForm.message.value = message;
	
	return true;
}
function getFlashVars() {
	var flashVars = 'heart_color=' + document.createForm.heart_color.value + '&';
	flashVars += 'background_color=' + document.createForm.background_color.value + '&';
	var message = document.createForm.message.value.replace(/\r\n/g, "\n");
	flashVars += 'message=' + escape(message) + '&';
	var speed = selectedValue(document.createForm.speed);
	flashVars += 'speed=' + speed + '&';
	return flashVars;
}
	
function getHtmlFromFlashVars(myFlashVars, mode) {
	var movieWidth = mode == 'myspace' || mode == 'sample' ? '250' : '300';
	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="' + movieWidth + '" height="70">' +
		  '<param name="movie" value="http://www.stunme.com/flash/heart_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/heart_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="' + movieWidth + '" height="70" ' +
		  'FlashVars="' + myFlashVars + '"></embed></object></a><br />';
	if (mode == 'myspace') {
		html +='<a href="http://www.myspace.com/heart_text" target="_top"><img src="http://www.stunme.com/images/heart_text/send_messages.gif" alt="Heart Scrolling Text" width="250" height="30" border="0" /></a><br /><a href="http://www.stunme.com" target="_blank"><img src="http://www.stunme.com/images/by_stunme_250.gif" width="250" height="16" border="0"/></a>';
	}
	else if (mode == 'sample') {
		html +='';
	}
	else {
		   html +='<a href="http://www.stunme.com" target="_blank"><img src="http://www.stunme.com/images/stunme_bar_300.gif" alt="Heart Scrolling Text" width="300" height="18" border="0" /></a><br />';
	}
	html += '</div>';
	return html;
}
function getCode() {
	validateAll();
	var flashVars = getFlashVars();
	document.createForm.embed_code.value = getHtmlFromFlashVars(flashVars, 'stunme');
	document.getElementById('gigya').src = '/widgets/heart_text/gigya?flash_vars=' + escape(flashVars);	
	document.getElementById('code').style.display = 'block';
}
function preview() {
	validateAll();
	var flashVars = getFlashVars();
	var thisHtml = getHtmlFromFlashVars(flashVars, 'stunme');
	document.getElementById('preview').innerHTML = thisHtml;
	document.createForm.embed_code.value = thisHtml;
}