var dragapproved=false
var minrestore=0
var initialwidth
var initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
function drag_drop(e) {
	if (ie5 && dragapproved && event.button == 1){
	document.getElementById("divWindow").style.left=tempx+event.clientX-offsetx
	document.getElementById("divWindow").style.top=tempy+event.clientY-offsety
	} else if (ns6 && dragapproved) {
	//tempx = 300;
	document.getElementById("divWindow").style.left=tempx+e.clientX-offsetx
	document.getElementById("divWindow").style.top=tempy+e.clientY-offsety
	}
}
function initializedrag(e) {
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	    tempx=parseInt(document.getElementById("divWindow").style.left)

	tempy=parseInt(document.getElementById("divWindow").style.top)
	dragapproved = true
	document.onmousemove = drag_drop
}

function CloseWindow()
{  
    
    if (document.getElementById('ddlSizes'))
	{
	    document.getElementById('ddlSizes').style.display='block';
	}
   
    var divID = '';
    if(IsCartOpen == 1)
    {       
        divID = 'divWindowOverlap';
    }
    else
    {   
        IsCartOpen = 0;
        if(document.getElementById('srcFile'))
        {       
            iframeContent=document.getElementById('srcFile');
            if(iframeContent==null) 
            {
                
            }
            else
            {
                iframeContent.src=null;
            }
        }
        divID = 'divWindow';
    }
      
    if(document.getElementById('divWindow'))
    {        
        dwincontent=document.getElementById(divID);
	    document.getElementById(divID).style.display='none';
	    if(IsCartOpen == 1)           //Code added by Ashish on 31-07-2007 (to handle Checkout page's UPS dropdown).
	    {
	        if(document.getElementById('divWindow'))
	            document.getElementById('divWindow').style.display='block';
	    }
	    if (EnableDisableSelectionLink)
	    {
	        EnableDisableSelectionLink(true);	 	
	     }
	    return false;
	}	
	
}

if (ie5||ns6)
document.onmouseup=new Function("dragapproved=false;document.onmousemove=null")


var closeWindow = false;

function open_popup(Left, Top, Src, Title, Width, Height,Mode)
{   
    //dwincontent=document.getElementById('divWindow');
	//dwincontent.innerHTML="abcdefg"; // Code is added to refresh the div 	
	
	if (closeWindow)
	    CloseWindow();	
	if(Width==null) {
		var width = 500;
	} else {
		var width = Width;
	}
	if(Height==null) {
		var height = 350;
	} else {
		var height = Height;
	}
	var tempSrc = Src.split("?")
	if(tempSrc.length>1)
	 {	    
	    Src = Src + '&Mode=Login'
	}
	else
	{
	  if(Mode.toUpperCase() == 'LOGIN')
	    Src = Src + '?Mode=Login'
	  else
	      Src = Src + '?Mode=SignUp'
	 }
    height = height - 22;
	if (Mode.toUpperCase()=='SIZECHART'){ IsCartOpen = 0;
	    ContentHTML = "<div id='POPUP'><table border='0' width='"+width+"' border='0' align='left' cellpadding='0' cellspacing='0' bgColor='#F2F2F2'><tr><td bgcolor='#CCCCCC' class='footer' style='text-align:left; padding-left:5px;font-size:12px; font-weight:bold; border-bottom:1px solid #666666 ;'>"+Title+"</td><td  bgcolor='#CCCCCC' class='footer' style='text-align:right; padding:0px;font-size:12px;border-bottom:1px solid #666666;'><img src='Images/closeButton.gif' alt='Close' width='20' height='22' align='right' onClick=CloseWindow()></td></tr><tr><td colspan=2><iframe scrolling='auto' frameborder=0 id='srcFile' name='srcFile' src='"+Src+"' width='"+width+"' height='"+height+"' allowtransparency='true' hspace='0' vspace='0' scrolling='auto' marginheight='0' marginwidth='0'></iframe></td></tr></table></div>"	    
	}else{
	    width = width -5;
	    if (Mode.toUpperCase()=='VIEWCART')
	    {
	        IsCartOpen = 1;
	        ContentHTML = "<div id='POPUP'><table border='0' width='"+width+"' border='0' align='left' cellpadding='0' cellspacing='0' bgColor='#F2F2F2'><tr><td bgcolor='#CCCCCC' class='footer' style='text-align:left; padding-left:5px;font-size:12px; font-weight:bold; border-bottom:1px solid #666666 ;'>"+Title+"</td><td  bgcolor='#CCCCCC' class='footer' style='text-align:right; padding:0px;font-size:12px;border-bottom:1px solid #666666;'  height='22'>&nbsp;</td></tr><tr><td colspan=2><iframe scrolling='Yes' frameborder=0 id='srcFile' name='srcFile' src='"+Src+"' width='"+width+"' height='"+height+"' allowtransparency='true' hspace='0' vspace='0' scrolling='auto' marginheight='0' marginwidth='0'></iframe></td></tr></table></div>"	        	               
	    }
	    else
	    {		         
	        ContentHTML = "<div id='POPUP'><table border='0' width='"+width+"' border='0' align='left' cellpadding='0' cellspacing='0' bgColor='#F2F2F2'><tr><td bgcolor='#CCCCCC' class='footer' style='text-align:left; padding-left:5px;font-size:12px; font-weight:bold; border-bottom:1px solid #666666 ;'>"+Title+"</td><td  bgcolor='#CCCCCC' class='footer' style='text-align:right; padding:0px;font-size:12px;border-bottom:1px solid #666666;'><img src='Images/closeButton.gif' alt='Close' width='20' height='22' align='right' onClick=CloseWindow()></td></tr><tr><td colspan=2><iframe scrolling='Yes' frameborder=0 id='srcFile' name='srcFile' src='"+Src+"' width='"+width+"' height='"+height+"' allowtransparency='true' hspace='0' vspace='0' scrolling='auto' marginheight='0' marginwidth='0'></iframe></td></tr></table></div>"
	    }    
    }	
	//set the dhtml popup in center of visible screen
	if(IsCartOpen == 1 && ((Mode.toUpperCase() == 'LOGIN') ||(Mode.toUpperCase() == 'SIGNUP')))
	{	   
	    dwincontent=document.getElementById('divWindowOverlap');
	    //window.parent.document.getElementById('divWindow').style.display='none';    //Code added by Ashish on 31-07-2007 (to handle Checkout page's UPS dropdown).
	    document.getElementById('divWindow').style.display='none';
	}
	else
	{		 
	     dwincontent=document.getElementById('divWindow');
	}
	    	
	dwincontent.innerHTML=ContentHTML;
	dwincontent.style.display='block';
	    if(Left=="center") {
		    var getScrnWidth = screen.width;
		    if(ie5)
		        dwincontent.style.left = (screen.width - Width)/2 - 8;
		     else
		         dwincontent.style.left = (screen.width - Width)/2 ;
	    } else {
		    dwincontent.style.left=Left;
	    }
	    if(Top=="center") {
		    var getScrnHeight = screen.height;		
		    dwincontent.style.top = getScrnHeight/2  - 305;
	    } else {
		    dwincontent.style.top = Top;
	    }
	
	bWindowOpened = true;
	closeWindow = true;
	
	/* */
	if (document.getElementById('ddlSizes'))
	{
	    document.getElementById('ddlSizes').style.display='none';
	}
	
}	

function hideLoader() {
	document.getElementById('IFrame').style.display = 'block';
	document.getElementById('Loader').style.display = 'none';
}