

var browserMessage="";

function rightClickIE() {if (document.all) {(browserMessage);return false;}}
function rightClickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(browserMessage);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=rightClickNS;}
else{document.onmouseup=rightClickNS;document.oncontextmenu=rightClickIE;}

document.oncontextmenu=new Function("return false")


function clickLink(id)
{
    id = '#' + id;
    $(id).click();
}

function loadCSS(filePath) {
    var headtg = document.getElementsByTagName('head')[0];
    if (!headtg) {
        return;
    }
    
    var linktg = document.createElement('link');
    linktg.type = 'text/css';
    linktg.rel = 'stylesheet';
    linktg.href = filePath;
    headtg.appendChild(linktg);
}

function InsertImageCallBackFunction(radWindow, returnValue)
{
	var oHidden = document.getElementById(InsertImagePositionID);
	oHidden.value = returnValue;
	__doPostBack('MyGallery$GalleryMenu','MyGallery:GalleryMenu:m9');
}

//This function is called by the DetailViewGallery
//It ensures that if we delete the current image, the main image is desplayed
function DeleteDetailViewImage()
{
	var oCurImage = document.getElementById("ImageID");
	var oMainImage = document.getElementById("MainImageID");
	var oSelectedImage = document.getElementById(SelectedImageID);
	
	if( oCurImage != null && oMainImage != null && oSelectedImage.value == oCurImage.value )
	{
	    oCurImage.value = oMainImage.value;
	}	

    __doPostBack('MyGallery$GalleryMenu','MyGallery:GalleryMenu:m2');
}
   
function DeleteImage()
{
	if(confirm("Delete image?"))
	{
	     __doPostBack('MyGallery$GalleryMenu','MyGallery:GalleryMenu:m2');
    }
}


function EditImageClick(imageID)
{
	var oSelectedImage = document.getElementById(SelectedImageID);
	oSelectedImage.value = imageID;

	if( IsEditMode == "True" )
		__doPostBack('MyGallery$GalleryMenu','MyGallery:GalleryMenu:m1');
	else
	{
		var btn = document.getElementById(btnSelectID);
		btn.click();
	}
}
             
function SetupGalleryMenu()
{
	document.oncontextmenu = null;
}

function DetailImageClick(imageID)
{
    var oHidden = document.getElementById( 'ImageID' );
	oHidden.value = imageID;

	var forms = document.getElementsByTagName('form');
	forms[0].submit();
}

function enableItem(menu, itemName, enable)
{
    var item = menu.FindItemByValue(itemName);
    
    if( enable )
        item.Enable();
    else
        item.Disable();
}

function OpenContextMenu(isMainImage, position, imageID, clickedElement, e)
{    
   var oSelectedImage = document.getElementById(SelectedImageID);
   oSelectedImage.value = imageID;
   var OldContextHandler = document.oncontextmenu;
   document.oncontextmenu = null;
   
   var menu = MenuInstance;

   enableItem(menu, 'Delete', !isMainImage);
   enableItem(menu, 'ShiftLeft', !isMainImage);
   enableItem(menu, 'ShiftRight', !isMainImage);
   enableItem(menu, 'MoveFirst', !isMainImage);
   enableItem(menu, 'MoveLast', !isMainImage);

   menu.Show(e);

   document.oncontextmenu = OldContextHandler;

   if( e )
   {
	  e.cancelBubble = true;
	
	  if (e.stopPropagation)
      {
	  	  e.stopPropagation();
      }
   }
}   


function GalleryMenu_ClientClick(sender, e)
{       
	if (e.Item && e.Item.Value != null)
    {    
		if (e.Item.Value == "InsertImage")
        {     
			if( e )
			{
				e.cancelBubble = true;
				e.returnValue = false;
				
				if (e.stopPropagation)
				{
	  				e.stopPropagation();
				}
			}
							
		    MenuInstance.Hide();
           
            //Getting RadWindow manager     
            var oManager = GetRadWindowManager();      
                 
            //Success. Getting existing window DialogWindow using GetWindowByName     
            var oWnd = oManager.GetWindowByName("InsertImageWindow");     
            var url = oWnd.GetUrl();
          
            //strip parameters. otherwise we get errors the second time we use it
            if( url.indexOf( '?' ) != -1 )
    			url = url.substring( 0, url.indexOf( '?' ) );

            //Success. Setting a size and a Url to the window using its client API before showing     
            oWnd.SetSize (270, 118);   
            oWnd.SetUrl(url);     
                 
            //Success. Opening window     
            oWnd.Show();  
    	   return false;
        }
     }
}

function GalleryDoNothing()
{
}

