/**
 * $Id: validate.js 357 2010-09-13 06:52:34Z zpatz $
 * $URL: https://www.toofast.ca/svn/toofast/trunk/validate.js $
 *
 */
function validateCreateAccount ( createaccount )
{

  // ** START **
  if (document.createaccount.username.value == "") {
  alert( "You must enter a username" );
  document.createaccount.username.focus();
  return false ;
  }

  var username = document.createaccount.username.value;
  if (username.match(/^\w{5,20}$/) == "null") {
  alert( "Your username is not allowed. Username Policy: 5-20 Characters (letters, numbers, underscore)" );
  document.createaccount.username.focus();
  return false ;
  }

  if (document.createaccount.password.value == "") {
  alert( "You must enter a password" );
  document.createaccount.password.focus();
  return false ;
  }

  var password = document.createaccount.password.value;
  if (password.match(/^\w{5,20}$/) != null) {
     if (password.match(/^.*[!@#$].*$/) == null)
     {
     alert( "Your password is not allowed. Password Policy: 5-20 Characters (letters or numbers) and one of the following symbols !@#$" );
      document.createaccount.password.focus();
      return false ;
     }

  }

  if (document.createaccount.firstname.value == "") {
  alert( "You must enter your first name" );
  document.createaccount.firstname.focus();
  return false ;
  }

  if (document.createaccount.lastname.value == "") {
  alert( "You must enter your last name" );
  document.createaccount.fastname.focus();
  return false ;
  }

  if (document.createaccount.email.value == "") {
  alert( "You must enter your email" );
  document.createaccount.email.focus();
  return false ;
  }

  if (document.createaccount.organization.value == "") {
  alert( "You must enter your organization" );
  document.createaccount.organization.focus();
  return false ;
  }

  if (document.createaccount.orgcountry.value == "") {
  alert( "You must enter your country" );
  document.createaccount.orgcountry.focus();
  return false ;
  }



  // ** END **
  return true ;

}

function validateLogin ( login )
{

  if (document.login.username.value == "") {
  alert( "You must enter a username" );
  document.login.username.focus();
  return false ;
  }

  var username = document.login.username.value;
  if (username.match(/^\w{5,20}$/) == null) {
  alert( "Your username is not allowed. Username Policy: 5-20 Characters (letters, numbers, underscore)" );
  document.login.username.focus();
  return false ;
  }

  if (document.login.password.value == "") {
  alert( "You must enter a password" );
  document.login.password.focus();
  return false ;
  }

  var password = document.login.password.value;
  if (password.match(/^\w{5,20}$/) != null) {
     if (password.match(/^.*[!@#$].*$/) == null)
     {
     alert( "Your password is not allowed. Password Policy: 5-20 Characters (letters or numbers) and one of the following symbols !@#$" );
      document.login.password.focus();
      return false ;
     }

  }

}


function validateCreateSurvey()
{
    // Set the default foldername if blank
    if ( $( "#FolderName" ).val() == "" )
    {
        $( "#FolderName" ).val( "Default" );
    }

    // ** START **
  if (document.addsurvey.SurveyName.value == "") {
        alert( "You must enter a survey name" );
        document.addsurvey.SurveyName.focus();
        return false ;
    }
    // ** END **

  if ((document.addsurvey.SurveyPassword.value == "") && (document.addsurvey.SurveyPasswordRequired.checked)) {
        alert( "You must enter a survey password" );
        document.addsurvey.SurveyName.focus();
        return false ;
    }
    // ** END **

    // Post the create
    HttpRequestSurveyCreate($( "#LoginID" ).val(),
                            $( "#SurveyName" ).val(),
                            $( "#SurveyPassword" ).val(),
			    $( "#SurveyTags" ).val(),
			    $( "#surveytagsshare" ).attr( "checked" ),
                            $( "#SurveyPasswordRequired" ).attr( "checked" ),
                            $( "#FolderName" ).val() );
}


function delanswerconfirm(x,y,filename)
{
  var answer = confirm('Do you really want to clear the results from this survey?');
  if (answer)
  {
    passdata(x,y,filename);
  }

}

function delsurveyconfirm(x,y,filename)
{
  var answer = confirm('Do you really want to delete this survey?');
  if (answer)
  {
    passdata(x,y,filename);
  }

}

function delquestions(w,x,y,Questionnumber,z)
{
  var answer = confirm('Do you really want to delete the checked questions?');
  if (answer)
  {
    DeleteQuestions(w,x,y,Questionnumber,z);
  }

}

function delemailsconfirm(x,y,filename)
{
  var answer = confirm('By clicking OK you are deleting all the e-mails and random passwords generated for this survey.  You will revert to using one password for your survey.');
  if (answer)
  {
    passdata(x,y,filename)

  }

}

function remindconfirm(x,y,filename)
{
  var answer = confirm('By clicking OK you are sending an e-mail reminder to ALL the people in your e-mail list to do your survey');
  if (answer)
  {
    passdata(x,y,filename)

  }

}

function admindeluserconfirm(x,y,filename)
{
  var answer = confirm('By clicking OK you are permanently deleting this user and all of their survey data');
  if (answer)
  {
    passdata(x,y,filename)

  }

}

function admindellogconfirm(x,y,filename)
{
  var answer = confirm('By clicking OK you are permanently deleting these log entries');
  if (answer)
  {
    passdata(x,y,filename)

  }

}

