<link type="text/css" href="<?php echo SITE_PATH; ?>powerpanel/html/css/photogallery.css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo SITE_PATH; ?>powerpanel/html/js/jquery.dragsort-0.5.1.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script> 

<script type="text/javascript">
    $(document).ready(function(){
        $("#ajaxphotogallery").dragsort({ 
            dragSelector: "div", 
            dragBetween: true, 
            dragEnd: saveOrder, 
            placeHolderTemplate: "<li class='placeHolder'><div class='backdrag'><table><tr><td align='center' valign='middle' width='241' height='255'>Drag Photo</td></tr></table></div></li>" 
        });
        get_video_listing();
        var options = { 
            beforeSubmit:  validate,  // pre-submit callback 
            success:       video_added  // post-submit callback 
        }; 
       
        // bind form using 'ajaxForm' 
        $('#frmprojects').ajaxForm(options); 
    });
     
    function video_added(responseText){
//         alert(responseText);
        var addMsg ="";
        if(responseText == "invalid"){
            addMsg = "Invalid video url.";
        }
        else if(responseText == "success"){
            addMsg = "The record has been successfully saved!";
            $('#frmprojects').resetForm();
           
        }
        else if(responseText == "url_exist"){
            addMsg = "This video is already exist, Please enter another video url.";
        }
        get_video_listing();
        $("#msg").html('<div class="dverrorcustom"><div class="confirmation-div"><strong>'+addMsg+'</strong></div></div>');
        $("#save-video").removeAttr("disabled");
    }
    
    function saveOrder() {
                    
        var dataid = $("#ajaxphotogallery li").map(function() { return $(this).attr('id'); }).get();                    
        
        set_photo_displayorder(dataid);                    
    }
    
    function set_photo_displayorder(photointglcode)
    {
        var url = "<?php echo SITE_PATH; ?>powerpanel/index.php?module=videogallery&action=set_photo_displayorder&photointglcode="+photointglcode;
        $.ajax({
            type: "GET",
            url: encodeURI(url),
            async: true,
            start : ProcessLoader(),
            success: function(data){
                get_video_listing();
                document.getElementById('dvprocessing').style.display = 'none';
            }
        });      
    }
    function get_video_listing()
    {
        var url = "<?php echo SITE_PATH; ?>powerpanel/index.php?module=videogallery&action=video_grid";
        $.ajax({
            type: "GET",
            url: encodeURI(url),
            async: true,
            start : ProcessLoader(),
            success: function(data){
                document.getElementById('ajaxphotogallery').innerHTML = trim(data);
                document.getElementById('dvprocessing').style.display = 'none';
            }
        });
    }
    function primaryvideo(videoID)
    {
        var url = "<?php echo SITE_PATH; ?>powerpanel/index.php?module=videogallery&action=primary&videoID="+videoID;
        $.ajax({
            type: "GET",
            url: encodeURI(url),
            async: true,
            start : ProcessLoader(),
            success: function(data){
                get_video_listing();
                document.getElementById('dvprocessing').style.display = 'none';
            }
        });
        return false;
    }
    function deletealbumphoto(videoID)
    {
        if(confirm("Are you sure you want to delete this video?")){
            var url = "<?php echo SITE_PATH; ?>powerpanel/index.php?module=videogallery&action=delvideo&videoID="+videoID;     
            $.ajax({
                type: "GET",
                url: encodeURI(url),
                async: true,
                start : ProcessLoader(),
                success: function(data){
                    get_video_listing();
                    document.getElementById('dvprocessing').style.display = 'none';
                    alert("Video deleted successfully"); 
                }
            });
        }else{
            return true;
        }
        return false;
    }
    function setpublish_unpublish(videoID,publish)
    {
        var url = "<?php echo SITE_PATH; ?>powerpanel/index.php?module=videogallery&action=set_publish&videoID="+videoID+"&publish="+publish;    
        $.ajax({
            type: "GET",
            url: encodeURI(url),
            async: true,
            start : ProcessLoader(),
            success: function(data){
                get_video_listing();
                document.getElementById('dvprocessing').style.display = 'none';
            }
        });
    }
    function savealbumcaption(videoID)
    {
        if(confirm("Are you sure you want to change the video title?")) {

            var photocaption = trim(document.getElementById('varphotocaption_'+videoID).value);
            var photocaption1 = encodeURIComponent(photocaption);
            var url = "<?php echo SITE_PATH; ?>powerpanel/index.php?module=videogallery&action=savealbumcaption&videoID="+videoID+"&photocaption="+photocaption1;    
            $.ajax({
                type: "GET",
                url: encodeURI(url),
                async: true,
                start : ProcessLoader(),
                success: function(data){
                    get_video_listing();
                    document.getElementById('dvprocessing').style.display = 'none';
                    if(data){
                        alert("Video title has been successfully updated.");
                    }
                }
            });
        }else{
            return true;
        }
        return false;
    }