function OpenBatchWindow(galleryName, thumbHeight, thumbWidth, mainImageID)
{	

    //Getting RadWindow manager     
    var oManager = GetRadWindowManager();      
   
    //Success. Getting existing window DialogWindow using GetWindowByName     
    var oWnd = oManager.GetWindowByName("BatchUploadWindow");   
    var url = oWnd.GetUrl();
  
    //strip parameters. otherwise we get errors the second time we use it
    if( url.indexOf( '?' ) != -1 )
        url = url.substring( 0, url.indexOf( '?' ) );
    			
    url = url + "?galleryName=" + galleryName + "&thumbHeight=" + thumbHeight + "&thumbWidth=" + thumbWidth + "&mainImageID=" + mainImageID

    //Success. Setting a size and a Url to the window using its client API before showing     
    oWnd.SetSize (460, 330);     
    oWnd.SetUrl(url);     
         
    //Success. Opening window     
    oWnd.Show();  
}

function OpenPositionWindow(imageID, galleryName, mainImageID)
{
    if( mainImageID == '' )
        mainImageID = imageID;
        
    //Getting RadWindow manager     
    var oManager = GetRadWindowManager();      
         
    //Success. Getting existing window DialogWindow using GetWindowByName     
    var oWnd = oManager.GetWindowByName("ChangePositionWindow");      
    var url = oWnd.GetUrl();
    
    //strip parameters. otherwise we get errors the second time we use it
    if( url.indexOf( '?' ) != -1 )
        url = url.substring( 0, url.indexOf( '?' ) );
        
    url = url + "?galleryName=" + galleryName + "&imageID=" + imageID + "&mainImageID=" + mainImageID;

    //Success. Setting a size and a Url to the window using its client API before showing     
    oWnd.SetSize (350, 200);    
    oWnd.SetUrl(url);     
         
    //Success. Opening window     
    oWnd.Show();  
}

function OpenEditTitleWindow(galleryName, mainImageID, isDetailView)
{
    var oSelectedImage = document.getElementById(SelectedImageID);
    var imageID = oSelectedImage.value;
       
    if( mainImageID == '' )
        mainImageID = imageID;
             
    //Getting RadWindow manager     
    var oManager = GetRadWindowManager();      
         
    //Success. Getting existing window DialogWindow using GetWindowByName     
    var oWnd = oManager.GetWindowByName("EditTitleWindow");      
    var url = oWnd.GetUrl();
    
    //strip parameters. otherwise we get errors the second time we use it
    if( url.indexOf( '?' ) != -1 )
        url = url.substring( 0, url.indexOf( '?' ) );
        
    url = url + "?galleryName=" + galleryName + "&imageID=" + imageID + "&mainImageID=" + mainImageID + "&isDetailView=" + isDetailView;

    //Success. Setting a size and a Url to the window using its client API before showing     
    oWnd.SetSize (400, 250);    
    oWnd.SetUrl(url);     
         
    //Success. Opening window     
    oWnd.Show();  
}

function OpenUploadWindow(galleryName, imageID, thumbHeight, thumbWidth, mainImageID)
{
   if( imageID == null )
   {
       var oSelectedImage = document.getElementById(SelectedImageID);
       imageID = oSelectedImage.value;
       
       if( mainImageID == '' ) mainImageID = imageID;
       
       var oMainImage = document.getElementById( 'MainImageID' );
       if( oMainImage != null ) mainImageID.value = mainImageID;
   }
    
    //Getting RadWindow manager     
    var oManager = GetRadWindowManager();      
         
    //Success. Getting existing window DialogWindow using GetWindowByName     
    var oWnd = oManager.GetWindowByName("UploadImageWindow");      
    var url = oWnd.GetUrl();
    
    //strip parameters. otherwise we get errors the second time we use it
    if( url.indexOf( '?' ) != -1 )
        url = url.substring( 0, url.indexOf( '?' ) );
        
    url = url + "?galleryName=" + galleryName + "&imageID=" + imageID + "&thumbHeight=" + thumbHeight + "&thumbWidth=" + thumbWidth + "&mainImageID=" + mainImageID;

    //Success. Setting a size and a Url to the window using its client API before showing     
    oWnd.SetSize (400, 298);    
    oWnd.SetUrl(url);     
         
    //Success. Opening window     
    oWnd.Show();  
}

function UploadImageCallBackFunction(radWindow, returnValue)
{
	radWindow.Close();
	document.getElementsByTagName('form')[0].submit();
}

function GalleryImageRevert(ID)
{
	__doPostBack( ID, 'Revert');
}

function EditArea_DoNothing()
{
}

function GalleryImage_DoNothing()
{
}