﻿// JScript File

	 
var urlobj;
var hidurl
var value;
function BrowseServer(ElementID,imgurl, val)
{
    urlobj = ElementID;
    hidurl = imgurl;
    value = val;
    OpenServerBrowser(
            '../fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/aspx/connector.aspx',
            screen.width * 0.7,
            screen.height * 0.7 ) ;
}

function OpenServerBrowser( url, width, height )
{
    var iLeft = (screen.width  - width) / 2 ;
    var iTop  = (screen.height - height) / 2 ;
    var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
    sOptions += ",width=" + width ;
    sOptions += ",height=" + height ;
    sOptions += ",left=" + iLeft ;
    sOptions += ",top=" + iTop ;
    var oCommand = new FCKDialogCommand( 'ImageButton', 'FCKLang.ImageButton'	, '../fckeditor/editor/dialog/fck_image.html?ImageButton', 450, 400 ) ;
    //var oWindow = window.open( '../fckeditor/editor/dialog/fck_image.html?ImageButton',450,400 ) ;
}

function SetUrl( url, width, height, alt )
{
    var imagewidth,imageheight;
    var img = new Image();
    img.src = url;
    if(img.width > 0)
    {
    if(img.width > img.height)
     {
      if(img.width > value)
      {
         imagewidth=value;
         value = value == 0 ? 0 : Math.round( img.height * ( value  / img.width ) )
         imageheight=value;
       }
       else
       {
        imagewidth=img.width;
        imageheight=img.height;
       }
       
     }
     else
     {
      if(img.height > value)
      {
         imageheight=value;
         value = value == 0 ? 0 : Math.round( img.width * ( value  / img.height ) )
         imagewidth=value;
       }
       else
       {
        imagewidth=img.width;
        imageheight=img.height;
       }
     }
     
    document.getElementById(urlobj).style.display="";
    document.getElementById(urlobj).src = url ;
    document.getElementById(hidurl).value = url ;
    document.getElementById(urlobj).width  = imagewidth ;
    document.getElementById(urlobj).height  = imageheight ;
    oWindow = null;
    }
    else
    {
      SetUrl( url, width, height, alt );
    }
}

function  Imz_Resize(Simg,imagesize)
{
 if ( Simg!=null) 
  { 
    img=new Image();
	img.src=Simg.src;	   
	if(img.width > img.height)
     {
      if(img.width > imagesize)
      {
         imagewidth=imagesize;
         imagesize = imagesize == 0 ? 0 : Math.round( img.height * ( imagesize  / img.width ) )
         imageheight=imagesize;
       }
       else
       {
        imagewidth=img.width;
        imageheight=img.height;
       }
       
     }
     else
     {
      if(img.height > imagesize)
      {
         imageheight=imagesize;
         imagesize = imagesize == 0 ? 0 : Math.round( img.width * ( imagesize  / img.height ) )
         imagewidth=imagesize;
       }
       else
       {
        imagewidth=img.width;
        imageheight=img.height;
       }
     }	

	Simg.height = imageheight;
	Simg.width=  imagewidth;
	Simg.style.display = "";				    
   }
}

 function seterrorimage(img)
{
      var id = img.id;
      var _img = new Image();
      _img.src = "Images/NoImage.jpg";
      if(_img.width > 0)
      {
           document.getElementById(id).src=_img.src;
        }
       else
         return false;    
    }


