	// INITIALIZE THE VARIABLES THAT WILL BE USED BY VARIOUS FUNCTIONS  
  
  
	var WinPic="";		// Next 4 variables are for the  
	var WinScroll="";		// previewPic function.  They create a  
	var WinWide="";		// popup window for previewing a postcard  
	var WinHigh="";		// image based on data passed by the link.  
  
	var imageFile = '';	// These 2 variables are used by the  
	var imageDetails = '';	// setPicture function to grab the   
					// postcard image and pass related  
					// data on to the cgi script.  
  
	var Chips = new StringArray(4);	// This is used to tell the   
					// set music function how many unique pieces  
					// of song data  
					// (separated by pipe | delimiters)  
					// are being passed by the selected index   
					// of the musicPic field, so that the data   
					// can be parsed, and passed onto the other   
					// music fields as individual values.  
  
	var songFile = '';	// These next 4 variables are used by the  
	var songTitle = '';	// setMusic function to grab the song file  
	  
	var colorPic = "";	// This variable is used by the getColor  
					// function, and will hold the various  
					// text and background colors chosen,  
					// and written to the appropriate fields  
					// as values.  
  
	var texturePic = "";	// This variable is used by the getTexture  
					// function, and will hold the texture  
					// file name that is selected by the visitor  
					// and will be written to the background field  
  
  
// THIS FUNCTION IS USED TO OPEN A POPUP WINDOW TO ALLOW THE VISITOR   
// TO SEARCH THE MUSIC DATABASE FOR AN UNLISTED TUNE.  
  
function openSearch(WinPic,WinScroll,WinWide,WinHigh) {  
  
	var str1 = WinPic;  
  
	var str2 =	'"toolbar=0,scrollbars=' + WinScroll +',width=' +WinWide+' ,height='+WinHigh+'"';  
  
   	msg=open(str1,"SearchWindow",str2);  
}  
  
// THIS FUNCTION IS USED TO OPEN A POPUP WINDOW TO PREVIEW A POSTCARD  
// IMAGE FULLSIZE  
  
function previewPic(WinPic,WinScroll,WinWide,WinHigh) {  
  
	var str1 = 'cards/' + WinPic;  
  
	var str2 =	'"toolbar=0,scrollbars=' + WinScroll +',width=' +WinWide+' ,height='+WinHigh+'"';  
  
   	msg=open(str1,"PreviewWindow",str2);  
}  
  
  
// THIS FUNCTION GRABS THE IMAGE THAT HAS BEEN SELECTED AND STORES IT'S  
// RELATED FILENAME AND DETAILS INTO HIDDEN FIELDS TO PASS ON TO THE   
// POSTCARD.  
  
function setPicture (imageFile,imageDetails) {  
   document.PostcardForm.image_url.value = imageFile;  
   document.PostcardForm.image_details.value = imageDetails;  
}  
  
// THIS FUNCTION IS USED BY THE setMusic FUNCTION TO DETERMINE HOW  
// MANY UNIQUE FIELDS OF DATA ARE BEING PASSED BY THE SONG SELECTED   
// IN THE musicPic MENU.  THE setMusic FUNCTION THEN PARSES THIS DATA,   
// AND PASSES IT ONTO THE OTHER MUSIC FIELDS AS INDIVIDUAL VALUES.  
  
function StringArray (n) {  
  this.length = n;  
  for (var i = 0; i < n; i++){ this[i] = '' }  
  return this  
}  
  
//  THIS FUNCTION STORES THE MUSIC SELECTION AND RELATED DATA.  
  
//function setMusic (songFile,songTitle,songLyrics,songDownload) {  
  
function setMusic(select) {  
  
   var tmp =   
document.PostcardForm.musicPic.options[document.PostcardForm.musicPic.options.selectedIndex].value;  
  
   if (tmp != null) {  
  
  
	// NOTE:  THE db_manager.cgi SEARCH FUNCTION REFERENCED BELOW  
	//        IS NOT INCLUDED IN THIS SCRIPT KIT!  
	  
	if (tmp=="*") {  
openSearch('http://www.tanboru.org/postcard/cgi-bin/db_manager.cgi?setup_file=music.setup.cgi&view_database_button=View','yes','600','300');   
	}  
  
	else {  
      var Done = 0;  
      var i = 0;  
      while (Done==0) {  
         if (tmp.indexOf('|')!=-1) {  
            Chips[i]=tmp.substring(0,tmp.indexOf('|'));  
            tmp=tmp.substring(tmp.indexOf('|')+1,tmp.length); i++;  
         } else {  
            Chips[i]=tmp;  Done=1;  
         }  
      }  
   }  
  
   songFile = Chips[0];  
   songTitle = Chips[1];  
    
  
// store the music selection and related data into the postcard cookie  
  
   txt=songTitle;  
   ctr=0;  
  
   while (txt.indexOf('"')>-1){  
	   pos=txt.indexOf('"');  
	   txt=txt.substring(0,pos)+'&quot;'+txt.substring(pos+1,txt.length);  
   }  
  
   songTitle=txt;  
  
	document.PostcardForm.sound_url.value = songFile;  
	document.PostcardForm.song_title.value = songTitle;  
		}  
  
}  
  
