/*
I am using this from the blainroe.com weather widget as the guide
<script src='http://netweather.accuweather.com/adcbin/netweather_v2/netweatherV2.asp?partner=netweather&tStyle=normal&logo=1&zipcode=EUR|IE|EI026|WICKLOW|&lang=uke&size=8&theme=spring1&metric=1&target=_blank'></script>
*/

function generateQueryString( stockistId, siteCaddyClientId, bgColor, useJavascript, linkStyle, linkText, linkImage ) {

	var query = "";
	
	if ( stockistId != null && stockistId.length > 0 ) {
		if ( query.length > 0 ) query += '&';
		query += 'sid=' + stockistId;
	}
	
	if ( siteCaddyClientId != null && siteCaddyClientId.length > 0 ) { 
		if ( query.length > 0 ) query += '&';
		query += 'sc=' + siteCaddyClientId;
	}
	
	if ( useJavascript != null && useJavascript.length > 0 ) { 
		if ( query.length > 0 ) query += '&';
		query += 'js=' + useJavascript;
	}
	
	if ( linkStyle != null && linkStyle.length > 0 ) { 
		if ( query.length > 0 ) query += '&';
		query += 'linkStyle=' + linkStyle;
	}
	
	if ( linkText != null && linkText.length > 0 ) { 
		if ( query.length > 0 ) query += '&';
		query += 'linkText=' + escape( linkText );
	}
	
	if ( linkImage != null && linkImage.length > 0 ) { 
		if ( query.length > 0 ) query += '&';
		query += 'linkImage=' + linkImage;
	}
	
	if ( bgColor != null && bgColor.length > 0 ) {
		if ( query.length > 0 ) query += '&';
		query += 'bgc=' + bgColor;
	}
	
	if ( query.length > 1 ) {
		query = '?' + query;
		return query;
	}
	else return '';
}

function generateFlashCode() {

	// Set up basic variables
	var markup = '';
	var f = document.scBBform;	// get a reference to the form

	// Get the information from the form
	var stockistId = f.stockistId.value;
	var siteCaddyClientId = f.siteCaddyClientId.value;
	var bgColor = f.bgColor.value;
	var useJavascript = f.useJavascript.checked;
	var linkStyle = f.linkStyle;
	for ( i=0; i<f.linkStyle.length; i++) {
		if ( f.linkStyle[i].checked == true )
			linkStyle = f.linkStyle[i].value;
	}
	var linkText = f.linkText.value;
	var linkImage = f.linkImage.value;
	
	// Validate the form input
	var errorMessage = '';
	if ( stockistId == null || stockistId.length < 1 ) 
		errorMessage += 'Enter the stockist ID provided by Shanore.\n';
	if ( linkStyle == '0' )
		if ( f.linkText.value == null || f.linkText.value.length < 1 )
			errorMessage += 'Enter the text for the link.\n';
	if ( errorMessage.length > 0 ) {
		
		errorMessage = 'Please correct the following problems and resubmit the form:\n\n' + errorMessage + '\nPress OK to continue.';
		alert( errorMessage );
		return;
	}

	// Get the base URL depending on what server we are working on	
	var baseUrl = 'http://www.tarasdiaryjewelry.com/mysitecaddy/';
	var loc = window.location + "";
	var found = loc.indexOf( "site3" );
	if ( found != -1 )
		baseUrl = loc.substr( 0, found );
	baseUrl += 'script.tara';
	
	// set the text box to the proper link
	markup = "<script src='" + baseUrl + generateQueryString( stockistId, siteCaddyClientId, bgColor, useJavascript, linkStyle, linkText, linkImage ) + "'></script>";
	f.outputtext.value = markup;
	return;
}

