

 $(document).ready(function(){
loadPlayer(NaN);
  });

 function sendStoredTone()
    {
         showDestination();
   if(document.forms[0].phoneNumber.value == "")
            { 
              
	      alert("You must enter a phone number");
	      document.forms[0].phoneNumber.focus();
	      return;
	     }

               if(document.forms[0].phoneNumber.value.match(/\d{10}/g) == null) 
		{
	          alert("Phone number is invalid");
		  document.forms[0].phoneNumber.focus();
		  return;
		}
           if (document.forms[0].cellService.selectedIndex == 0)
	    {
	          alert("You must select a cell service provider");
		  document.forms[0].cellService.focus();
                  return;
		}

      document.forms[0].act.value="sendTone";
      document.forms[0].submit();
   
}
 function sendGeneratedTone(whichWay)
    { 
 if(document.forms[0].tone.value=="")
       {
        alert("Please select a tone by playing the tone");
	return;
        } 
   if(whichWay=="email")
     {
       var regExp =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
       var myMatch =document.forms[0].emailAddy.value.match(regExp);
      if(!myMatch){
       alert("You entered a bad email address bitch try again");         
       return;
     }
     else{ //alert(document.forms[0].tone.value);
	$.post("sendTone2.php", { emailAddy: document.forms[0].emailAddy.value, Mp3Tone: document.forms[0].tone.value, deliv: 'email' },
  function(data){
   // alert();   
     alert(data);
     // stopProgressBar();
  });
         
      }
     }
   else
    { 
 
   if(document.forms[0].phoneNumber.value == "")
            { 
  
	      alert("You must enter a phone number");
	      document.forms[0].phoneNumber.focus();
	      return;
	     }

               if(document.forms[0].phoneNumber.value.match(/\d{10}/g) == null) 
		{
	          alert("Phone number is invalid");
		  document.forms[0].phoneNumber.focus();
		  return;
		}
           if (document.forms[0].cellService.selectedIndex == 0)
	    {
	          alert("You must select a cell service provider");
		  document.forms[0].cellService.focus();
                  return;
		}
   $.post("sendTone2.php", { cellService: document.forms[0].cellService.value, Mp3Tone: document.forms[0].tone.value, phoneNumber: document.forms[0].phoneNumber.value, deliv: 'cell' },
  function(data){
   // alert();   
     alert(data);
     // stopProgressBar();
  });
   }
}
function makeRingTone()
    {
  if(document.forms[0].playerStatus.value!="songLoaded")
       {
        alert("Please upload a song first (mp3 Only) click the green plus");
	return;
    }
 startProgressBar("Generating Tone");
$.post("makeTone.php", { songLength: document.forms[0].songLength.value, songStartSecs: document.forms[0].songStartSecs.value,format: document.forms[0].format.value ,songStartMin: document.forms[0].songStartMin.value, songName: document.forms[0].songName.value,uploadedTone: document.forms[0].mp3song.value ,qual: document.forms[0].qual.value},
  function(data){
     importantShit = data.substring(data.indexOf("/tmp"),data.length)
     var results= importantShit.split(",");
    // EP_stop("ep_player"); 
    // EP_loadPlayList("ep_player", results[0]);
      loadPlayer(results[0]);
     document.forms[0].mp3Tone.value = results[1];
   //     alert(document.forms[0].mp3Tone.value);
//      try
//   {
//    EP_next("ep_player");
//   }
// catch(err)
//   {
//   txt="There was an error on this page.\n\n";
//   txt+="Error description: " + err.description + "\n\n";
//   txt+="Click OK to continue.\n\n";
//   //alert(txt);
//   }
   
      stopProgressBar();
 //     showDestination();
  });
     }
function stopProgressBar()
  {
$("#progressbar").hide("explode", {}, 1000);
$("#progressbar").progressbar("stop");

 }
function showDestination()
{
 $("#cellInfo").show("explode", {}, 1000);
}
function loadMp3(filename1,artist,title1){
  // alert(filename1+artist+title1);
       document.forms[0].tone.value=filename1;
    EP_loadMP3('ep_player',"<location>"+filename1+"</location><creator>"+artist+"</creator><title>"+title1+"</title>");
    
   
}
function loadPlayer(playlist)
  {
  playerHeight="320";
  playerWidth="320";

   if(navigator.userAgent.indexOf("MSIE")>0)
    {
      playerHeight="270";
      playerWidth="220";
    }
    else
	{
      playerHeight="290";
      playerWidth="245";
          }
var so = new SWFObject("player4/ep_player.swf", "ep_player", playerWidth, playerHeight, "9", "#FFFFFF");
		so.addVariable("skin", "player4/skins/alien_green/skin.xml");
		so.addVariable("playlist", playlist);
		so.addVariable("autoplay", "true");
		so.addVariable("shuffle", "false");
		so.addVariable("repeat", "false");
		so.addVariable("volume", "50");
                so.addVariable("notifyonevent", "true");
		so.addVariable("buffertime", "1");
		so.addParam("allowscriptaccess", "always");
		so.write("flashcontent");
  }
function showPlayer()
  {
  $("#flashcontent").show("fold", {}, 1000);
  }
function startProgressBar(mess)
 {
$("#progressbar").show("fold", {}, 1000);
	document.forms[0].act.value="makeTone";
	$("#progressbar").progressbar({ 
           interval: 127000, 
            increment: 1,
           text: mess,
            range: true,
            stop: function() { 
          
       // alert("Finished"); 
    } 
}).progressbar("start");
     }
	
function showDialog()
{
$("#dialog").dialog({ 
    modal: true,
     
    overlay: { 
        opacity: 0.5, 
        background: "black" 
    } 
});
  $("#dialog").show();
}
    function ajaxFileUpload()
    {
        $('#progress1').text('');
        //starting setting some animation when the ajax starts and completes
        $("#loading")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });
       
        /*
            prepareing ajax file upload
            url: the url of script file handling the uploaded files
                        fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
            dataType: it support json, xml
            secureuri:use secure protocol
            success: call back function when the ajax complete
            error: callback function when the ajax failed
           
                */
        $.ajaxFileUpload
        (
            {
                url:'upload.php',
                secureuri:false,
                fileElementId:'audio',
                dataType: 'script',
                success: function (data, status)
                {         //alert(data);
                          if(data.indexOf("tmp") >=  0)
		  {
		     // $('#progress1').text('Your file was uploaded successfully');
                    var results = data.split(","); 
                    stopProgressBar();
		    showPlayer(); 
                   // EP_loadPlayList("ep_player",results[0]);
                   loadPlayer(results[0]);
 	          
		    document.forms[0].playerStatus.value="songLoaded";
                    document.forms[0].songName.value="Ringtone";
		    document.forms[0].mp3song.value=results[1];
                  }
                else
		     {
		       $('#progress1').text('Your file was NOT uploaded succesfully');
			 stopProgressBar();
		      }
                },
                error: function (data, status, e)
                {
                    alert("Error\n"+data.toString()+"\n"+ e);
                }
            }
        )
        return false;
}
function send2phone()
    {
      if($('#cellInfo').is(':hidden')){
        $('#cellInfo').show(500);
      }
      if($('#emailInfo').is(':visible')){
	$('#emailInfo').hide(100);
      }
    }
function send2Email()
    {
      if($('#cellInfo').is(':visible')){
        $('#cellInfo').hide(100);
      }
      if($('#emailInfo').is(':hidden')){
	$('#emailInfo').show(500);
      }
    }
