
<script type="text/javascript">
<!--
//Create a boolean variable to check for a valid Internet Explorer instance.
    var xmlhttp = false;
//Check if we are using IE.
    try {
//If the Javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
//alert(xmlhttp);
//alert ("You are using Microsoft Internet Explorer.");
    } catch (e) {
        //alert(e);

//If not, then use the older active x object.
        try {
//If we are using Internet Explorer.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//alert ("You are using Microsoft Internet Explorer");
        } catch (E) {
            // alert(E);
//Else we must be using a non-IE browser.
            xmlhttp = false;
        }
    }
//If we are using a non-IE browser, create a javascript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
//alert ("You are not using Microsoft Internet Explorer");
    }




//-->

    
</script>

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <div class="">
        <a href="<?php echo base_url(); ?>super_admin">Dashboard</a>->>
        <span>Edit Group</span>
    </div>
    <h3 class="page-header">Edit Group Form</h3>
    <p>
        <?php
        $message = $this->session->userdata('message');
        $this->session->unset_userdata('message');
        if ($message) {
            echo $message;
        }
        ?>
    </p>
    <div class="col-md-9 column">
        <div class="box span12">

            <div class="box-content">
                <h3 style="color: green"> 
                    <?php
                    $sdata = array();
                    $sdata['group_id'] = $group_details->group_id;
                    $this->session->set_userdata($sdata);
                    ?>
                </h3>

                <fieldset>
                    <form class="cmxform" id="formID2"    name="edit_group"  enctype="multipart/form-data" action="<?php echo base_url(); ?>super_admin_group/update/<?php echo $group_details->group_id ?>" method="post">

                        <legend></legend>

                        <div class="form-group col-sm-7">
                            <label class="control-label" for="typeahead">Group Name</label>
                            <div class="controls">
                                <input type="text" data-errormessage-value-missing="Group Name is required!"

                                       class="form-control validate[required]"  id="typeahead"  name="group_name" value="<?php echo $group_details->group_name ?>" >
                                <input type="hidden" class="span6 typeahead" id="typeahead"  name="url_id" value="<?php echo $group_details->url_id ?>" >
                            </div>
                        </div>                   

                        <br/>
                        <br/>

                        <div class="form-group col-sm-7">
                            <label class="control-label" for="typeahead">Group Type </label>
                            <div class="controls">
                                <select id="group_type" name="group_type" onchange="addGroupType(this.value);" style="float:left; " data-errormessage-value-missing="Group type is required!"
                                        class="form-control validate[required]">
                                    <option value="">Select Type</option>
                                    <?php foreach ($group_type as $v_type) { ?>
                                        <option value="<?php echo $v_type->group_type_id; ?>">
                                            <?php echo $v_type->group_type_name; ?>
                                        </option>
                                    <?php } ?>
                                    <option value="other">Other</option>
                                </select>
                            </div>

                            <script>
                                function addGroupType(groupType) {
                                    if (groupType === 'other') {
                                        document.getElementById('other_type').innerHTML = "<input style='float:left;' type='text' data-errormessage-value-missing='Group type is required!' class='form-control validate[required]' id='group_other_type' name='group_other_type' value='' placeholder='Enter Group Other Type' onblur='checkGroupType(this.value);' >";
                                        document.getElementById('message1').innerHTML = "<p style='color:red;'>Group Type Is required</p>";
                                    } else {
                                        document.getElementById('other_type').innerHTML = "";
                                        document.getElementById('message1').innerHTML = "";
                                    }
                                }

                                function checkGroupType(groupOtherType)
                                {
                                    if (groupOtherType !== '') {
                                        document.getElementById('message1').innerHTML = '<p style="color:red;"></p>';
                                    } else if (groupOtherType == '') {
                                        document.getElementById('message1').innerHTML = '<p style="color:red;">Please Enter Group type</p>';
                                    }
                                }

                            </script>

                            <div class="col-sm-7" id="message1"></div>
                            <div class="col-sm-7" id="message2"></div>
                        </div>
                        <div id="other_type" class="form-group col-sm-7"></div>
                        <br/>

                        <div class="form-group col-sm-7">
                            <label   for="group_public_id">Group Invitation Code:</label>
                            <div class="controls">
                                <input type="text" 
                                       data-errormessage-value-missing="Invitation code is required!"
                                       accept=""class="form-control validate[required, custom[groupinvitation],custom[spaceFunction],custom[codeExistence]] text-input"   
                                       name="group_public_id" 
                                       id="group_public_id" 
                                       value="<?php
                                       if (set_value('group_public_id')) {
                                           echo set_value('group_public_id');
                                       } else {
                                           echo$group_details->group_public_id;
                                       }
                                       ?>"   onkeyup="makerequest(this.value, 'res')" />
                                &nbsp;&nbsp;&nbsp;<div id="res"></div>
                                <input type="hidden" id="incode" name='incode' />
                            </div>

                            <script>
                                $(document).ready(function () {
                                    $("#group_public_id").on("keypress keyup keydown blur", function () {
                                        var pass = $(this).val();
                                        checkGroupCode(pass, 'res');
                                    });
                                });
                                function checkGroupCode(given_text, objID)
                                {
                                    //alert(given_text);
                                    var patt = new RegExp(" ");
                                    var res = patt.test(given_text);
                                    if (res) {
//                                      document.getElementById(objID).innerHTML = '<p style="color: red;">space not allowed</p>';
                                    } else {
                                        if (given_text) {
                                            serverPage = '<?php echo base_url(); ?>super_admin_group/check_public_group_code_for_edit/' + given_text;
                                            xmlhttp.open("GET", serverPage);
                                            xmlhttp.onreadystatechange = function ()
                                            {
                                                //alert(xmlhttp.readyState);
                                                //alert(xmlhttp.status);
                                                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                                {
//                                                    alert(xmlhttp.responseText);
                                                    if (xmlhttp.responseText == 1)
                                                    {
                                                        document.getElementById(objID).innerHTML = '<p style="color: red;">Code not Available</p>';
                                                        document.getElementById("incode").setAttribute("value", 0);
                                                    }
                                                    if (xmlhttp.responseText == 2)
                                                    {
                                                        document.getElementById(objID).innerHTML = '<p style="color: green;">Code Available</p>';
                                                        document.getElementById("incode").setAttribute("value", 1);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    xmlhttp.send(null);
                                }
                            </script>
                        </div>
                        <br/>

                        <div class="form-group col-sm-7">
                            <label class="control-label" for="group_url">Group URL:</label>
                            <div class="controls">
                                <input type="text" 
                                       data-errormessage-value-missing="Group url is required!"
                                       class="form-control validate[required,custom[groupurl],custom[spaceFunction],custom[url_group_Existence]] text-input"   
                                       name="group_url" 
                                       id="group_url"
                                       value="<?php
                                       if (set_value('group_url')) {
                                           echo set_value('group_url');
                                       } else {
                                           echo $group_details->url;
                                       }
                                       ?>"/>&nbsp;&nbsp;&nbsp;<div id="res2"></div>
                                <input type="hidden" id="urlcode" name='urlcode' />
                            </div>
                            <script>

                                $(document).ready(function () {
                                    $("#group_url").on("keypress keyup keydown blur", function () {
                                        var url = $(this).val();
                                        checkGroupUrl(url, 'res2');
                                    });
                                });
                                function checkGroupUrl(given_text, objID)
                                {
//                                    alert(given_text);
                                    var patt = new RegExp(" ");
                                    var res = patt.test(given_text);
                                    if (res) {
                                        //    ocument.getElementById(objID).innerHTML = '<p style="color: red;">space not allowed</p>';
                                    } else {
                                        if (given_text) {
                                            serverPage = '<?php echo base_url(); ?>super_admin_group/check_group_url_for_edit/' + given_text;
                                            xmlhttp.open("GET", serverPage);
                                            xmlhttp.onreadystatechange = function ()
                                            {
//                                                alert(xmlhttp.readyState);
//                                                alert(xmlhttp.status);
                                                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                                                {
//                                                    alert(xmlhttp.responseText);
                                                    if (xmlhttp.responseText == 1)
                                                    {
                                                        document.getElementById(objID).innerHTML = '<p style="color: red;">URL not Available</p>';
                                                        document.getElementById("urlcode").setAttribute("value", 0);
                                                    }
                                                    if (xmlhttp.responseText == 2)
                                                    {
                                                        document.getElementById(objID).innerHTML = '<p style="color: green;">URL Available</p>';
                                                        document.getElementById("urlcode").setAttribute("value", 1);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    xmlhttp.send(null);
                                }

                            </script>
                        </div>
                        <br/>

                        <div class="form-group col-sm-12">
                            <label class="control-label " for="textarea2" class="form-control texteditor">Group Description</label>
                            <div class="controls">
                                <textarea name="group_description" class="texteditor col-md-5" id="textarea2" rows="8"><?php echo $group_details->group_description ?></textarea>
                            </div>
                        </div>
                        <br/>

                        <div class="form-group col-sm-7">
                            <button type="submit" class="btn btn-primary" id="sbtn" >Update</button>
                            <button type="reset" class="btn">Cancel</button>
                        </div>
                        <br/>
                        <br/>
                    </form> 
                </fieldset>
            </div>
        </div><!--/span-->

    </div><!--/row-->
</div>

<script type="text/javascript">
    document.forms['edit_group'].elements['group_type'].value = '<?php echo $group_details->group_type_id ?>';
</script>
<!--<script type="text/javascript">
    document.forms['edit_group'].elements['group_size'].value = '<?php // echo $group_details->group_size                             ?>';
</script>-->