</script>
<script type="text/javascript">

    function openLinksModel(id)
    { 	
        var response;
        $.ajax({
            type: "GET",
            url:"index.php" ,
            data: "module=videogallery&action=videopopup&videoid="+id,
            async: false,
            success: function(data)
            {
                response=data;
            }

        });
        //alert(response);
        $('#links-modal').html(response);

        $('#links-modal').dialog({
            autoOpen: false,
            height: 470,
            width: 580,
            modal: true
        });
        $('#links-modal').dialog('open');

    }

    function checksameurl()
    { 	
        var eid=$("#hd_intglcode").val();
        var videourl=$('#var_youtubeurl').val();
        $.ajax({
            type: "GET",
            url:"index.php" ,
            data: "module=videogallery&action=checksame&videourl="+videourl+"&eid="+eid,
            async: false,
            success: function(data)
            {
                // alert(data);
                if(data>0)
                {
                    exist=1;
                }
                else
                {
                    exist=0;
                }
            }
        });
    }
    function validateurl(url)
    {
        //    return url.match(/http(s):\/\/(?:www\.)?youtube.*watch\?v=([a-zA-Z0-9\-_]+)/);
        return url.match(/http:\/\/(?:www\.)?youtube.*watch\?v=([a-zA-Z0-9\-_]+)/);
    }
    function validate()
    {
        //checksameurl();
        if(trim(document.getElementById('var_title').value) == "")
        {
            alert("Please enter video title.");
            document.getElementById('var_title').focus();
            return false;
        }
        else if(document.getElementById('var_youtubeurl').value == "")
        {
            alert("Please enter video url.");
            document.getElementById('var_youtubeurl').focus();
            return false;
        }
        /*else if(!validateurl(document.getElementById('var_youtubeurl').value))
        {
            alert("Please enter valid video URL.");
            document.getElementById('var_youtubeurl').focus();
            return false;
        }*/
       
        document.getElementById('h_save').value ='T';
        $("#save-video").attr("disabled","disabled");
        return true;
    }
</script>
<script ype="text/javascript">
    function share(id){
        $.ajax({
            type: "GET",
            url:"index.php" ,
            data: "module=videogallery&action=sharedata&ajax=Y&eid="+id,
            async: false,
            success: function(result){
                //alert(result);
                $( "#modelpopup" ).html(result);
            }
        });
            
        $( "#modelpopup" ).dialog({            
            height:380,
            width:620,
            modal: true,
            buttons:{
                "Cancel": function() {
                    $(this).dialog( "close" );
                },
                "Push": function() {
					
                    var chked = false;
                    $('input:checkbox[name="fb[]"]:checked,input:checkbox[name="tw[]"]:checked').each(function(k,v){
                        chked = true;
                    });
                   
                    if ($('#var_video_title').val()=='')
                    {
                        alert('Please Enter required fields');
                        return false;
                    }
					
                    if(chked){
                        var postdata=$("#frmshareoption").serialize();
                        $.ajax({
                            type: "POST",
                            url:"index.php?module=videogallery&action=sharedata&ajax=Y&eid="+id ,
                            data: postdata,
                            async: false,
                            success: function(result){
//                                                                alert(result);
                                if(trim(result)==1){
                                    alert("Video are pushed successfully.");
                                }else{
                                    alert("Error.. Please try again.");
                                }
                                $( "#modelpopup" ).dialog( "close" );
                                window.location.reload();
                            }
                        });
                    }else{
                        alert(" Please select atleast one page.");
                        return false;
                    }
                }
            }
        });
    }
    function sharemutiple(){
        var chkelements = document.getElementsByName("chkgrow");
        var ids = "";
        var countChecked = 0;
        for(var i = 0; i < chkelements.length; i++){
            if(chkelements.item(i).checked == true){
                countChecked++;
                if(ids != "")
                    ids += ",";
                ids += chkelements.item(i).value;
            }
        }
        if(countChecked == 0){
            alert(" Please select atleast one record to be push.");
            return false;
        }
        // alert(ids);
        share(ids);
    }
