var xmlHttp = null;

var rsh;



function GetXmlHttpObject(Response){



    var objXmlHttp = null;



    if (navigator.userAgent.indexOf("Opera") >=0 ) {

        alert ("المتصفح Opera لا يدعم هذه التقنية ");

        return

    }else if(navigator.userAgent.indexOf("MSIE")>=0){

        var objName = "Msxml2.XMLHTTP" ;

        if (navigator.appVersion.indexOf("MSIE 5.5") >=0){

           var objName = "Microsoft.XMLHTTP" ;



        }

        try{

            objXmlHttp = new ActiveXObject(objName);

            objXmlHttp.onreadystatechange = Response;

            return objXmlHttp;

        }catch (e){

            alert(e.message + '\n' +"خطأ : من المحتمل ان تكون ActivX معطله لديك");

        }



    }else if(navigator.userAgent.indexOf("Mozilla")){

        objXmlHttp = new XMLHttpRequest();

        objXmlHttp.onload = Response;

        objXmlHttp.onerror = Response;

        return objXmlHttp;

    }



}



function get_comment(id){

         try{



         document.getElementById('imgr').style.visibility = "visible";

         document.getElementById('caption').innerHTML = '';

         document.getElementById('caption').innerHTML = 'جار معالجة الطلب...';

         xmlHttp = GetXmlHttpObject(Responsecomment);

         xmlHttp.open('POST','fawaz_ajax/getalbum.php' ,true);

         Link = "?action=get&type=comment&id="+id;

         xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");

         xmlHttp.setRequestHeader("Content-length", Link.length);

         xmlHttp.setRequestHeader("Connection", "close");

         xmlHttp.send(Link);
         
         }catch (e) {alert(e.description);}

}



// execute command
function Responsecomment () {
 if (xmlHttp.readystate == 4 ){
        try{

            //document.getElementById('fawaz').style.visibility = "visible";

            //frm.cost.disabled = true;

            document.getElementById('imgr').style.visibility = "hidden";
            document.getElementById('caption').innerHTML = '';

            document.getElementById('viewr').innerHTML = '';
            document.getElementById('viewr').innerHTML = xmlHttp.responseText;


        }catch (e) {alert(e.message)};
  }
}


function Response () {



 if (xmlHttp.readystate == 4 ){

 

        try{

            //document.getElementById('fawaz').style.visibility = "visible";

            //frm.cost.disabled = true;

            document.getElementById('imgr').style.visibility = "hidden";

            document.getElementById('caption').innerHTML = '';

            

             document.getElementById('viewr').innerHTML = '';

            document.getElementById('viewr').innerHTML = xmlHttp.responseText;

            

        }catch (e) {alert(e.message)};

    }

}



//get all image from album

//----------------------------------------------------------------------------------------------

var image_file = new Image(); //this is temp variable , to load images in it;

var i = 0;

var imagesName  = null;



function Get_Album(start){

   try{





         document.getElementById('imgr').style.visibility = "visible";

         document.getElementById('caption').innerHTML = '';

         document.getElementById('caption').innerHTML = 'جار معالجة الطلب...';

         

         //set reSize image in firest load



         

         xmlHttp = GetXmlHttpObject(Response);

         xmlHttp.open('POST','fawaz_ajax/getalbum.php' ,true);

         Link = "?action=get&type=thumb&start="+start;

         xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=windows-1256");

         xmlHttp.setRequestHeader("Content-length", Link.length);

         xmlHttp.setRequestHeader("Connection", "close");



         xmlHttp.send(Link);

         

         //imagepath  =   document.image_viewr.src;

         }catch (e) {alert(e.description);}

}



function Loading_images() {

try {



   (image_file.complete) ? disp_images() : setTimeout('Loading_images()',100);

   

}catch (e) {alert(e.description);}





//alert (image_file.complete);

}

function checkload(){

//(images[index].complete)? dispbars() : setTimeout('checkload('+index+')', 100);

  alert ('end');



}



