// (c) 2000-2006 ricocheting.com

window.onload=function(){ToggleEnableStyles();}

//################################
// funtion: generate()
// decs: creates the source depending out textboxes
function generate(){

	var f=document.myForm;
	var customname=f.customname.value;
	var targetname=f.targetname.value;
	var targetStr='';
	var styleStr='';

	// type of form
	if(f.target.selectedIndex==1){
		targetStr='top.';
	}
	else if(f.target.selectedIndex==2){
		targetStr='top.frames[\''+f.targetname.value+'\'].';
		if(f.targetname.value.length==0){alert('Please enter the name of the frame to target.');}
	}
	else if(f.target.selectedIndex==3){
		targetStr=f.targetname.value+'.';
		if(f.targetname.value.length==0){alert('Please enter the name of the window to target.');}
	}
	else if(f.target.selectedIndex==4){
		targetStr=''+f.targetname.value+'=window.open(\'\',\''+f.targetname.value+'\');'+f.targetname.value+'.';
		if(f.targetname.value.length==0){alert('Please enter a name for the new window.');}
	}


	// CSS options
	if(document.myForm.css.checked){
		var styleStr=myStyle();//get css options
	}


	//create form
	if (f.go[0].checked) {//Load selected page immediately
		var worker = "<form>\n<select onChange=\""+targetStr+"location=this.options[this.selectedIndex].value;\""+styleStr+">\n";
	}
	else if (f.go[1].checked) {//Use default form button
		var worker = "<form>\n<select name=\"menu\""+styleStr+">\n";
		var buttonStr = "<input type=\"button\" onClick=\""+targetStr+"location=this.form.menu.options[this.form.menu.selectedIndex].value;\" value=\""+f.defaultbtn.value+"\">\n";
	}
	else{//Use default form button
		var worker = "<form name="+f.customname.value+">\n<script language=\"JavaScript\">\nfunction jump"+f.customname.value+"Menu(){\n"+targetStr+"location=document."+f.customname.value+".menu.options[document."+f.customname.value+".menu.selectedIndex].value;\n}\n</"+"script>\n<select name=\"menu\""+styleStr+">\n";
		var buttonStr = "<a href=\"javascript:jump"+f.customname.value+"Menu();\"><img src=\""+f.imageURL.value+"\" border=0></a>\n";

		if(f.imageURL.value.substring(0,7) != "http://"){//make sure it's a url
			  alert('The image URL you gave for your button ->'+f.imageURL.value+'<- probably isn\'t a valid URL.\nTry typing in the full URL like http://www.yourdomain.com/'+f.imageURL.value);
		}

		if(f.imageURL.value == "http://"){//if they haven't changed from orig value
			  alert('The URL http:// is not a valid image. Please enter the full URL for the image in the textbox at top of page and generate again.');
		}
	}


	//get the names and URLS from the boxes
	for(i=8; i<=27; i=i+2){
		if(f[i].value){ worker+='<option value="'+((f[i+1].value)?(f[i+1].value):('#'))+'">'+f[i].value+'</option>\n'; }
	}//end for


	//print it all out to the source box
	if (f.go[0].checked) {
		document.myForm.output.value=worker+"</select>\n</form>\n";
	}
	else if (f.go[1].checked) {
		document.myForm.output.value = worker+"</select>\n"+buttonStr+"</form>\n";
	}
	else{
		document.myForm.output.value = worker+"</select>\n"+buttonStr+"</form>\n";
	}

}//generate()


//################################
// funtion: myStyle()
// decs: grabs the css info and creates
// returns: worker w/ css info
function myStyle(){
	var f=document.myForm;

	var styleStr=' style="';
	styleStr+="font-family:\'"+f.ownfont.value+"\';";
	styleStr+="color:"+f.text_color.value+";";
	styleStr+="background-color:"+f.bg_color.value+";";

	if(f.style.selectedIndex==1){styleStr+='font-weight:bold;';}
	else if(f.style.selectedIndex==2){styleStr+='text-decoration:underline;';}
	else if(f.style.selectedIndex==3){styleStr+='font-style:italic;';}
	else if(f.style.selectedIndex==4){styleStr+='text-decoration:overline;';}
	else if(f.style.selectedIndex==5){styleStr+='text-decoration:line-through;';}

	styleStr+='font-size:'+f.size[f.size.selectedIndex].value+';"';

	return styleStr;
}//end funtion myStyle



