function openterms() {
	popupWin = window.open('../competition/terms_and_conditions.shtml', 'terms', 'scrollbars=yes,width=510,height=500,resizable=yes,status=no')
}

function openprize() {
	popupWin = window.open('../competition/full_prize_details.shtml', 'prize', 'scrollbars=yes,width=510,height=500,resizable=yes,status=no')
}

function oncompsubmit() {
  //set the redirect;
  var lh = location.href;
  var redirect = lh.substring( 0, lh.lastIndexOf( '/' )+1 )+'result.shtml';
  $( '#field_redirect' ).attr( 'value', redirect );
  var req_fields = [ 'first_name', 'last_name', 'email', 'image', 'title', 'description', 'location' ];
  var message = '';
  var valid = true;
  //check the terms and conditions
  if ( $( '#field_terms' ).attr( 'checked' ) != true ) {
    valid = false;
    message = 'Please accept the terms and conditions';
  }
  //check the fields
  for( var i =0; i<req_fields.length; i++ ) {
    var field = req_fields[ i ];
    var val = $( '#field_'+field ).attr( 'value' );
    if ( val==undefined || val.length<3 ) {
      valid = false;
      message = 'Please fill in all the required fields, marked with a *';
      break;
    }
  }
  var fields = [ 'title', 'description' ];
  var names = [ 'Title', 'Description' ];
  var lengths = [ 14, 80 ];
  for( var i =0; i<fields.length; i++ ) {
    
    var field = fields[ i ];
    //console.log( 'checking: ' + field );
    var val = $( '#field_'+field ).attr( 'value' );
    //console.log( 'checking: ' + val );
    if ( val != undefined && val.length>lengths[i] ) {
      valid = false;
      message = names[i]+' can\'t be longer than '+lengths[i]+' characters.'  ;
      break;
    }
  }  if ( !valid ) {
    alert( message );
    return false;
  } else {
    return true;
  }
}