</script>
<div id="modelpopup" title="Share on Facebook & Twitter"></div>
<div class="breadcrumbs">
    <a href="index.php">Home</a>&nbsp;>&nbsp;<span class="current">Manage Video Gallery</span> 
</div>

<div id="links-modal" title="Video"></div>

<!--<div class="spacer20"></div>-->
<div id="msg"></div>
<!--<div class="spacer20"></div>-->
<h3 class="add_detail">Videos & Details</h3>
<div class="grid-list-inner-table-text">
    <?php // onSubmit="return validate();" ?>
    <form  name="frmprojects"  id="frmprojects" action="<?= $frmaction ?>" method="post"  enctype="multipart/form-data" >

        <table width="100%" cellspacing="3" cellpadding="3" border="0" class="additional_detail_content">
            <tr>
                <td width="20%" valign="top" align="left" class="add-new-user-text">Video Title: <span>(required)</span> </td>
                <td valign="top" align="left" colspan="3">
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td width="50%">
                                <input type="text" style="float :left; width:376px; " value="" id="var_title" class="date-textarea fl" name="var_title">
                                <div class="fl contact-comment-new position-relative mgl5 mgt10">
                                    <span class="help-icon1"></span>
                                    <div style="width: 430px; height: 30px;" class="contact-hint fl">
                                        The title of the video gives you a basic idea regarding the video.</div>
                                </div>
                            </td>
                        </tr>
                    </table>

                </td>
            </tr>

            <tr>
                <td width="20%" valign="top" align="left" class="add-new-user-text">Video URL: <span>(required)</span></td>
                <td width="754" valign="top" align="left">
                    <input type="text" maxlength="200" value="" id="var_youtubeurl" class="add-new-user-textarea" style="width:376px;" name="var_youtubeurl" tabindex="2">
                    <span style="color:red;" class="add-new-user-text">(Only Youtube Video Url)</span><br>
                    <div style="height:20px;padding-top:10px;"><span>(Eg: http://www.youtube.com/watch?v=9MoKICpeBb8)</span></div>
                </td>
            </tr>

            <tr>
                <td>
                    &nbsp; 
                </td>   
                <td>
                    <input border="0" type="image" hspace="5" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btnsaveande','','html/images//submit-button-blue-hover.gif',1)" src="<?= GLOBAL_ADMIN_IMAGES_PATH ?>/submit-button-blue.gif" alt="save-exit" id="btnsaveande" name="btnsaveande" value="1">
                </td>
            </tr>

            <tr>
                <td colspan="2">
                    <input type="hidden" value="" id="old_video_url" name="old_video_url">
                    <input type="hidden" value="" id="old_video_thumb" name="old_video_thumb">
                    <input type="hidden" value="" id="eid" name="eid">
                    <input type="hidden" value="" id="hd_intglcode" name="hd_intglcode">
                    <input type="hidden" value="T" id="h_save" name="h_save">
                    <input type="hidden" value="" id="filterby" name="filterby">
                    <input type="hidden" name="int_displayorder" value="1" />
                </td>   
            </tr>
        </table>
        <?php // $BottomSubmitButtons ?>
    </form>    
</div>

<div class="spacer20"></div>  
<div class="spacer20"></div>

<div>
    <div><h3 class="fl add_detail">View / Edit Videos</h3></div>
    <div style="padding: 5px;"><span style="font-size:15px; color:#333; " class="mgl10 mgt10"><b>(Note: From here you can edit or update the video title.)</b></span></div>
</div>


<table width="100%" border="0" cellspacing="0" cellpadding="0" class="additional_detail_content" style="padding: 1px;">
    <tr>
        <td width="100%">
            <div>
                <?php if (empty($videoArry)) { ?>
                    <div id="nophoto" style="text-align: center;padding: 10px;">
                        No Video uploaded
                    </div>
                    <?
                    $photogriddisplay = "display:none;";
                } else {
                    $photogriddisplay = "";
                }
                ?>
                <ul id="ajaxphotogallery" class="photo-drag">    
                </ul>
            </div>
        </td>
    </tr>
</table>   