/*******************/
//This file is required for running of cb3 menu on page templates in both frontend and in backend
//When you change any thing to this file make sure the same is maintained in both backend and in front-end
// Javascript which is used to Navigate to particular page.
/// The javascript function is used by Navigation controls like Menu; Breadcrumbs; siteMap; etc.
/********************/

    //on component art menu item click
    function NavigateURL(url, target) {
        if (url && url != '') {
            var today = new Date();
            if (url == '/')
                url = '/cBaseHomePage/';
            if (target && target != '' && target != 'undefined')
                var wnd = window.open(escape(url), target);
            else
                var wnd = window.open(escape(url), '_self');
        }
    }

    //on component art menu item click
    function CreateNewPage(pageStructureId, pageId, ordinal) {

        url = '/Sites/PageStructures/PageProperty.aspx?';

        if (pageStructureId != 0)
            url = url + 'PageStructureId=' + pageStructureId

        if (pageId != 0)
            url = url + '&ParentPageId=' + pageId;

        if (ordinal != 0)
            url = url + '&Ordinal=' + ordinal;

        var openerWindow = null;
        
        if (window.parent)
            openerWindow = window.parent;
        else
            openerWindow = window;
            
        var wnd = openerWindow.open(url, '_self');
    }

    //frontend site ondemandmenu  ClientItemClicking event used for opening the correct page
    function RadMenu_OnClientItemClicking(sender, eventArgs) {
        eventArgs.set_cancel(true);
        var item = eventArgs.get_item();

        if (item.get_attributes && item.get_attributes() && item.get_attributes().getAttribute) {
            if (item.get_attributes().getAttribute("CanGoToPage") && item.get_attributes().getAttribute("CanGoToPage").toLowerCase() == "false") {
                return;
            }
            var navigateUrl = item.get_navigateUrl();
            navigateUrl.replace(/\/\//ig, "/");
            switch (item.get_attributes().getAttribute("AddNewPage")) {
                case "addnewpage":
                    CreateNewPage(item.get_attributes().getAttribute("PageStructureID"), 0, -1);
                    break;
                case "addnewsubpage":
                    CreateNewPage(item.get_attributes().getAttribute("PageStructureID"),
                                  item.get_attributes().getAttribute("ParentPageID"), -1);
                    break;
                default:
                    var target = item.get_attributes().getAttribute("Target");
                    NavigateURL(navigateUrl, target);
                    break;
            }
        }
    }

    //frontend site ondemandmenu  ClientItemPopulating event used for opening the correct page
    function RadMenu_OnClientItemPopulating(sender, eventArgs) {
        var context = eventArgs.get_context();
        //level of the current menu item is passed to page method for working of Viisble VisibleLevelsNumber property of ondemandmenu
        context["Level"] = eventArgs.get_item().get_level();
        //pass current page id to page method for preventing click on the current page for sub menu
        if (CBase3Page) {
            context["CurrentPageID"] = CBase3Page.ID;
            context["CurrentCulture"] = CBase3Page.CurrentCulture;
            context["CurrentPageUrl"] = CBase3Page.CurrentPageUrl;

        }
        else {
            context["CurrentPageID"] = 0;
            //context["CurrentCulture"] = "nl-NL";  // better to handle this from server.
        }
        context["MenuItemCssClass"] = sender.get_attributes().getAttribute("MenuItemCssClass");
    }

     //after popilation set id property
    function RadMenu_OnClientItemPopulated(sender, args) {

        if (args && args.get_item && args.get_item().get_items) {
            args.get_item().get_items().forEach(function(item) {
                item.get_element().id = item.get_attributes().getAttribute("ClassID");
            });
        }
    }

   //set id property  to root level items
    function RadMenu_OnClientLoad(sender, args) {
        if (sender && sender.get_items) {
            sender.get_items().forEach(function(item) {
                if (item && item.get_element && item.get_attributes) {
                    item.get_element().id = item.get_attributes().getAttribute("ClassID");
                }
            });
        }
    }
  /*Functions for FAQ Renderer*/
  
  function TogleSubjectGroupVisibility(object) 
   {
       if(object)
       {
            var divGroupID = object.getAttribute('GroupID');
            var qaGroup = document.getElementById(divGroupID);
            if(qaGroup)
            {
               var answerCollection = qaGroup.getElementsByTagName("SPAN");
               var answesCount = answerCollection.length;
               var styleValue = (object.getAttribute("CHECKED"))?'':'none';
               if(answerCollection && answesCount > 0)
               {
                   for(var i=0; i<answesCount; i++)
                   {
                        if(answerCollection[i].id.substring(0,6) == "Answer")
                            answerCollection[i].style.display = styleValue;
                   }
               }
            }
       } 
   }
   
   function TogleAnswerVisibility(answerID) 
   {
        var divAnswer = document.getElementById(answerID);
        if(divAnswer)
        {
           if(divAnswer.style.display == '')
                divAnswer.style.display = 'none';
           else
                divAnswer.style.display = '';
        }
   }
    
    /*End of FAQ */
    
    /* Functions for Poll Renderer */
    
    function PollRenderControl_PollAnserOkButtonClientClick(objectID,optionSelcted,pollID,messageText)
    {
        var pollAnswerDiv = document.getElementById("PollAnswerDiv");
        if (pollAnswerDiv) pollAnswerDiv.disabled = true;
        if(document.getElementById(optionSelcted) && document.getElementById(optionSelcted).value != "") {

            if (parseInt(pollID) != parseInt(readCookie("Cbase3Poll" + pollID)))
                __doPostBack(objectID);
            else
                alert(messageText);
        }
    }
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }
    function ClickCheck(sender,pollAnswerHidden)
    {
        var pollAnswer = document.getElementById(pollAnswerHidden);
        if(pollAnswer != null && sender != null)
            pollAnswer.value = sender.value;
    }

    function PollRendererControlCallBack_onComplete(sender,eventArgs)
    {
        var pollAnswerDiv = document.getElementById("PollAnswerDiv");
        if (pollAnswerDiv) pollAnswerDiv.disabled = false;
    }

    function PollRendererControlCallBack_onError(sender,eventArgs)
    {
        var pollAnswerDiv = document.getElementById("PollAnswerDiv");
        if (pollAnswerDiv) pollAnswerDiv.disabled = false;
    }
     
    function PollRendererControlCallBack_Load(sender,eventArgs)
    {
	/*
		debugger;
		var div = document.getElementById(sender.Id);
		if (div)
		{
			var span = document.createElement("Span");
			span.innerHTML = div.innerHTML;
			var parentNode = div.parentElement;
			parentNode.removeChild(div);
			parentNode.appendChild(span);
		}
		*/
    }   
    
    function ValidatePollAnswer(sender,eventArg)
    {
        var flag = true;
        if(pollAnswerID == 0)
            flag = false;
        
        //Set Validation Message.
        var validationSummay = document.getElementById("PollRendererControlValidationSummary");
        if (validationSummay) 
            if (flag)
                validationSummay.innerHTML = sender.ErrorMessage;
            else
                validationSummay.innerHTML = sender.ErrorMessage;
        
        eventArg.IsValid = flag;
    }
    
    /* End of Poll */
    
    /*Calendar Overview scripts */
    
    // Move an element directly on top of another element (and optionally
    // make it the same size) 
    var selectedID = 0;
    function Cover(bottom, top, ignoreSize)  
    {
        //debugger;
        var location = Sys.UI.DomElement.getLocation(bottom);
        top.style.position = 'absolute';
        top.style.top = location.y + 'px';
        top.style.left = location.x + 'px';    
        if (!ignoreSize) 
        {
            top.style.height = bottom.offsetHeight + 'px';
            top.style.width = bottom.offsetWidth + 'px';
        }  
        return false;
    }
    function TriggerAnimation(id)
    {
        var animBehavior = $find(id.toString());
        if (animBehavior!=null)
            animBehavior.get_OnClickBehavior().get_animation().play();
        
        return false;
    }
    function CalendarOverview_RowContextMenu(menu,index, e)
    {
        menu.Show(e);
 
        e.cancelBubble = true;
        e.returnValue = false;
        if (e.stopPropagation)
        {
           e.stopPropagation();
           e.preventDefault();
        }
        selectedID = index;
//        this.SelectRow(this.Rows[index].Control, true);
    }
    function RadMenuClientItemClick(sender, eventArgs)
    {
        try
        {
            var id = selectedID; 
            if (eventArgs.Item.Value == "1")
            {
                TriggerAnimation(id);
            }
            else if (eventArgs.Item.Value == "3")
            {
                SaveCalendarOverviewInFormateCallBack.Callback("iCalendar",id);
            }
            else if (eventArgs.Item.Value == "4")
            {
                SaveCalendarOverviewInFormateCallBack.Callback("vCalendar",id);
            }
        }
        catch(ex)
        {
            
        }
       return false;
    }
    function TogleEventVisibility(obj,id) 
   {
        var divAnswer = document.getElementById('DetailsRepeaterDiv'+id); 
        if(divAnswer)
        {
           if(divAnswer.style.display == '')
           {
                divAnswer.style.display = 'none';
                obj.src = "Images/Minus.GIF"; 
           }
           else
           {
                divAnswer.style.display = '';
                obj.src = "Images/Plus.GIF";
           }
        }
   }
    /* End CalendarOverview */
    
    /* Calendar picker scripts*/
    
        function Calendar1_onSelectionChanged(sender, args)
    {
        var selectedDatesCollection = sender.get_selectedDates();
        var selectedRangeDate = "";
        for(var i = 0;i < selectedDatesCollection.DateArray.length;i++)
        {
            if(selectedRangeDate == "")
                selectedRangeDate =  selectedDatesCollection.DateArray[i].toLocaleString();
            else
                selectedRangeDate +=  "|" + selectedDatesCollection.DateArray[i].toLocaleString();
        }
       CalendarPickerGridCallBack.Callback('Rebind',selectedRangeDate);
    }
    function getTodayDate(calendar)
    {
        
        calendar.clearSelectedDate();
        calendar.SetSelectedDate(new Date());
        CalendarSplitterCallBack.Callback('Initialize');
        
    }
    var imageButtonPath = null;  
    var targetControl;  
    function RowClick(rowIndex, e)
    {   
        if(this.Rows[rowIndex].ItemType != "NestedView")  
        {  
            if(e.srcElement)  
            {  
                targetControl = e.srcElement;  
            }  
            else if(e.target)  
            {  
                targetControl = e.target;  
            }  
            if(targetControl.tagName != "IMG")  
            {  
                if(this.Rows[rowIndex+1].ItemType == "NestedView" && this.Name != "DetailTable")  
                {  
                    if(this.Rows[rowIndex+1].Control.style.display == "" || this.Rows[rowIndex+1].Control.style.display == "block" || this.Rows[rowIndex+1].Control.style.display == "table-row")  
                    {  
                        this.Rows[rowIndex+1].Control.style.display = "none";  
                        imageButtonPath = this.GetCellByColumnUniqueName(this.Rows[rowIndex], "ExpandColumn").childNodes[0].src;  
                        imageButtonPath = imageButtonPath.replace("SingleMinus","SinglePlus");  
                        this.GetCellByColumnUniqueName(this.Rows[rowIndex], "ExpandColumn").childNodes[0].src = imageButtonPath;  
                        this.GetCellByColumnUniqueName(this.Rows[rowIndex], "ExpandColumn").childNodes[0].title = "Expand";  
                    }  
                    else if(this.Rows[rowIndex+1].Control.style.display == "none")  
                    {  
                        this.Rows[rowIndex+1].Control.style.display = "";  
                        imageButtonPath = this.GetCellByColumnUniqueName(this.Rows[rowIndex], "ExpandColumn").childNodes[0].src;  
                        imageButtonPath = imageButtonPath.replace("SinglePlus","SingleMinus");  
                        this.GetCellByColumnUniqueName(this.Rows[rowIndex], "ExpandColumn").childNodes[0].src = imageButtonPath;  
                        this.GetCellByColumnUniqueName(this.Rows[rowIndex], "ExpandColumn").childNodes[0].title = "Collapse";  
                    }  
                }    
            }
            this.SelectRow(this.Rows[rowIndex].Control, true);
        }      
    }
    function CalendarPicker_RowContextMenu(menu, index, e)
    {
       
        menu.Show(e);
 
        e.cancelBubble = true;
        e.returnValue = false;
        if (e.stopPropagation)
        {
           e.stopPropagation();
           e.preventDefault();
        }
//        this.SelectRow(this.Rows[index].Control, true);
    }
  
   function ToglePickerEventVisibility(obj,id) 
   {
    
       
        var divAnswer = document.getElementById('DetailsView'+id); 
        //var divAnswer = document.getElementById(answerID);
        if(divAnswer)
        {
           if(divAnswer.style.display == '')
           {
                divAnswer.style.display = 'none';
                obj.src = "Images/Plus.GIF"; 
           }
           else
           {
                divAnswer.style.display = '';
                obj.src = "Images/Minus.GIF";
           }
        }
   }
   

    /* End of calendar picker*/
    
    /* Functions for Form Renderer */
       
        function doBeforePaste(control)
        {
           maxLength = control.attributes['maxLength'].value;
           if(maxLength)
           {
               event.returnValue = false;
           }
        }
        function doPaste(control)
        {
           maxLength = control.attributes['maxLength'].value;
           value = control.value;
           if(maxLength){
                event.returnValue = false;
                maxLength = parseInt(maxLength);
                var o = control.document.selection.createRange();
                var iInsertLength = maxLength - value.length + o.text.length;
                var sData = window.clipboardData.getData('Text').substr(0,iInsertLength);
                o.text = sData;
            }
        }
        function LimitInput(control)
        {
            if(control.value.length > control.attributes['maxLength'].value)
            {
                control.value = control.value.substring(0,control.attributes['maxLength'].value);
            }
        }
        function validateOption(control, min, max, desimals, digitsBeforeDesimal, onlyPositive,isRequried) 
        {
            if (isRequried.toLowerCase() == 'true')
                ValidateEmptyText(control)
            
                var data = '';
                if (document.getElementById(control))
                    data = document.getElementById(control).value;
                if (TrimAll(data) != "") {
                    var isNumber = true;
                    var isValidRange = true;
                    var isValidExpression = true;
                    var alreadyHasDesimal = false;
                    var c;

                    for (var i = 0; i < data.length; i++) {
                        c = ascii_value(data.charAt(i));
                        if (c == 45) // code for a minus sign
                        {
                            if (i == 0) //OK at first position.
                                continue;
                            else {
                                isNumber = false;
                                break;
                            }
                        }
                        if (c == 46) // code for decimal point.
                        {
                            if (!alreadyHasDesimal) {
                                alreadyHasDesimal = true;
                                continue;
                            }
                            else {
                                isNumber = false;
                                break;
                            }
                        }
                        if (c < 48 || c > 57) // Codes for the digis...
                            isNumber = false;
                    }
                    if (isNumber) {
                        if (data > max)
                            isValidRange = false;
                        else if (data < min)
                            isValidRange = false;
                        if (isValidRange) {
                            var expression = createExpression(desimals, digitsBeforeDesimal, onlyPositive)
                            var isValidExpression = validateNumberWithRegularExpression(expression, data);
                        }
                    }
                    if (!isValidRange || !isValidExpression || !isNumber) {
                        if (document.getElementById(control) && document.getElementById(control).parentNode && document.getElementById(control).parentNode.children[3])
                            document.getElementById(control).parentNode.children[3].style.display = "";
                        count++;
                        return false;
                    }
                    else {
                        if (document.getElementById(control) && document.getElementById(control).parentNode && document.getElementById(control).parentNode.children[3])
                            document.getElementById(control).parentNode.children[3].style.display = "none";
                        return true;
                    }
                }
        }
        function createExpression(desimals,digitsBeforeDesimal,onlyPositive)
        {
            var expression="";
            expression+="^";
            //Only Positive number
            if(false == onlyPositive)
                expression+="[-+]";
            else
                expression+="[+]";
                
            expression+="?";
            //Digits before desimal
            if(digitsBeforeDesimal == "")
                expression+="[0-9]*";
            else
            {
                expression+="[0-9]";
                expression+="{0,";
                expression+=digitsBeforeDesimal;
                expression+="}";
            }
            //Number of Desimal points
            if(parseInt(desimals) > 0)
            {
                expression+="(\\"
                expression+=".[0-9]";
                expression+="{1,";
                expression+=desimals;
                expression+="})?";
            }
            expression+="$";
            return expression;
        }
        function validateNumberWithRegularExpression(expression,Number)
        {
           var regularExpression  =  new RegExp(expression);
           return regularExpression.test(Number);
        }
        function ascii_value(c)
        {
	        // restrict input to a single character
	        c = c.charAt (0);

	        // loop through all possible ASCII values
	        var i;
	        for (i = 0; i < 256; ++ i)
	        {
		        // convert i into a 2-digit hex string
		        var h = i . toString (16);
		        if (h . length == 1)
			        h = "0" + h;

		        // insert a % character into the string
		        h = "%" + h;

		        // determine the character represented by the escape code
		        h = unescape (h);

		        // if the characters match, we've found the ASCII value
		        if (h == c)
			        break;
	        }
	        return i;
        }
        function WatermarkFocus(txtElem, strWatermark) 
        {
             if (txtElem.value == strWatermark) 
             {
                txtElem.value = '';
                txtElem.className ="withoutWatermarkClass";
             }
        }

        function WatermarkBlur(txtElem, strWatermark) 
        {
            if (TrimAll(txtElem.value) == '') 
             {
                txtElem.value = strWatermark;
                txtElem.className ="withWatermarkClass";
            }

        }
        function TrimAll(text) {
            if (!text || !text.replace) text = text;
            text = text.replace(/^\s+/ig, "");

            return text.replace(/\s+$/ig, "");

        }
         //********This section added by sudhir for form renderer**********
        // javascript function to post data on submit button of form
        
        function onFormSubmitButtonClientClick(senButtonUniqueId)
        {
//            if (typeof(Page_ClientValidate)=="function") Page_ClientValidate("FormElements");
//            if (typeof(Page_IsValid) == "undefined" || true==Page_IsValid)
//            {
//                __doPostBack(senButtonUniqueId);
            //            }
            count = 0;
            if (ValidateFormData())
                __doPostBack(senButtonUniqueId);
            else {
                return false;
            }
        }
        function ValidateEmptyText(sender) {
            var flag = true;
            var obj = document.getElementById(sender);
            var errorObj = document.getElementById(sender + "_errorSpan");
            if (obj) {
                flag = (obj.value.replace(/^\s+|\s+$/g, '') != "");

            }
            if (!flag) {
                count++;
                if (errorObj) errorObj.style.display = "";

            }
            else
                if (errorObj) errorObj.style.display = "none";

            return flag;

        }
        //Function validates whether the email address specified is valid
        //function skips the validation if nothing is specified.as empty text is also valid. :)
        function ValidateEmailAddress(sender) {
            var flag = true;
            var errorObj = document.getElementById(sender + "_errorSpan");
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            var obj = document.getElementById(sender);

            if (obj && TrimAll(obj.value) != "")
                flag = filter.test(obj.value)

            if (!flag) {
                count++;
                if (errorObj) errorObj.style.display = "";
            }
            else
                if (errorObj) errorObj.style.display = "none";
            return flag;
        }
        //Function validates whether email address is specified and is valid
        //This is to be used when the email address field is also a required field
        function ValidateRequiredEmailAddress(sender) {
            var flag = true;
            var errorObj = document.getElementById(sender + "_errorSpan");
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            var obj = document.getElementById(sender);

            if (obj)
                flag = filter.test(obj.value)

            if (!flag) {
                count++;
                if (errorObj) errorObj.style.display = "";
            }
            else
                if (errorObj) errorObj.style.display = "none";
            return flag;
        }
        function ValidateDropdownList(sender) {
            var flag = true;
            var obj = document.getElementById(sender);
            var errorObj = document.getElementById(sender + "_errorSpan");
            if (obj) {
                flag = (obj.selectedIndex > 0);
            }
            if (!flag) {
                count++;
                if (errorObj) errorObj.style.display = "";

            }
            else
                if (errorObj) errorObj.style.display = "none";
            return flag;

        }

        function ValidateCheckBoxList(sender) {
            var flag = false;
            var minimumChoices;
            var userCheckedChoices = 0;
            var obj = document.getElementById(sender);
            if (obj && obj.getAttribute) minimumChoices = parseInt(obj.getAttribute("MinimumChoices"));
            if (minimumChoices == 0) minimumChoices = 1;
            var errorObj = document.getElementById(sender + "_errorSpan");
            if (obj && obj.getElementsByTagName("input") && obj.getElementsByTagName("input").length > 0) {
                for (var item = 0; item <= obj.getElementsByTagName("input").length; item++) {
                    if (obj.getElementsByTagName("input")[item] && obj.getElementsByTagName("input")[item].type == "checkbox" && obj.getElementsByTagName("input")[item].checked) {
                        userCheckedChoices++;
                    }
                }
            }
            flag = (userCheckedChoices >= minimumChoices);
            if (!flag) {
                count++;
                if (errorObj) errorObj.style.display = "";

            }
            else
                if (errorObj) errorObj.style.display = "none";
            return flag;
        }
        //********************************************************************
    /* End of Functions for Forms*/
    
       //function to execute the script returned by the renderer
    function cloneInnerHTML(node, target) 
    {
	    if (target) 
	    {
		    newNode = target;
		    target.innerHTML = '';
	    } 
	    else 
	    {
		    var newNode = node.cloneNode(false);
	    }

	    if (node.hasChildNodes()) 
	    {
		    var children = node.childNodes;
		    for (var i = 0; i < children.length; i++) 
		    {
			    var child = children[i];
			    if (child.tagName == 'SCRIPT') 
			    {
				    var newScript = document.createElement('script');
				    newScript.setAttribute('type', 'text/javascript');
				    newScript.setAttribute('id', child.getAttribute('id'));
				    //copyScriptText(child, newScript);
				    if (child.src) 
				        newScript.src = child.src;
				    else
				        newScript.text =  child.text;
				    newNode.appendChild(newScript);
			    } 
			    else 
			    {
				    newNode.appendChild(cloneInnerHTML(child, null));
			    }
		    }
	    }
	    return newNode;
    }
      /* Functions for RSSButton Renderer Control */
    function LoadRSSNews(rssURL)
    {
//        //debugger;
//        if(document.forms[0]!= null)
//        {
//            var form = document.forms[0];
//            form.action = formAction;
//            form.method = "post";
//            form.submit();
        //        }

        window.open(rssURL, '_blank'); 
        //window.location.href = window.location.protocol +"//"+ window.location.host +"/" +"GetNewsRSS.aspx?ContentItemID="+parseInt(catId);
    }
    /* Functions for Newletter singup Renderer */
    
     
    function NewletterSingupOKOnClientClick(OkClinetId,OkUniqueId,Nametextbox,Emailtextbox,ValidationSummary)
    { 
        var nametextbox,emailtextbox,validationSummary;
        var EmailAndNameRequried,EmailRequried,NameRequried,InvalidEmail,EmailShouldBeLessThan500Characters,NameShouldBeLessThan500Characters;
         nametextbox = document.getElementById(Nametextbox)
         var okButton = document.getElementById(OkClinetId);
         EmailAndNameRequried = okButton.getAttribute("emailAndNameRequried");
         EmailRequried = okButton.getAttribute('emailRequried');
         NameRequried = okButton.getAttribute("nameRequried");
         InvalidEmail= okButton.getAttribute("invalidEmail");
         EmailShouldBeLessThan500Characters= okButton.getAttribute("emailShouldBeLessThan500Characters");
         NameShouldBeLessThan500Characters = okButton.getAttribute("nameShouldBeLessThan500Characters");
         emailtextbox = document.getElementById(Emailtextbox)
         validationSummary = document.getElementById(ValidationSummary)

        var message = "";
        var flag = true;
        if(nametextbox && emailtextbox)
        {
            if(""==TrimAll(nametextbox.value) && ""==TrimAll(emailtextbox.value))
            {
                message = EmailAndNameRequried;//"Please Enter Name and Email Address";
                flag = false;
            }
            else if(""==TrimAll(nametextbox.value))
            {
                message = NameRequried;// "Please Enter Name";
                flag = false;
            }
            else if(""==TrimAll(emailtextbox.value))
            {
               message = EmailRequried;//"Please Enter Email Address";
               flag = false;
            }
            else if(""!=TrimAll(emailtextbox.value) && !NewletterSingupValidateEmail(emailtextbox.value))
            {
                message = InvalidEmail;// "Please Enter valid mail Address";
                flag = false;
            }
            else if(500<NewletterSingupGetLength(TrimAll(nametextbox.value)))
            {
                message = NameShouldBeLessThan500Characters;// "Please Enter valid mail Address";
                flag = false;
            }
            else if(500<NewletterSingupGetLength(TrimAll(emailtextbox.value)))
            {
                message = EmailShouldBeLessThan500Characters// "Please Enter valid mail Address";
                flag = false;
            }
        }
         if (validationSummary && !flag)
         { 
                validationSummary.style.display = 'block';
                validationSummary.innerHTML = message;
                return flag;
         }
         else
         {
            __doPostBack(OkUniqueId);
         }
        return false;
    }
    function NewletterSingupGetLength(text)
    {
        return text.length;
    }
    function NewletterSingupValidateEmail(emailAddr)
    {
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            return filter.test(emailAddr)
              
    }
   
    /* End of Functions for Newletter singup Renderer */