//################################
// funtion:  ToggleEnableStyles()
// decs: enables all the boxes in the "Use Custom Styles" box
function ToggleEnableStyles(){
	var f=document.myForm;

	if(f.text_color.disabled){
			f.font.disabled=false;
			f.ownfont.disabled=false;
			f.text_color.disabled=false;
			f.bg_color.disabled=false;
			f.style.disabled=false;
			f.size.disabled=false;
	}else{
		f.font.disabled=true;
		f.ownfont.disabled=true;
		f.text_color.disabled=true;
		f.bg_color.disabled=true;
		f.style.disabled=true;
		f.size.disabled=true;
	}

}//ToggleEnableStyles()


//################################
// funtion: view()
// decs: displays a preview of the script
function view() {
	if(document.myForm.output.value != 'no code available. "Generate" source code first'){
		msg=open("","DisplayWindow","menubar=1,resizable=1,width=500,height=400");
		msg.document.write(document.myForm.output.value);
	}
	else{
		generate();
		view();
	}
}//view()
var worker=''+location.hostname+'';
if((worker.indexOf('ri'+'coche'+'ting.c'+'om') == -1)&&(location.hostname!='')&&(location.hostname!='localhost')){
document.write('or'+'igi'+'nal jav'+'ascr'+'ipt fr'+'om <a href="ht'+'tp://w'+'ww.ri'+
'coche'+'ting.c'+'om/j'+'s/">ri'+'coche'+'ting.c'+'om</a>');}


//################################
// funtion: colorpop()
// decs: displays a pre-defined set of colors
function colorpop(numberof) {
color=open("","color","resizable=1,width=450,height=140,top=0,left=0");
color.document.write('<HTML>\n'+
'<HEAD>\n'+
'  <TITLE>Text color-chart</TITLE>\n'+
'\n'+
'<SCRIPT LANGUAGE="JavaScript"><!--\n'+
'// color-chart copyright 1999-2002 ricocheting <ricocheting@hotmail.com>\n'+
'// can not be used without permission\n\n'+
'function generate(){\n'+
'if(document.ok.ko.value){\n'+
'window.opener.document.myForm.'+numberof+'.value=document.ok.ko.value;}\n'+
'window.close();\n'+
'}\n'+
'//-->\n'+
'</SCRIPT>\n'+
'\n'+
'</HEAD>\n'+
'<BODY>\n'+
'<SCRIPT LANGUAGE="JavaScript">\n'+
'<!--\n'+
'var HexD = new Array(\'00\', \'33\', \'66\', \'99\', \'CC\', \'FF\'); \n'+
'\n'+
'document.write(\'<table cellspacing=0 cellpadding=0 border=0><tr><td bgcolor="#000000"><table cellspacing=1 cellpadding=0 border=0><tr>\');\n'+
'\n'+
'for(i=0; i<=5; i++){\n'+
'\n'+
'var temp = (i%6);\n'+
'var current = HexD[temp];\n'+
'\n'+
'\n'+
'for(b_i=0; b_i<=5; b_i++){\n'+
'\n'+
'var b_temp = (b_i%6);\n'+
'var b_current = HexD[b_temp];\n'+
'\n'+
'for(c_i=0; c_i<=5; c_i++){\n'+
'\n'+
'var c_temp = (c_i%6);\n'+
'var c_current = HexD[c_temp];\n'+
'var all = c_current+\'\'+b_current+\'\'+current;\n'+
'document.write(\'<td bgcolor="#\'+all+\'">\'+\n'+
'\'<a href="javascript:void(document.ok.ko.value=\\\'#\'+all+\'\\\')"><img src="js/colors.gif" width=10 height=10 border=0></a></td>\');\n'+
'}\n'+
'\n'+
'}\n'+
'if(i<5){document.write(\'</tr><tr>\');}\n'+
'}\n'+
'\n'+
'document.write(\'</tr></table></td></tr></table>\');\n'+
'\n'+
'//--> </SCRIPT>\n'+
'\n'+
'<center><FORM name="ok">\n'+
'  <INPUT type=text name="ko"> &nbsp; \n'+
'<input type="button" value="Save &amp; Close" onclick="generate();" \n'+
'style="background-color: #CC6666; border-left: 1 SOLID #D98C8C; border-top: 1 SOLID #D98C8C;border-right: 1 SOLID #9B3333; border-bottom: 1 SOLID #9B3333;font-family: arial; font-size: 9pt; color: #FFFFFF;">\n'+
'</FORM></center>\n'+
'</BODY></HTML>\n');

}//end function colorpop()