//put image themp to bige view



function put_img_to_view(url_pah,id,a_date) {



     // set default image to load

     with (document.image_viewr){
                height = 16;
                width = 16;
                src = null;
                align="center";
                src = 'fawaz_ajax/img/indicator_arrows.gif';
     }

     document.getElementById('caption').style.visibility = 'visible';
     document.getElementById('caption').innerHTML = 'يتم تحميل الصورة الآن.....';

     
     image_file.src = 'globalimages/album/bimg/' + url_pah
     imagesName =  url_pah ;

     Loading_images();

     //End Default;



      id_comment.value = parseInt(id); // set image id to now the current image display

      //document.getElementById('create_date').innerHTML = a_date;

}

function disp_images (){

try {

     path = 'globalimages/album/bimg/';

     

     if (typeof document.image_viewr == 'undefined')

         alert ('يبدو ان هناك مشكلة , لم يتم تحديد موضع العرض, الرجاء التواصل مع مبرمج الموقع لحل المشكلة');

     else {

           document.getElementById('caption').innerHTML = '';
           document.image_viewr.src = null;
           document.image_viewr.src = image_file.src;

           (document.image_viewr.complete) ? reSize() : setTimeout('disp_images()',100);



     }

   }catch (e) {alert(e.description);}

}

//----------------------------------------------------------------------------------------------



function reSize() {


           document.image_viewr.width = "413";
           document.image_viewr.height ="293";
           document.getElementById('caption').style.visibility = 'visible';

           document.getElementById('caption').innerHTML = '';

           image_file.src = null;



}



function check(frm){

 try{

                if (frm.name.value.length < 2){

                        alert ('الرجاء ادخال اسمك بشكل صحيح');

                        frm.name.focus();

                }else if (frm.country.value.length < 2){

                        alert ('الرجاء ادخال اسم البلد بشكل صحيح');

                        frm.country.focus();

                }else if (frm.comment.value.length < 4){

                        alert ('التعليق صغير جدا  لا يمكن قبوله , الرجاء وضع تعليق صحيح');

                        frm.comment.focus();

                }else{



                         Link = "country=" + frm.country.value + "&name=" + frm.name.value + "&comment=" + frm.comment.value + "&id=" + frm.idv.value + '&current='+frm.current.value;
                         document.getElementById('imgr').style.visibility = "visible";

                         document.getElementById('caption').innerHTML = '';

                         document.getElementById('caption').innerHTML = 'يتم الأن اضافة تعليقك الرجاء الإنتضار.....';

                         

                         Link = "?action=get&type=save&" + Link;

                         xmlHttp = GetXmlHttpObject(Response);

                         xmlHttp.open('POST','fawaz_ajax/getalbum.php'+ Link ,true);

                         xmlHttp.send(null);

                         

                }

         }catch (e) {alert(e.description);}



}



var AutoClose = true;



PositionX = 100;

PositionY = 100;



defaultWidth  = 150;

defaultHeight = 100;



if (parseInt(navigator.appVersion.charAt(0))<=4){

        var isNN=(navigator.appName=="Netscape")?1:0;

        var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;

}



var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;

var optIE='scrollbars=no,width=150,height=100';







function popImage(imageURL,imageTitle){



         if (isNN){imgWin=window.open('about:blank','',optNN);}

         if (isIE){imgWin=window.open('about:blank','',optIE);}

                with (imgWin.document){

                        writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');

                        writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');

                        writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');

                        writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');

                        writeln('width=300-(document.body.clientWidth-document.images[0].width);');

                        writeln('height=300-(document.body.clientHeight-document.images[0].height);');

                        writeln('window.resizeTo(width,height);}');writeln('if (isNN){');

                        writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');

                        writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');

                        if (!AutoClose)

                                 writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')

                        else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');

                        writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');

                        close();

                }

        }

