/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function validateClassicSuper()
{
    var name = jQuery("#name").val();
    var song= jQuery("#songs").val();
    var status = true;
    var notice = "";
    
     if(isEmpty(name))
   {
       status = false;
       notice = notice + " Name cannot be empty.\n"
    

   }
   
    if(isEmpty(song))
   {
       status = false;
       notice = notice + " Song cannot be empty.\n"
    

   }
   
    if(status==false)
   {

         alert(notice);
         return false;
   }
   else
   {
       //document.getElementById('frmFeedback').submit();
       return true
    }

}



function validateForm()
{
   var name =  $("#name").val();
   var email = $("#email").val();
      var song = $("#song").val();
   var artist = $("#artist").val();
    var showID = $("#showID").val();
    var securitycode = $("#request-captcha-input").val();
   var notice = "";
   var status = true;
  

   if(isEmpty(name))
   {
       status = false;
       notice = notice + " Name cannot be empty.\n"
    

   }



    if(!validateEmail(email))
   {
       status = false;


       notice = notice + "Email needs to be in proper format and cannot be left blank.\n"
   }
    if(isEmpty(song))
   {
       status = false;
       notice = notice + " Song cannot be empty.\n"


   }

   if(isEmpty(artist))
   {
       status = false;
        notice = notice + " Artist cannot be empty.\n"
     
   }

    if(isEmpty(showID))
   {
       status = false;
        notice = notice + " Please select a show.\n"

   }

   if(isEmpty(securitycode))
   {
       status = false;
        notice = notice + " Security code cannot be empty.\n"

   }

   if(status==false)
   {

         alert(notice);
         return false;
   }
   else
   {
       //document.getElementById('frmFeedback').submit();
       return true
    }


}






function validateEmail(email)
{
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    var isMailAdd = emailPattern.test(email);
	if(!isMailAdd)
	{
		return false;

	}
        else
        {
            return true;
        }
}

function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function isEmpty(elementValue)
{

	elementValue = trim(elementValue);


    if((elementValue == '') || (elementValue == null) || (elementValue == ' '))
	{

	   return true;

	}
	else
	{

	   return false;

	}


}



function validateContactForm()
{
    var formChild = jQuery("#contact-form").children();
    var regStatus = true;
     var regMessage = "";

     for(var i=0;i<formChild.length;i++)
     {
            if(formChild[i].type=="text" && formChild[i].id=="security-code" && isEmpty(formChild[i].value))
            {
                regMessage += "Please fill in security code.\n";
                regStatus = false;
            }
            else if(formChild[i].type=="text" && formChild[i].id=="Email" && !validateEmail(formChild[i].value))
            {
                 regMessage += "Email cannot be empty and must be in correct format.\n";
                 regStatus = false;
            }
     }

     if(!regStatus)
     {
         alert(regMessage);
         return false;
     }
     else
     {
      //  document.getElementById("contact-form").submit();
        return true;
     }
}
