  function checkPaypal(){
    if(document.getElementById('payEmail').value.length<5){
      alert('Please enter a valid email');
      return false;
    }

    if(document.getElementById('nCust').checked==true){
        if(document.getElementById('npass').value.length<3){
            alert('Please enter a password');
            return false;
        }
    }

    if(document.getElementById('nCust').checked==true){
        if(document.getElementById('npass').value!=document.getElementById('npass2').value){
            alert('Passwords do not match');
            return false;
        }

        if(document.getElementById('termscheck').checked!=true){
            alert('You have not agreed to our terms and conditions');
            return false;
        }
    }

    return true;
  }
  
  function searchPage(page, source){
    $("#searchResults").html('<center><img src="/images/loading_aqua.gif" style="padding-bottom:400px"/></center>');
    $("#searchResults").load("/search?q="+escape(document.getElementById('q').value)+"&source="+source+"&page="+page);
  }

  function changePhones(){
    $("#selectphone").html('<select><option value="">Loading...</option></select>');
    $("#selectphone").load("/changephone?carrier="+document.getElementById('carrier2').value+"&brand="+document.getElementById('brand').value);
  }

  function changeBrands(){
    $("#selectbrand").html('<select><option value="">Loading...</option></select>');
    $("#selectbrand").load("/changebrand?carrier="+document.getElementById('carrier2').value);
  }

  function imgchange(){
    if(document.getElementById('dloption')){
      if(document.getElementById('carrier2').value!='' && document.getElementById('brand').value!='')
          document.getElementById('dloption').style.display='block';
      getSuggestion(document.getElementById('carrier2').value, document.getElementById('brand').value, document.getElementById('phone').value);
    }
    $("#phoneimg").load("/imgchange?phone="+document.getElementById('phone').value);
  }

  function applySuggestion(){
    if(document.getElementById('suggestedMethod').value==1){
        setRadioDownloadValue(document.getElementById('helpformat').value);
    }
    if(document.getElementById('suggestedMethod').value==2){
        setRadioEmailValue(document.getElementById('helpformat').value);
    }
    if(document.getElementById('suggestedMethod').value==3){
        setRadioPhoneValue(document.getElementById('helpformat').value);
    }
  }

  function getRadioValue(radioN)
  {
    for(i=0;i<document.updateHelp[radioN].length;i++)
    {
      if (document.updateHelp[radioN][i].checked == true)
        return document.updateHelp[radioN][i].value;
    }
  }

  function setRadioDownloadValue(radiovalue){
    for(i=0;i<document.downloadForm['format'].length;i++)
    {
        if (document.downloadForm['format'][i].value == radiovalue){
            document.downloadForm['format'][i].checked = true;
        }

    }
  }

  function setRadioEmailValue(radiovalue){
    for(i=0;i<document.emailForm['format'].length;i++)
    {
        if (document.emailForm['format'][i].value == radiovalue){
            document.emailForm['format'][i].checked = true;
        }

    }
  }

  function setRadioPhoneValue(radiovalue){
    document.getElementById('selectPhoneForm').value = radiovalue;
    for (i=0; i <= document.phoneForm.carrier.options.length - 1;i++)
    {
        var tempString = new String(document.phoneForm.carrier.options[i].value);
        var brokenstring = tempString.split('^');
        if((brokenstring[4] == document.getElementById('suggestedCarrier').value) || (brokenstring[3] == document.getElementById('suggestedCarrier').value) || (brokenstring[2] == document.getElementById('suggestedCarrier').value))
            document.phoneForm.carrier.options[i].selected = "selected";
    }

    for(i=0;i<document.phoneForm['web_sup'].length;i++)
    {
        if (document.phoneForm['web_sup'][i].value == document.getElementById('suggestedSupport').value){
            document.phoneForm['web_sup'][i].checked = true;
        }
    }
  }

  function changeSuggestion(){
    $("#dloption").load("/dloption?has=2");
  }

  function getSuggestion(car2, bran2, phon2){
    $("#dloption").html("Loading...");
    $("#dloption").load("/dloption?carrier="+car2+"&brand="+bran2+"&phone="+phon2);
  }

  function checkHelpForm(){
    if(document.getElementById('carrier2').value==''){
        alert('Please select a carrier');
        return false;
    }
    if(document.getElementById('brand').value==''){
        alert('Please select a brand');
        return false;
    }
    if(document.getElementById('phone').value==''){
        alert('Please select a phone');
        return false;
    }

    var options = {
        target:        '#dloption'
    };

    $('#updateHelp').ajaxSubmit(options);

    return false;
  }

  function addtoplaylist(id){
    $("#playlist").load("/account/addtoplaylist?id="+id);
  }

  function removeplaylist(id){
    $("#playlist").load("/account/removeplaylist?id="+id);
  }

  function rankUp(id){
    $("#playlist").load("/account/rankup?id="+id);
  }

  function rankDown(id){
    $("#playlist").load("/account/rankdown?id="+id);
  }

  function createFile(start, end, v) {      
      document.getElementById('prerecordid').value='';
      var duration = end - start;
      if(duration>40)
        duration = 40;
      $("#downloadSection").html('<div id="downloadRingtone">  <img src="/images/loading_aqua.gif" /></div>');
      $("#downloadSection").load("/createRingtone?start="+start+"&duration="+duration+"&v="+v);
  }

  function setAmp(num){
    setValueByName('amp', num);
  }

  function homecreateFile(start, end, v) {    
      var duration = end - start;
      window.location = "/generateRingtone?start="+start+"&duration="+duration+"&video="+v;
  }

  function setRingtoneOptions(fin, fout, lp){
    if(fin=="invert")
        setValueByName('fadein', 1);
    else
        setValueByName('fadein', 0);
    if(fout=="invert")
        setValueByName('fadeout', 1);
    else
        setValueByName('fadeout', 0);
    if(lp=="invert")
        setValueByName('loop', 1);
    else
        setValueByName('loop', 0);
  }

  function setValueByName(field, val){
    var elements = document.getElementsByName(field);
    for(i=0; i<elements.length; i++){
        elements[i].value = val;
    }
  }

  function updateCarrierList(web){
    $("#smsCarrierList").html('<select id="smsCarrierList" style="width:150px"><option value="">Loading...</option></select>');
    $("#smsCarrierList").load("/updateCarrierList?web="+web);
  }

  function saveRingtoneName(video, n, start, duration){
    $("#saveRingtoneStatus").load("/saveRingtoneName?video="+video+"&start="+start+"&duration="+duration+"&name="+n+"&title="+escape(document.getElementById('ringtitle').value));
  }

  function removeSpaces(string) {
    return string.split(' ').join('');
  }

  $(function(){
	$("#chooseT2T_Image img").click(function(){
		$("#chooseT2T_Image img").removeClass("selected");
		$(this).addClass("selected");
	});
  });

  // edit account modal box
  $(function(){
  	$("#accountInfo .edit ").click(function(){
  		$.modal.show("#editMyAccount");
  	});
  	$("#editMyAccount .close ").click(function(){
  		$.modal.close("#editMyAccount");
  	});
    $("#editMyAccount .cancel ").click(function(){
  		$.modal.close("#editMyAccount");
  	});
  });

  // edit account modal box
  $(function(){
  	$("#myPhone .edit ").click(function(){
  		$.modal.show("#editMyPhone");
  	});
  	$("#editMyPhone .close ").click(function(){
  		$.modal.close("#editMyPhone");
  		//$("#myFeed").css("display","block");
  	});
  });

  $(function(){
  	$("#mySources .edit ").click(function(){
  		$.modal.show("#editMySource");
  	});
  	$("#editMySource .close ").click(function(){
  		$.modal.close("#editMySource");
  		//$("#myFeed").css("display","block");
  	});
  });

  // tabs
  $(function(){
  	$("#tabs .tab-body").hide();
  	$("#tabs .tab-body").filter(":first").show();

  	$("#tabs .tab").click(function(){
  		$("#tabs .tab").removeClass("selected");
  		$(this).addClass("selected");
  		var thisID = $(this).attr("id");
  		var newID = "#" + thisID + "-body";

  		$("#tabs .tab-body").hide();
  		$(newID).show();
  	});
  });

  //choose thumb
  $(function(){
  	$("#chooseThumbnail .thumbnail").click(function(){
  		$(this).siblings().removeClass("selected");
  		$(this).addClass("selected");
  	});
  });
