﻿ function noPostBack(sNewFormAction){                
    // Assign form action attribute, disable viewstate (allows form POST to classic asp)
    sNewFormAction='/CheckLogin.asp';
                
    document.forms[0].action = sNewFormAction;
    document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';       
}


// Window centering
$(window).resize(function(){
    $('#popUp').css({
	    position:'absolute',
	    left: ($(window).width() - $('#popUp').outerWidth())/2,
	    top: ($(window).height() - $('#popUp').outerHeight())/2
    });
});


// Documentation/Link Popups
function basicPopup(url) {
    popupWindow = window.open(url, 'Resource data management documentation','height=800,width=600,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
}

function linkPopUp(url) {
    window.open(url, 'Link', 'height=1200,width=1024,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
}


// Styled pop displayed "in-page"
// Set popup status
//0 disabled 1 enabled
var popupStatus = 0;

// Load popup
function loadPopup(){	
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$(".popupContent").fadeIn("slow");
		popupStatus = 1;
		
		// Set focus
		if($("#ctl00_USERID").val() == ""){
            $("#ctl00_USERID").focus();        
		}
		else
		    $("#ctl00_PASSWORD").focus();		
	}
}

function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$(".popupContent").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".popupContent").height();
	var popupWidth = $(".popupContent").width();
    var vertScroll = 0; // set initial vertscroll value
    
    // Check browser type to determine offset:
    // Need to update the popup position in relation to the vertscroll
    if(typeof(window.pageYOffset) == 'number') {
        //Netscape compliant
        vertScroll = window.pageYOffset;    
    }
        else if(document.body && document.body.scrollTop) 
    {
        //DOM compliant
        vertScroll = document.body.scrollTop;    
    } else if(document.documentElement && document.documentElement.scrollTop) {
        //IE6 standards compliant mode
        vertScroll = document.documentElement.scrollTop;
    }
                
    // Define constant distance from viewport "top"
    var seperator = 25; 
    var zindex = "10000";

    // Center popup relative to viewport
	$(".popupContent").css({
		"z-index": zindex,
		"position": "absolute",		
		"top": seperator + vertScroll,	
		"left": windowWidth/2-popupWidth/2
	});
	
	//only need force for IE6 here	
	$("#backgroundPopup").css({
		"height": windowHeight
	});	    	
}

function setPopUpContents(productNumber, productName){        
    // Display content       
    if(productNumber == 'login'){
        // login panel
        $(".popupContent").height(300);
        $(".popupContent").width(300);              
        //$("#popUpImage").html("<span id='ctl00_userNameLbl'><strong>Username</strong></span><input id='ctl00_USERID' type='text' name='ctl00$USERID'><span id='ctl00_passwordLbl'><strong>Password</strong></span><input id='ctl00_PASSWORD' type='password' name='ctl00$PASSWORD' /><input id=\"ctl00_loginBtn\" class=\"submitBtn\" type=\"submit\" title=\"Click here to login to the RDM client area.\" onclick=\"noPostBack('CheckLogin.asp')\">");
        $("#popUpImage").html("<div id='loginPanel'><div class='clear'></div><div class='loginField'><span id='ctl00_userNameLbl'><strong>Username:</strong></span><input id='ctl00_USERID' type='text' name='ctl00$USERID' size='16'/></div><div class='clear'></div><div class='loginField'><span id='ctl00_passwordLbl'><strong>Password:</strong></span><input id='ctl00_PASSWORD' type='password' name='ctl00$PASSWORD' size='18' /></div><br /><br /><br /><input id=\"ctl00_loginBtn\" class=\"submitBtn\" type=\"submit\" title=\"Click here to login to the RDM client area.\" onclick=\"noPostBack('CheckLogin.asp')\"><div class='clear'></div></div>");
        				
		//center login panel, load popup
		$(window).resize(); 
		loadPopup();
    }
    else {
        // Image panel                
        $(".popupContent").height(770);
        $(".popupContent").width(600);   
        $("#popUpImage").html("<img src='DisplayProductImage.aspx?ProductNumber="+productNumber+"&ImageSize=large' alt='RDM image viewer' /><div class='clear'></div><center><p class='popUpInfo'>Product number: "+productNumber+"</p><p class='popUpInfo'>\""+productName+"\"</p></center>");
        
        //center image panel, load popup
		centerPopup();
		loadPopup();
    }
}
 


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP	
	/*$(".popUpClickArea").click(function(){
		//centering with css
		//centerPopup(); // need to call this method on mouse scroll 		
		$(window).resize(); 
						
		//load popup
		loadPopup();
	});*/
				
	//CLOSING POPUP "x"	
	$(".popupContentClose").click(function(){
		disablePopup();
	});
	//Click outside image area
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Escape key event
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});