//  THIS NEXT FUNCTION ALLOWS THE VISITOR TO LISTEN TO THE SONG THAT  
//  IS CURRENTLY SELECTED  
  
  
	function playMe() {  
  
		var thisSong = document.PostcardForm.sound_url.value;  
  
		songLocation = "music/" + thisSong;  
  
		if (thisSong != "") {  
			msg=open(songLocation,"SongWindow","toolbar=0,scrollbars=no,width=150,height=75");  
		}  
		else {  
			alert('\nSelecione a música primeiro.\n\nClique para ouvir.\n\n');  
		};  
  
	}  
  
// THIS FUNCTION GRABS THE HEX VALUE OF THE COLOR SELECTED FROM THE  
// PALETTE AND WRITES IT AS THE VALUE OF THE APPROPRIATE FIELD  
// (bgcolor, text, link, vlink, alink)  
  
	function getColor (colorPic) {  
  
	   if (document.PostcardForm.pickOne[0].checked) {  
			document.PostcardForm.bgColor.value = colorPic;  
		}  
	   if (document.PostcardForm.pickOne[1].checked) {  
			document.PostcardForm.textColor.value = colorPic;  
		}  
	   if (document.PostcardForm.pickOne[2].checked) {  
			document.PostcardForm.linkColor.value = colorPic;  
		}  
	   if (document.PostcardForm.pickOne[3].checked) {  
			document.PostcardForm.vlinkColor.value = colorPic;  
		}  
	   if (document.PostcardForm.pickOne[4].checked) {  
			document.PostcardForm.alinkColor.value = colorPic;  
		}  
  
	}  
  
// THIS FUNCTION GRABS THE NAME OF THE BACKGROUND TEXTURE SELECTED  
// BY THE VISITOR AND WRITES IT AS THE VALUE OF THE background FIELD  
  
	function getTexture(texturePic) {  
	   document.PostcardForm.background.value = texturePic;  
	}  
  
// THIS FUNCTION GRABS THE NAME OF THE BACKGROUND TEXTURE SELECTED  
// BY THE VISITOR AND WRITES IT AS THE VALUE OF THE background FIELD  
  
	function resetTexture() {  
	   document.PostcardForm.background.value = "";  
	}  
  
function validatePostcard(){  
  
// FIRST, CHECK TO MAKE SURE THAT THE NECESSARY ROUTING DATA HAS BEEN  
// SUPPLIED.  
  
	if (document.PostcardForm.image_url.value == "")   
        {  
        alert("Escolha a imagem que\nvai compor o seu cartão.");  
        return false;  
	}  
  
	if (document.PostcardForm.sender.value == "")   
        {  
        alert("Preencha seu nome\npara enviar o seu cartão.");  
	  document.PostcardForm.sender.select();  
	  document.PostcardForm.sender.focus();  
        return false;  
	}  
  
	if (document.PostcardForm.sender_email.value.indexOf("@") == -1 ||  
            document.PostcardForm.sender_email.value == "")   
        {  
        alert("Escreva o seu E-mail\npara enviar o seu cartão.");  
	  document.PostcardForm.sender_email.select();  
	  document.PostcardForm.sender_email.focus();  
        return false;  
	}  
         
	if (document.PostcardForm.recipient.value == "")   
        {  
        alert("Escreva o nome da pessoa\nque irá receber o cartão.");  
	  document.PostcardForm.recipient.select();  
	  document.PostcardForm.recipient.focus();  
        return false;  
	}  
  
	if (document.PostcardForm.recipient_email.value.indexOf("@") == -1 ||  
            document.PostcardForm.recipient_email.value == "")   
        {  
        alert("Escreva o E-mail da pessoa\nque irá receber o seu cartão");  
	  document.PostcardForm.email.select();  
	  document.PostcardForm.email.focus();  
        return false;  
	}  
  
// NOW CLEAN UP THE MESSAGE FIELD AND REPLACE ANY PROBLEMATIC  
// CHARACTERS WITH SAFE ONES.  
  
  txt=document.PostcardForm.text_raw.value;  
  ctr=0;  
  
  while (txt.indexOf("|")>-1){  
   pos=txt.indexOf("|");  
   txt=txt.substring(0,pos)+"-"+txt.substring(pos+1,txt.length);  
   }  
  
  while (txt.indexOf('"')>-1){  
	   pos=txt.indexOf('"');  
	   txt=txt.substring(0,pos)+''+txt.substring(pos+1,txt.length);  
   }  
  
  while (txt.indexOf("\n")>-1){  
	   pos=txt.indexOf("\n");  
	   txt=txt.substring(0,pos)+"<BR>"+txt.substring(pos+1,txt.length);  
   }  
  
  txt = txt + '<P>';  
  
// NOW STORE THE CLEANED MESSAGE TEXT FROM THE RAW TEXT FIELD INTO THE  
// HIDDEN TEXT FIELD TO PASS ONTO THE SCRIPT.  
  
  document.PostcardForm.text.value=txt;  
  
// STORE THE SENDER NAME INTO THE HANDLE FIELD  
  
  document.PostcardForm.handle.value=document.PostcardForm.sender.value;  
  
  
// NOW TELL THE FORM THAT IT'S OKAY TO PASS THE DATA ONTO THE CGI SCRIPT  
// FOR PROCESSING.  
  
  return true;  
  
}  