﻿    var selectedRow = null;
    var selectedElem = null;
    var Validateonblur=false;
    var CurrentEmailAddress =null;
    var ElementIdPrefix="ctl00_MainContent_";
    var imagesPrefix = "";
    var environment = "";

    

    //onmouse over Row function
    //----------------------------    
    function onmouseoverRow(elemId)
    {
  
        return;
        var selectedElement = eval(elemId)
        var infoPanel = $(selectedElement.InfoMessage);
        var offsetParent = $(selectedElement.ElementId);
                
        var positions = offsetParent.position();
        
        infoPanel.css("left",positions.left + 640 + "px");
        infoPanel.css("top",positions.top + "px");
        infoPanel.css("display", "block");
        
        $(selectedElement.ErrorMessagePanel).css("left",positions.left + 469 + "px");
        $(selectedElement.ErrorMessagePanel).css("top",positions.top-5 + "px");
        
    }
    
  
    //onmouse out Row function
    //----------------------------
    function onmouseoutRow(elemId)
    {
        return;
        var selectedElement = eval(elemId);
        if(selectedElem==selectedElement)
            return;
        $(selectedElement.InfoMessage).style.display= 'none';
   }
     
    //select Row function
    //----------------------------
    
 
    
    function selectRow(elemId)
    {
        
        if(selectedElem != null)
        {
            if(selectedElem==eval(elemId))
                return;
            $(selectedElem.InfoMessage).css("display","none");
        }
        
        selectedElem = eval(elemId);
        
        var offsetParent    = $(selectedElem.ElementId);
        //offsetParent.css("border","1px solid red");
            
        var positions       = offsetParent.offset();
        var infoPanel       = $(selectedElem.InfoMessage);
        
        $(selectedElem.ErrorMessagePanel).css("left",positions.left + 469 + "px");
        $(selectedElem.ErrorMessagePanel).css("top",positions.top-5 + "px");
        
        infoPanel.css("left",positions.left + 469 + "px");
        infoPanel.css("top",positions.top-5 + "px");
        $(selectedElem.InfoMessage).fadeIn("slow");
        
        //infoPanel.addClass("formElement-informationPanel-checked");
        
        
    }


 
 function MarkMeAsEligibleForValidation(elemId)
 {   
    setTimeout(function(){
        selectedElem = eval(elemId);
        if($(selectedElem.TextBox).value!="" && selectedElem.IsEligibleForValidation == false)
        {
            selectedElem.IsEligibleForValidation = true;
        }
    },50);
}
 
 
    //----------------------------
    //todo Captcha  Json Element!!!!!!!
    //----------------------------
    var formElementCaptcha = {
        ElementId : "CaptchaPanel",
        ErrorMessagePanel : "CaptchErrorMsgBox",
        InfoMessage : "CaptchaInfoBox",
        TextBox : ElementIdPrefix+"txtCaptch",
        captchaValue: "imgCaptchValue",
        Valid : false
    }
    
    //User Name Validation function
    //-----------------------------
    function UserNameValidation()
    { 
      if(!formElementUserName.IsEligibleForValidation)
        return;
        
      formElementUserName.Available = true;
      if(formElementUserName.ValidationFunction())
      {
        formElementUserName.AvailablityFunction();
        //signupEventTracker._trackEvent('UserName'); 
      }
      CurrentUserName=$(formElementUserName.TextBox).val();
      
    }

    //Ajax Call of Element Availebility
    //---------------------------------
    function AjaxCall(JsonParams,jsonElement)
    {
        
           //prompt("","http://aniboom/Resources/Interfaces/GeneralServices.aspx?mdn=" + jsonElement.ServerMethodName.replace("#","") + "&dt=" + JsonParams.data);
           $.ajax({
           type: "POST",
           url: fullAppPath + "/Resources/Interfaces/GeneralServices.aspx?mdn=" + jsonElement.ServerMethodName.replace("#","") + "&dt=" + JsonParams.data,
           data: "{}",
            
           success: function(msg){
                
                jsonElement.onBlurCallBackFunction(msg);
           },
           
            error: function(object, text, error) 
            {
                window.status = object.status;
            }

         });
         
         
       
       /*
       new Ajax.Request('http://www.aniboom.com/Services/MembershipService.asmx/' + jsonElement.ServerMethodName,
        {   parameters: JsonParams,
            method: 'post', 
            onSuccess: function(transport)
            {  
               var callback = transport.responseXML.documentElement.firstChild.data.evalJSON();
               jsonElement.onBlurCallBackFunction(callback);
               /* 
                else if(methodName == "ValidateCaptcha"){
                    formElementCaptcha.Valid = callback.available;
                    alert(formElementCaptcha.Valid )
                 }
              
            },
            
            onFailure: function(){
                window.status = "problem with ajax";
            }
            
            
        });
        */
    }
     
     
     
         //----------------------------
    //Email Address  Json Element
    //----------------------------
     var formElementEmailAddress = {
        ElementId : "#EmailAddressPanel",
        ErrorMessagePanel : "#EmailAddressErrorMsgBox",
        InfoMessage : "#EmailAddressInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtEmailAddress",
        ServerMethodName : "#EmailAddressAvailbiltyCheck",
        AvailabilityErrorMessagePanel : "#EmailAvailabilityErrorMessagePanel",
        IsEligibleForValidation : false,
        Object : function(){ return new AbstractElement(this) },
        AvailablityFunction : function()
        {             
        
            
            AjaxCall(
                { data: escape($(formElementEmailAddress.TextBox).val()) }, 
                this);
        },
        Valid: false,
        Available : true,
        AvailbalityBox: "#" + ElementIdPrefix+"EmailAddressAvailbalityBox",
        
        onBlurCallBackFunction : function(callback)
        {
            formElementEmailAddress.Available=eval(callback);
            
            if(!formElementEmailAddress.Available){
                formElementEmailAddress.ValidationFunction();
            }
        },
        
        ValidationFunction : function()
        {
            $(formElementEmailAddress.AvailabilityErrorMessagePanel).css("display","none");
            $(formElementEmailAddress.AvailbalityBox).html("");
            formElementEmailAddress.Valid=TrimValidation($(formElementEmailAddress.TextBox).val());
             if(formElementEmailAddress.Valid)
             {
                var regexp=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                formElementEmailAddress.Valid=regexp.test($(formElementEmailAddress.TextBox).val());
             }
             
             
              if(!formElementEmailAddress.Available){
                formElementEmailAddress.Valid = false;
              }
           
             if(!formElementEmailAddress.Valid){
                $(formElementEmailAddress.ErrorMessagePanel).css("display","block");
                //$(formElementEmailAddress.TextBox).addClass("formElement-field-input-Error");
                $(this.ElementId + "Indication").removeClass("formElement-validIndication");
                $(this.ElementId + "Indication").addClass("formElement-errorIndication");
                }
             else{
                CurrentEmailAddress = "";
                $(formElementEmailAddress.ErrorMessagePanel).css("display","none");
                //$(formElementEmailAddress.TextBox).addClass("formElement-field-input");
                $(this.ElementId + "Indication").addClass("formElement-validIndication");
                $(this.ElementId + "Indication").removeClass("formElement-errorIndication");
               }
             return formElementEmailAddress.Valid;
        }
    }
    //EmailAddress Validation function
    //----------------------------
    
    
    function EmailAddressValidation(){
        
        if(!formElementEmailAddress.IsEligibleForValidation)
            return;
        
        formElementEmailAddress.Available = true;
        if(formElementEmailAddress.ValidationFunction()) 
        {
            formElementEmailAddress.AvailablityFunction()   
        }
    }

    
    //----------------------------
    //User Name Json Element
    //----------------------------
    var formElementUserName = {
        ElementId : "#UserNamePanel",
        ErrorMessagePanel : "#UserNameErrorMsgBox",
        InfoMessage : "#UserNameInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtUserName",
        Available : true,
        AvailbalityBox: "#" + ElementIdPrefix+"UserNameAvailbalityBox",
        ServerMethodName : "#UserNameAvailbiltyCheck",
        AvailabilityErrorMessagePanel : "#UserNameErrorAvailbalityBox",
        IsEligibleForValidation : false,
        
        onBlurCallBackFunction : function(callback)
        {
            
            formElementUserName.Available=eval(callback);
            
            if(!formElementUserName.Available){
                formElementUserName.ValidationFunction();
            }
        },
        
        AvailablityFunction : function()
        {

            AjaxCall({ data: escape($(formElementUserName.TextBox).val()) }, this);
                   
        },
        Valid : false,
        ValidationFunction : function()
        {   
            
           formElementUserName.Valid = TrimValidation($(formElementUserName.TextBox).val());
           if(formElementUserName.Valid)
           {
                formElementUserName.Valid = LengthValidation($(formElementUserName.TextBox).val(),6,50); 
           }
           
           if(!formElementUserName.Available){
                formElementUserName.Valid = false;
           }
            
           if(!formElementUserName.Valid){
                
              $(formElementUserName.ErrorMessagePanel).css("display","block");
              //$(formElementUserName.TextBox).addClass("formElement-field-input-Error");
              $(this.ElementId + "Indication").removeClass("formElement-validIndication");
              $(this.ElementId + "Indication").addClass("formElement-errorIndication");
              }
           else{
            
              CurrentUserName = "";
              $(formElementUserName.ErrorMessagePanel).css("display","none");
              //$(formElementUserName.TextBox).addClass("formElement-field-input");
              $(this.ElementId + "Indication").addClass("formElement-validIndication");
              $(this.ElementId + "Indication").removeClass("formElement-errorIndication");
              }
           
           return formElementUserName.Valid;
            
        }
         
    }
    
    
    //----------------------------
    //Password Json Element
    //----------------------------
     var formElementPassword = {
        //me : formElementPassword,
        ElementId : "#PasswordPanel",
        ErrorMessagePanel : "#PasswordErrorMsgBox",
        InfoMessage : "#PasswordInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtPassword",
        Valid: false,
        IsEligibleForValidation : false,
        
        ValidationFunction : function ()
        {
            
            if(!this.IsEligibleForValidation)
                return;
            
            formElementPassword.Valid = charactersValidationfunction($(formElementPassword.TextBox).val(),6,50);
            
            if(!formElementPassword.Valid)
            {
              $(formElementPassword.ErrorMessagePanel).css("display","block");
              $(formElementPassword.TextBox).addClass("formElement-field-input-Error");
              $(this.ElementId + "Indication").removeClass("formElement-validIndication");
              $(this.ElementId + "Indication").addClass("formElement-errorIndication");
              
            }
            else
            {
                //signupEventTracker._trackEvent('Password'); 
                formElementVerifyPassword.ValidationFunction();
                $(formElementPassword.TextBox).addClass("formElement-field-input");
                $(formElementPassword.ErrorMessagePanel).css("display","none");
                $(this.ElementId + "Indication").addClass("formElement-validIndication");
              $(this.ElementId + "Indication").removeClass("formElement-errorIndication");
            }
              
           return formElementPassword.Valid
        }
    }
    
    
    
    //----------------------------
    //Verify Password Json Element
    //----------------------------
    var formElementVerifyPassword = {
        ElementId : "#VerifyPasswordPanel",
        ErrorMessagePanel : "#VerifyPasswordErrorMsgBox",
        InfoMessage : "#VerifyPasswordInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtVerifyPassword",
        Valid: false,
        IsEligibleForValidation : false,
        
        ValidationFunction :function ()
        {
           if(!this.IsEligibleForValidation)
                return;
           formElementPassword.IsEligibleForValidation = true;
            
            formElementVerifyPassword.Valid = VerifyPasswordValidation($(formElementVerifyPassword.TextBox).val(),6,50);
            
           if(! formElementVerifyPassword.Valid)
           {
              $(formElementVerifyPassword.ErrorMessagePanel).css("display","block");
              $(formElementVerifyPassword.TextBox).addClass("formElement-field-input-Error");
              $(this.ElementId + "Indication").removeClass("formElement-validIndication");
              $(this.ElementId + "Indication").addClass("formElement-errorIndication");
            }
           else{
                
              $(formElementVerifyPassword.ErrorMessagePanel).css("display","none");
              $(formElementVerifyPassword.TextBox).addClass("formElement-field-input");
              $(this.ElementId + "Indication").addClass("formElement-validIndication");
              $(this.ElementId + "Indication").removeClass("formElement-errorIndication");
            }
              
           return  formElementVerifyPassword.Valid
        }
    }
    
    
    //----------------------------
    //ZoneType Json Element
    //----------------------------
    var formElementZoneType = {
        ElementId : "#ZoneTypePanel",
        ErrorMessagePanel : "#ZoneTypeErrorMsgBox",
        InfoMessage : "#ZoneTypeInfoBox",
        TextBox : "#" + ElementIdPrefix+"ZoneType",
        ValidationFunction :ZoneTypeValidation,
        IsEligibleForValidation : false
    }
    
    var selectedValue
    function ZoneTypeChangedEventHandler(ddlZoneType,elemId)
	{
        var elem = eval(elemId);
        var selectedValue = ddlZoneType.value;
        var label = "";
        $(elem.TextBox).value = selectedValue;
	    
	    switch(selectedValue){
	         
            case "3":
	            $(formElementLastName.ElementId).css("display","none");
	            label = "Company";
	        break; 
	        
	        case "4":
	            $(formElementLastName.ElementId).css("display","none");
	            label = "School";
	        break;
	        
	        case "5":
	            $(formElementLastName.ElementId).css("display","none");
	            label = "Festival";
	        break;
	        
	        default:
	            label = "First Name";
	            $(formElementFirstName.ElementId).css("display","block");   
	            $(formElementLastName.ElementId).css("display","block");   
	            $(formElementLastName.TextBox).value = "";
	            
	        break;
	    }
	    
	    if(label!="First Name"){
	        $(formElementLastName.TextBox).value = label;
	    }
	    $(formElementFirstName.Label).innerHTML = label;
	}
    
   
   
   
    
    //----------------------------
    //First Name Json Element
    //----------------------------
    var formElementFirstName = {
        ElementId : "#FirstNamePanel",
        ErrorMessagePanel : "#FirstNameErrorMsgBox",
        InfoMessage : "#FirstNameInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtFirstName",
        Label : "#FirstNameLabel",
        Valid : false,
        IsEligibleForValidation : false,
        
        ValidationFunction : function()
        {
            if(!this.IsEligibleForValidation)
                return;
           formElementFirstName.Valid = LengthValidation($(formElementFirstName.TextBox).val(),1,100);
           if(!formElementFirstName.Valid){
              $(formElementFirstName.ErrorMessagePanel).css("display","block");
              $(formElementFirstName.TextBox).addClass("formElement-field-input-Error");
           }
           else{
                
              $(formElementFirstName.ErrorMessagePanel).css("display","none");
              $(formElementFirstName.TextBox).addClass("formElement-field-input");
           }  
           return formElementFirstName.Valid
        }
        
    }
    

    //----------------------------
    //Last Name Json Element
    //----------------------------
     var formElementLastName = {
        ElementId : "#LastNamePanel",
        ErrorMessagePanel : "#LastNameErrorMsgBox",
        InfoMessage : "#LastNameInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtLastName",
        Valid : false,
        IsEligibleForValidation : false,
        
        ValidationFunction : function()
        {
            if(!this.IsEligibleForValidation)
                return;
           formElementLastName.Valid = LengthValidation($(formElementLastName.TextBox).val(),1,100);
           if(!formElementLastName.Valid){
              $(formElementLastName.ErrorMessagePanel).css("display","block");
              $(formElementLastName.TextBox).addClass("formElement-field-input-Error");
            }
           else{
               //signupEventTracker._trackEvent('Last Name'); 
              $(formElementLastName.ErrorMessagePanel).css("display","none");
              $(formElementLastName.TextBox).addClass("formElement-field-input");
           }
              
           return formElementLastName.Valid
        }
    }
    
        
        
     //----------------------------
    //Head Line Json Element
    //----------------------------
    var formElementHeadLine = {
        ElementId : "#HeadLinePanel",
        ErrorMessagePanel : "#HeadLineErrorMsgBox",
        InfoMessage : "#HeadLineInfoBox",
        TextBox : "#" + ElementIdPrefix+"txtHeadLine",
        Valid : false,
        IsEligibleForValidation : false,
        
        ValidationFunction : function()
        {
            if(!this.IsEligibleForValidation)
                return;
           formElementHeadLine.Valid = LengthValidation($(formElementHeadLine.TextBox).val(),1,100);
           if(!formElementHeadLine.Valid){
              $(formElementHeadLine.ErrorMessagePanel).css("display","block");
              $(formElementHeadLine.TextBox).addClass("formElement-field-input-Error");
           }
           else{
               //signupEventTracker._trackEvent('Express Yourself'); 
              $(formElementHeadLine.ErrorMessagePanel).css("display","none");
              $(formElementHeadLine.TextBox).addClass("formElement-field-input");
           }
              
           return formElementHeadLine.Valid
        }
    }
    
    
    //----------------------------
    //Captcha Line
    //----------------------------
    var formElementCaptcha = {
        ElementId : "#CaptchaPanel",
        ErrorMessagePanel : "#CaptchaErrorMsgBox",
        InfoMessage : "#CaptchaInfoBox",
        TextBox : "#" + ElementIdPrefix + "txtcaptcha",
        Valid : false,
        IsEligibleForValidation : false,
        
        ValidationFunction : function()
        {
            
            if(!this.IsEligibleForValidation)
                return;
            
            this.Valid = (!IsEmpty($(this.TextBox).val()));
            
            if(!this.Valid){
                $(this.ErrorMessagePanel).css("display","block");
                $(this.TextBox).addClass("formElement-field-input-Error");
                $(this.ElementId + "Indication").removeClass("formElement-validIndication");
                $(this.ElementId + "Indication").addClass("formElement-errorIndication");
            }
            else{
                $(this.ErrorMessagePanel).css("display","none");
                $(this.TextBox).addClass("formElement-field-input");
                $(this.ElementId + "Indication").addClass("formElement-validIndication");
                $(this.ElementId + "Indication").removeClass("formElement-errorIndication");
            }
           
           return this.Valid;
        }
    }
    
    
      //----------------------------
    //Captcha Line
    //----------------------------
    var formElementPrivacy = {
        ElementId : "#PrivacyPanel",
        ErrorMessagePanel : "#PrivacyErrorMsgBox",
        InfoMessage : "#PrivacyInfoBox",
        TextBox : ElementIdPrefix + "PrivacyTermsCheckBox",
        Valid : false,
        IsEligibleForValidation : false,
        
        ValidationFunction : function()
        {
            
            if(!this.IsEligibleForValidation)
                return;
            
            this.Valid = document.getElementById(this.TextBox).checked;

            if(!this.Valid)
            {
            
                
                $(this.ErrorMessagePanel).css("display","block");
                /*
                $(this.TextBox).addClass("formElement-field-input-Error");
                $(this.ElementId + "Indication").removeClass("formElement-validIndication");
                $(this.ElementId + "Indication").addClass("formElement-errorIndication");
                */
                
            }else{
            
                
                $(this.ErrorMessagePanel).css("display","none");
                /*
                $(this.TextBox).addClass("formElement-field-input");
                $(this.ElementId + "Indication").addClass("formElement-validIndication");
                $(this.ElementId + "Indication").removeClass("formElement-errorIndication");
                */
            }
           
           return this.Valid;
        }
    }
    //characters Validation function
    //-------------------------------
    function charactersValidationfunction(inputValue,minLength,maxLength)
    {
       
           var re=new RegExp(/^[A-Za-z0-9]{6,50}$/i) ;
           return (re.test(inputValue)) ;
               
    }
    
    //Length Validation function
    //----------------------------
    function LengthValidation(inputValue,minLength,maxLength)
    {
        var length = inputValue.replace(/^\s+|\s+$/g,"").length;    
        if(length < minLength || length >maxLength)
            return false;
        return true;
    }
    
    //Trim Validation function
    //----------------------------
    function TrimValidation(inputValue)
    {
        var Trimed=inputValue.replace(/^\s*/, "").replace(/\s+/, "");
        if(Trimed.length < inputValue.length)
            return false;
        return true;
    }
    
    function IsEmpty(str){
        
        var length = str.replace(/^\s+|\s+$/g,"").length;
        return (length==0);
        
    }
    //Verify Password Validation function
    //----------------------------
    function VerifyPasswordValidation(inputValue)
    {    
        var passval = $(formElementPassword.TextBox).val();
        
      return (passval == inputValue && formElementPassword.Valid);
        
    }
    function ZoneTypeValidation(inputValue){
        //alert(inputValue);
    }
    
    //formElements Collection function
    //--------------------------------
    function formElements(){
        this.Items = new Array();
        this.Count=this.Items.length;
        
        this.AddElement = function(elem){
            
            this.Items[this.Items.length] = elem;
            this.Count++;
        }
        
        this.GetElementByName = function(elemName){
            for(i=0;i<this.Items.length;i++){
                if(this.Items[i].Id==elemName)
                return this.Items[i];
            }
        }
   }

    
    
    var formElementsCollection = new formElements();
        formElementsCollection.AddElement(formElementUserName);
        formElementsCollection.AddElement(formElementEmailAddress);
        formElementsCollection.AddElement(formElementPassword);
        formElementsCollection.AddElement(formElementPrivacy);
        formElementsCollection.AddElement(formElementVerifyPassword);
        formElementsCollection.AddElement(formElementCaptcha);
            
    //ValidateForm function
    //-------------------------
    var counter = 0;
    function ValidateForm()
    {

       counter++;
       if(document.readyState!="complete" && counter < 30){
            setTimeout("ValidateForm()",100);
            return;
       }
       
            
       allValid = true;
       Validateonblur=true;
       
       
       for(i=0;i<formElementsCollection.Count;i++)
       {
            if(formElementsCollection.Items[i].IsEligibleForValidation){
                //alert(formElementsCollection.Items[i].ElmentId);
                //alert(formElementsCollection.Items[i].IsEligibleForValidation);
                 if(formElementsCollection.Items[i].ElementId=="#UserNamePanel")
                 {
                    UserNameValidation()
                 }
                 else if(formElementsCollection.Items[i].ElementId=="#EmailAddressPanel")
                 {
                    EmailAddressValidation()
                 }
                 else{
                   formElementsCollection.Items[i].ValidationFunction();
                 }
                  
                  $(formElementsCollection.Items[i].TextBox).bind('blur',formElementsCollection.Items[i].ValidationFunction);
                   
              if(allValid)
                  allValid = formElementsCollection.Items[i].Valid;
            }
        
            var offsetParent    = $(formElementsCollection.Items[i].ElementId);
            var positions       = offsetParent.position();
            
            $(formElementsCollection.Items[i].ErrorMessagePanel).css("left",positions.left + 469 + "px");
            $(formElementsCollection.Items[i].ErrorMessagePanel).css("top",positions.top-5 + "px");
       }
       
       return allValid;

    }
    
function MarkIsEligibleForValidation(){
    
    for(i=0;i<formElementsCollection.Count;i++){
        formElementsCollection.Items[i].IsEligibleForValidation = true;
    }
}


function fillUpPasswordFields(){
    
    if($(formElementPassword.TextBox).getAttribute("viewState"))
        $(formElementPassword.TextBox).value = $(formElementPassword.TextBox).getAttribute("viewState");
        
    if($(formElementVerifyPassword.TextBox).getAttribute("viewState"))
        $(formElementVerifyPassword.TextBox).value = $(formElementVerifyPassword.TextBox).getAttribute("viewState");
}


function ChangeCaptcha(element){
    element = element[0];
    element.src = element.src + "?id=1";
}
function CheckInputInCaptcha()
{
    if($(formElementCaptcha.Valid))
    {
        //signupEventTracker._trackEvent('Type Code Below');
    }
}