/*is the URL valid?*/
function is_valid_url(url) {
  var RegExp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;    
  return RegExp.test(url) ? true : false;
}

function checkForm() {
  if($('slideshow_pptfile').value==""){
    toggleSuggestion("2",1,"Please provide your presentation file");
    window.scrollTo(0,0);
    $('suggestionAlert0').style.margin="190px 0pt 0pt -110px";
    $('suggestionAlert1').style.margin="381px 0pt 0pt -110px";
    return false;
  } else if($('slideshow_title').value=="") { 
    toggleSuggestion("3",1,"Include some more descriptive keywords in the title, this helps people in finding your content");
    $('slideshow_title').focus();
    window.scrollTo(0,0);
    $('suggestionAlert1').style.margin="394px 0pt 0pt -110px";
    return false;
  } else if($('slideshow_audio_url') && ($('slideshow_audio_url').value!='' 
            && !is_valid_url($('slideshow_audio_url').value))) { 
    alert("The audio URL you provided isn't valid. Please try again!");
    return false;
  } else {
    if($('slideshow_language').value=="") {
      $('slideshow_language').value = "**"; 
    }
    try{
      pageTracker._trackEvent('upload','single','queued');
    } catch(e) {}
    Element.hide($('upload_submit_button'));
    Element.show($('progress_bar'));
    return true;
  }
}

function single_upload_submitform() {
  if (slideshare_object.dev) { log('DEBUG: slideshow upload'); }
  frm = jQuery('#s3_upload')[0];
  if ( checkForm() ) {
    frm.key.value = generate_s3_key(frm.file.value, "s");
    $('ppt_location').value = s3_upload_target + "/"+frm.key.value;
    s3Post.uploadAttachment(document.getElementById('s3_upload'));
  } else {
    return false;
  }
}

function toggleSuggestion(id,state,msg){
  $('suggestionAlert'+id).innerHTML=msg;
  $('suggestionAlert'+id).style.display = state==1 ? '' : 'none';
}

function checkTitle(element){
  if (element.value.length>0) {
    toggleSuggestion("3",0,"");
  } else {
    if ($("suggestionAlert2").innerHTML.length>0) {
      $("suggestionAlert0").style.margin="190px 0pt 0pt -110px";
    } else{
      $("suggestionAlert0").style.margin="58px 0pt 0pt -80px";
    }
    toggleSuggestion("3",1,"Include some descriptive keywords in the title, this helps people in finding your content");
  }
}

function toggle_contest_list(count,pid) {
  $('contest_list'+count).disabled=!$('contest_list'+count).disabled;
  $('private_type_'+pid).selectedIndex=0;
  $('private_type_'+pid).disabled=!$('private_type_'+pid).disabled;

  $('join_chk'+count).checked ? entriesCount++ : entriesCount--;
  
  if ($('category_row'+count).style.display=='') {
    $('category_row'+count).style.display='none';
    $('contest_cat_list'+count).style.display='none';
  } else {
    if (entriesCount>maxlimit) {
      $('contest_list'+count).disabled=!$('contest_list'+count).disabled;
      $('private_type_'+pid).disabled=!$('private_type_'+pid).disabled;
      $('join_chk'+count).checked =false;
      alert("You have reached your maximum limit of "+maxlimit
            +" entries in the contest");
    } else {
      $('category_row'+count).style.display="";
      $('contest_cat_list'+count).style.display="";
    }
  }
}

function toggle_checkbox(index) {
  $('contest_list'+index).disabled=!$('contest_list'+index).disabled;
}

function singleupload_check_extension(ele, extensions) {
  if (check_extension(ele.value, extensions)) {
    return true;
  } else {
    ele.value = "";
    return false;
  }
}