﻿    $(document).ready(function() {
        $('#frmUserPhoto').ajaxForm(function(resp){
            if($.validate()){
                var data = JSON.parse(resp);
                if(data.msg.substring(0,1)!=' '){
                    alert(data.msg);
                    location.href='Fotograflarim';
                }else{
                    alert(data.msg);
                }
            }
        });
        $('#frmFotografOnayUpdate').ajaxForm(function(resp){
            debugger;
            //if($.validate()){
                var data = JSON.parse(resp);
                if(data.msg.substring(0,1)!=' '){
                    alert(data.msg);
                    //location.href='Fotograflarim';
                }else{
                    alert(data.msg);
                }
            //}
        });
        $('#frmFotografOnayApprovedStatusChange').ajaxForm(function(resp){
            debugger;
            //if($.validate()){
                var data = JSON.parse(resp);
                if(data.msg.substring(0,1)!=' '){
                    alert(data.msg);
                    location.reload();
                }else{
                    alert(data.msg);
                }
            //}
        });
        
        if(document.getElementById('imgLogo')!=null){
            var dh=120;
            if(document.getElementById('imgLogo').height>dh){
                var w=dh*document.getElementById('imgLogo').width/document.getElementById('imgLogo').height;
                
                document.getElementById('imgLogo').setAttribute('height',dh);
                document.getElementById('imgLogo').setAttribute('width',w);
            }
        }
    });

    function ValidateFotografEkle(){
        Validate = true;

        if($('#UserPhotoID')[0].value.length==0)
        {
            $('#fileResim')[0].className='';
            $('#fileResimErrMsg')[0].className='validationErrMsg';
            if($('#fileResim')[0].value==''){
                $('#fileResim')[0].className='validationError';
                $('#fileResimErrMsg')[0].innerHTML='<b>Fotoğraf Yükleyin</b> alanı boş bırakılamaz';
                $('#fileResimErrMsg')[0].className='validationErrMsgShow';
                Validate=false;
            }
        }
        
        return Validate;
    }
    
    function FotografSil()
    {
        if($('#UserPhotoID')[0].value!='0'){
            $('#frmUserPhoto')[0].action='userphotodelete.set';
            $('#frmUserPhoto').submit();        
        }else{
            alert('Fotoğraf seçin');
        }
    }
    
    function FotografDuzenle()
    {
        if($('#UserPhotoID')[0].value!='0'){
            location.href='FotografEkle?UserPhotoID='+$('#UserPhotoID')[0].value;
        }else{
            alert('Fotoğraf seçin');
        }
    }
    
    function FotografPopup(pnum)
    {
        //alert(p);
        //FotografDetay?psize=1&pnum=1
        //myWindow = window.open("FotografDetay?UserPhotoID=" + UserPhotoID, "FotografDetay", 'width=566,height=680');
        //myWindow = window.open("FotografDetay?psize=1&pnum=" + pnum, "FotografDetay", 'width=566,height=680');
        myWindow = window.open("FotografDetay?psize=1&pnum=" + pnum, "FotografDetay", 'width=630,height=755,scroll bars=no');
        myWindow.focus();
    }
    
    function FotografPopupKobiOzel(UserID,UserPhotoID,RowID)
    {
        //alert('FotografPopupKobiOzel');
        //FotografDetay?psize=1&pnum=1
        //myWindow = window.open("FotografDetay?UserPhotoID=" + UserPhotoID, "FotografDetay", 'width=566,height=680');
        //alert("FotografDetay?psize=1&pnum=1&UserID="+UserID+"&UserPhotoID="+UserPhotoID);
        //myWindow = window.open("FotografDetay?psize=1&pnum=1&UserID="+UserID+"&UserPhotoID="+UserPhotoID, "FotografDetay", 'width=566,height=680');
        if(document.getElementById('KobiPageType')==null 
            || document.getElementById('KobiPageType').value=='KobiOzel'){
            myWindow = window.open("FotografDetay?psize=1&pnum="+RowID+"&UserID="+UserID, "FotografDetay", 'width=630,height=755,scroll bars=no');
        }else{
            myWindow = window.open("FotografDetay?psize=1&pnum="+RowID+"&UserID="+UserID, "FotografDetay", 'width=630,height=755,scroll bars=no');
        }
        myWindow.focus();
    }
    
    //Admin
    function FotografListUpdate(UserPhotoID,Mode){
        if(Mode==0){
            $('#divTitle_1_'+UserPhotoID)[0].style.display='block';
            $('#divTitle_2_'+UserPhotoID)[0].style.display='none';

            $('#divDescription_1_'+UserPhotoID)[0].style.display='block';
            $('#divDescription_2_'+UserPhotoID)[0].style.display='none';

            //$('#divApprovedStatus_1_'+UserPhotoID)[0].style.display='block';
            //$('#divApprovedStatus_2_'+UserPhotoID)[0].style.display='none';

            $('#divProcess_1_'+UserPhotoID)[0].style.display='block';
            $('#divProcess_2_'+UserPhotoID)[0].style.display='none';
        }else{
            $('#divTitle_1_'+UserPhotoID)[0].style.display='none';
            $('#divTitle_2_'+UserPhotoID)[0].style.display='block';

            $('#divDescription_1_'+UserPhotoID)[0].style.display='none';
            $('#divDescription_2_'+UserPhotoID)[0].style.display='block';

            //$('#divApprovedStatus_1_'+UserPhotoID)[0].style.display='none';
            //$('#divApprovedStatus_2_'+UserPhotoID)[0].style.display='block';

            $('#divProcess_1_'+UserPhotoID)[0].style.display='none';
            $('#divProcess_2_'+UserPhotoID)[0].style.display='block';
        }
    }

    function FotografUpdateAdmin(UserPhotoID){
        //debugger;
        //alert('FotografUpdateAdmin'+UserPhotoID);
        if($('#UserPhotoID')[0].value.length>0){
            FotografListUpdate($('#UserPhotoID')[0].value,0);
        }

        FotografListUpdate(UserPhotoID,1);
        $('#UserPhotoID')[0].value=UserPhotoID;
    }
    function FotografCancelAdmin(UserPhotoID){
        //debugger;
        //alert('FotografCancelAdmin'+UserPhotoID);
        FotografListUpdate(UserPhotoID,0);
        $('#UserPhotoID')[0].value='';

        $('#txtTitle_'+UserPhotoID)[0].value=$('#divTitle_1_'+UserPhotoID)[0].innerHTML;
        $('#txtDescription_'+UserPhotoID)[0].value=$('#divDescription_1_'+UserPhotoID)[0].innerHTML;
    }
    function FotografSaveAdmin(UserPhotoID){
        //debugger;
        //alert('FotografSaveAdmin'+UserPhotoID);
        FotografListUpdate(UserPhotoID,0);
        $('#UserPhotoID')[0].value='';

        $('#divTitle_1_'+UserPhotoID)[0].innerHTML=$('#txtTitle_'+UserPhotoID)[0].value;
        $('#divDescription_1_'+UserPhotoID)[0].innerHTML=$('#txtDescription_'+UserPhotoID)[0].value;

        $('#valUserPhotoID')[0].value=UserPhotoID;
        $('#valTitle')[0].value=$('#txtTitle_'+UserPhotoID)[0].value;
        $('#valDescription')[0].value=$('#txtDescription_'+UserPhotoID)[0].value;
        //$('#valApprovedStatus')[0].value=$('#txtTitle_'+UserPhotoID)[0].value;
        $('#valApprovedDecription')[0].value=$('#txtApprovedDecription_'+UserPhotoID)[0].value;
    }

    function ChangeApprovedDecription(UserPhotoID,IsShow){
        //alert(UserPhotoID+'_'+IsShow);
        if(IsShow==true){
            $('#txtApprovedDecription_'+UserPhotoID)[0].style.display='block';
        }else{
            $('#txtApprovedDecription_'+UserPhotoID)[0].style.display='none';
        }
    }
    //Fotograf
    function FotograflarPageNext(UserID){
        var PageNum=1;
        if(document.getElementById('UserPhoto_PageNum')!=null){
            PageNum=parseInt(document.getElementById('UserPhoto_PageNum').value)+1;
            document.getElementById('UserPhoto_PageNum').value=PageNum;
            FotografSetPage(UserID,PageNum);
        }
    }
    function FotograflarPagePre(UserID){
        var PageNum=1;
        if(document.getElementById('UserPhoto_PageNum')!=null){
            PageNum=parseInt(document.getElementById('UserPhoto_PageNum').value)-1;
            document.getElementById('UserPhoto_PageNum').value=PageNum;
            FotografSetPage(UserID,PageNum);
        }
    }
    function FotografSetPage(UserID,PageNum){
        if(PageNum==1){
            document.getElementById('UserPhotoPre').style.display='none';            
        }else{
            document.getElementById('UserPhotoPre').style.display='block';            
        }

        if(document.getElementById('KobiPageType').value=='KobiOzel'){xurl='NextPhotoList.get';}else{xurl='NextPhotoList.get';}
        $.post(xurl+'?UserID='+UserID+'&PageNum='+PageNum,function(resp){
            var data = JSON.parse(resp);
            if(data.count>0)
            {
                for(i=1;i<6;i++)
                {
                    //alert('uyeOzelFoto_'+i);
                    document.getElementById('uyeOzelFoto_'+i).innerHTML='';
                }
                //debugger;
                for(i=0;i<data.count;i++)
                {
                    var i2=i+1;
                    //alert('uyeOzelFoto_'+i2);
                    if(document.getElementById('KobiPageType').value=='KobiOzel'){
                        document.getElementById('uyeOzelFoto_'+i2).innerHTML='<img src="/NewsImages/'+data.rows[i]["Photo"]+'" onclick="FotografPopupKobiOzel(\''+data.rows[i]["UserID"]+'\',\''+data.rows[i]["UserPhotoID"]+'\',\''+data.rows[i]["RowNum"]+'\');" style="cursor:pointer;" border="0" height="100" width="150" /><div class="clear"></div><a href="#"><strong>'+data.rows[i]["Title"]+'</strong></a>';
                    }else{
                        document.getElementById('uyeOzelFoto_'+i2).innerHTML='<img src="/NewsImages/'+data.rows[i]["Photo"]+'" onclick="FotografPopupKobiOzel(\''+data.rows[i]["UserID"]+'\',\''+data.rows[i]["UserPhotoID"]+'\',\''+data.rows[i]["RowNum"]+'\');" style="cursor:pointer;" border="0" height="100" width="150" /><div class="clear"></div><a href="#"><strong>'+data.rows[i]["Title"]+'</strong></a>';
                    }
                }
                
                var Total=5;
                Total=parseInt(data.rows[0]["Total"]);
                var PageCount1=Total/5;
                var PageCount=parseInt(PageCount1);
                if(PageCount<PageCount1){PageCount++;}
                
                if(PageNum==PageCount){
                    document.getElementById('UserPhotoNext').style.display='none';            
                }else{
                    document.getElementById('UserPhotoNext').style.display='block';            
                }
            }
        }); 

    }
    function ResimOnizleme(path){
        //path=path.replace('\\','/');
        //alert(path);
        //document.getElementById('imgKobiLogo').src=path;
        //debugger;
        var src="file:///"+path.replace(/\\/g,"/");
        $('#imgLogo')[0].src=src;
        //document.getElementById('imgKobiLogo').src='d/i/btn_gonder_turuncu.gif';
        //document.getElementById('imgKobiLogo').src='C:\Documents and Settings\ipoyraz\Belgelerim\Resimlerim\DeleteBin.gif';
        //document.getelementById('divKobiLogo').innerHTML='<img id="imgKobiLogo" src="'+path+'" />';

        if($('#imgLogo')[0].clientHeight>$('#imgLogo')[0].clientWidth){
            if($('#imgLogo')[0].clientHeight>120){
                $('#banaOzelFotoPre')[0].innerHTML='<img src="'+src+'" id="imgLogo" height="120" />';
            }
        }else{
            if($('#imgLogo')[0].clientWidth>276){
                $('#banaOzelFotoPre')[0].innerHTML='<img src="'+src+'" id="imgLogo" width="276" />';
            }
        }
    }
    function AdminSetPage(pnum,sort){
        document.getElementById('frmFotografOnay').action='?psize=10&pnum='+pnum+'&sort='+sort;
        document.getElementById('frmFotografOnay').submit();
    }
