function showLoadingProgress() {
    //create new div
    var newDiv;
    var newBg;    
          
    var dvBG = document.getElementById('divMainBg');
    if (dvBG != null && dvBG != undefined)
        newBg = dvBG;
    else {
        newBg = document.createElement('div');
        newBg.setAttribute('id', 'divMainBg');        
    }
    newBg.className = "bgFilter";
    newBg.innerHTML = "<div class='bgFilter'>&nbsp;</div>";
    newBg.style.display = "inline";

    
    var dv = document.getElementById('divManualProgress');
    if (dv != null)
        newDiv = dv;
    else {
        newDiv = document.createElement('div');
        newDiv.setAttribute('id', 'divManualProgress');
        newDiv.style.textalign = "center";
        newDiv.style.border = "solid 1px #0A3158"
        newDiv.style.backgroundColor = "white"
        newDiv.style.padding = "3px"        
    }

    newDiv.innerHTML = "<img border=\"0\" src=\"progress.gif\" style='padding-left:15px;' alt=\"Loading...\"/><br/><span class='subNormal'>Please wait...</span>";
    newDiv.className = "ajax_progress";
    newDiv.style.display = "inline";

    //scroll(0, 0);   
    var body = document.body;
    var html = body.parentNode;
    var y = body.scrollTop, x = body.scrollLeft, w = body.offsetWidth, h = body.offsetHeight;
    if (y == 0) {
        y = html.scrollTop;
        x = html.scrollLeft;
        w = html.clientWidth;
        h = html.clientHeight;
    }
    if (w > 0)
        x += w / 2 - 50 / 2;
    else
        w = document.body.offsetWidth;

    if (h > 0)
        y += h / 2 - 80 / 2;
    else
        h = document.body.offsetHeight;

    //check x and y again
    if (x == 0)
        x += w / 2 - 50 / 2;
    if (y == 0)
        y += h / 2 - 50 / 2;

    newDiv.style.position = "absolute";    
    if (navigator.appName.indexOf("Netscape") > -1) {
        var iTop = Math.floor(y);
        if (iTop >= 100 && iTop < 200)
            newDiv.style.top = "150px";
        else if (iTop >= 200 && iTop < 300)
            newDiv.style.top = "250px";
        else if (iTop >= 300 && iTop < 400)
            newDiv.style.top = "350px";
        else if (iTop >= 400 && iTop < 500)
            newDiv.style.top = "450px";
        else if (iTop >= 500 && iTop < 600)
            newDiv.style.top = "550px";
        else if (iTop >= 600 && iTop < 700)
            newDiv.style.top = "650px";
        else if (iTop >= 700 && iTop < 800)
            newDiv.style.top = "750px";
        else if (iTop >= 800 && iTop < 900)
            newDiv.style.top = "850px";
        else if (iTop >= 900 && iTop < 1000)
            newDiv.style.top = "950px";
        else if (iTop >= 1000 && iTop < 1100)
            newDiv.style.top = "1050px";
        else 
            newDiv.style.top = iTop;

        var iLeft = Math.floor(x);
        if (iLeft >= 100 && iLeft < 200)
            newDiv.style.left = "150px";
        else if (iLeft >= 200 && iLeft < 300)
            newDiv.style.left = "250px";
        else if (iLeft >= 300 && iLeft < 400)
            newDiv.style.left = "350px";
        else if (iLeft >= 400 && iLeft < 500)
            newDiv.style.left = "450px";        
        else if (iLeft >= 500 && iLeft < 600)
            newDiv.style.left = "550px";
        else if (iLeft >= 600 && iLeft < 700)
            newDiv.style.left = "650px";
        else if (iLeft >= 700 && iLeft < 800)
            newDiv.style.left = "750px";
        else if (iLeft >= 800 && iLeft < 900)
            newDiv.style.left = "850px";
        else if (iLeft >= 900 && iLeft < 1000)
            newDiv.style.left = "950px";
        else
            newDiv.style.left = iLeft;
    }
    else {
        newDiv.style.left = x;
        newDiv.style.top = y;
    }

    newBg.style.position = "absolute";
    newBg.style.top = 0;
    newBg.style.left = 0;    
    newBg.style.height = h + 1000;
    newBg.style.width = w + 1000;

    var frm = document.forms[0];
    if (frm != null) {
        frm.appendChild(newBg);  //to disable the window
        frm.appendChild(newDiv);
        //document.body.style.overflow = "hidden";
        document.documentElement.style.overflow = "hidden";
    }  
}

//manually hide ajax loading progress created by showLoadingProgress
function hideLoadingProgress() {
    var dv = document.getElementById("divManualProgress");
    var dvMainBg = document.getElementById("divMainBg");
    if (dv != null)
        dv.style.display = "none";  
    
    if (dvMainBg != null)
        dvMainBg.style.display = "none";
                    
    //document.body.style.overflow = "auto";
    document.documentElement.style.overflow = "auto";
}

//show curtain
function disableWindow() {
    var body = document.body;
    var html = body.parentNode;
    var y = body.scrollTop, x = body.scrollLeft, w = body.offsetWidth, h = body.offsetHeight;
    if (y == 0) {
        y = html.scrollTop;
        x = html.scrollLeft;
        w = html.clientWidth;
        h = html.clientHeight;
    }
    if (w > 0)
        x += w / 2 - 214 / 2;
    else
        w = document.body.offsetWidth;

    if (h > 0)
        y += h / 2 - 80 / 2;
    else
        h = document.body.offsetHeight;

    var dvMainBg = document.getElementById("divMainCurtain");
    if (dvMainBg != null) {
        //scroll(0, 0);
        //without DTD        
        dvMainBg.style.top = 0;
        dvMainBg.style.left = 0;
        dvMainBg.style.height = h;
        dvMainBg.style.width = w;
        //end without
        dvMainBg.style.display = "inline";
        document.body.style.overflow = "hidden";
    }
}

function enableWindow() {
    var dvMainBg = document.getElementById("divMainCurtain");
    if (dvMainBg != null) {
        dvMainBg.style.display = "none";
        document.body.style.overflow = "auto";
    }
}

//called when async postback begins
function prm_InitializeRequest(sender, args) {
    showLoadingProgress();    
}

// called when async postback ends
function prm_EndRequest(sender, args) {
    hideLoadingProgress();    
}

function trapDefaultButton(e, btnid)
{ 
	var bt = document.getElementById(btnid); 
	if (typeof bt == 'object'){ 		
		if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
			if (event.keyCode == 13 && bt.disabled == false){ 
				bt.click(); 
				return false; 
			} 
		} 
					    
		if(navigator.appName.indexOf("Netscape")>(-1)){ 
			if (e.keyCode == 13){ 								
			    var bt = document.getElementById(btnid); 									    			    
//			    bt.click();
//			    return false;
				var i = e.target.id.lastIndexOf("_");									
				var ctrl = e.target.id.substr(0, i);											
				i = btnid.lastIndexOf("_");
				var ctrl2 = btnid.substr(i+1);				
				i = ctrl.indexOf("_");
				if (i > -1) 				
					ctrl = ctrl.substr(0,i) + '$' + ctrl.substr(i+1);					
																		
				__doPostBack(ctrl + '$' + ctrl2, '');				
				return false; 
			} 
		} 		
		if (navigator.appName.indexOf("Safari")>(-1)){ 
			if (e.keyCode == 13){ 
				if (e.target.nodeType == 3) { // defeat Safari bug
					var targ = e.target.parentNode
					var source = targ.tagName
					var i = source.lastIndexOf("_");									
					var ctrl = source.substr(0, i);											
					i = btnid.lastIndexOf("_");
					var ctrl2 = btnid.substr(i+1);				
					i = ctrl.indexOf("_");
					if (i > -1) 				
						ctrl = ctrl.substr(0,i) + '$' + ctrl.substr(i+1);					
																			
					__doPostBack(ctrl + '$' + ctrl2, '');				
				}				
				return false; 
			} 
		} 
	} 
} 

function ignoreEnterKey(e) {				
	if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
		if (event.keyCode == 13){ 
			alert("Enter key is not allowed! Use \"<br/>\" tag instead.");							
			return false; 
		} 
	} 
	if ( navigator.appName.indexOf("Netscape")>(-1) || navigator.appName.indexOf("Safari")>(-1) ) { 
		if (e.keyCode == 13){ 								
			alert("Enter key is not allowed! Use \"<br/>\" tag instead.");							
			return false; 
		} 
	} 
}			

function ignoreKeyPress() {				
	return false; 
}			

function ignoreNonNumeric(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
} 
 
function Cover(bottom, top, ignoreSize) {       
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    //top.style.top = (screen.availHeight/2)-(top.style.height/2);   
    //alert(top.style.top);
    top.style.left = location.x + 'px';
    //top.style.left = (screen.availWidth/2)-(top.style.width/2);    
    
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}


function toggleControl(ctrlId) {				
    var ctrl=document.getElementById(ctrlId);    
    if (ctrl==null) 
        return;
   else if (ctrl.style.display=="none")
        ctrl.style.display="inline";				
   else if (ctrl.style.display=="" || ctrl.style.display=="inline")
        ctrl.style.display= "none";
}


function downloadWin(url) {
    newWindow = window.open(url, "downloadWin", "width=500,height=450,location=no,resizable=yes,scrollbars=yes,top=" + ((screen.availHeight / 2) - (450 / 2)) + ",left=" + ((screen.availWidth / 2) - (500 / 2)));
    newWindow.focus;
}

function secureDownload(url) {
    newWindow = window.open(url, "downloadWin", "width=500,height=200,location=no,resizable=yes,scrollbars=yes,top=" + ((screen.availHeight / 2) - (200 / 2)) + ",left=" + ((screen.availWidth / 2) - (500 / 2)));
    newWindow.focus;
}   		

function downloadToExcel(url) {
    newWindow=window.open(url,"downloadToExcel","width=500,height=275,location=no,resizable=yes,scrollbars=yes,top=" + (( screen.availHeight/2)-(275/2)) + ",left=" + ((screen.availWidth/2)-(500/2)));
	newWindow.focus;			
}		

function openPopUp(url, width, height) {
    newWindow=window.open(url,"pop","width=" + width +",height=" + height + ",location=no,resizable=yes,scrollbars=yes,top=" + (( screen.availHeight/2)-(height/2)) + ",left=" + ((screen.availWidth/2)-(width/2)));
	newWindow.focus;			
}			

//show/hide confirmation window
function toggleConfirm(divId, bgDivId, value) {		    		    
    //divId -> main confirmation window
    //bgDivId -> background div to disable background
    //value -> true or false
    var div = document.getElementById(divId);
    if (div != null)
    {
        if (value == true)        
        {  
            var strHeight = div.style.height;
            var strWidth = div.style.width;
            var divHeight = 100;
            var divWidth = 250;
            var winHeight = document.body.offsetHeight;
            var winWidth = document.body.offsetWidth;
            //show background filter             
            var bgDiv= document.getElementById(bgDivId); 
            if (bgDiv!=null)                                
                bgDiv.style.display = "block";  
                            
            if (div.style.height != null)
                divHeight = strHeight.replace(/px/,"");
                
            if (div.style.width != null)
                divWidth = strWidth.replace(/px/,"");
                
            if (document.documentElement.clientHeight != null && document.documentElement.clientHeight != 'undefined')
                winHeight = document.documentElement.clientHeight;                  
                                                                                                                
            div.style.top = (winHeight/2)- divHeight;
            div.style.left = (winWidth/2) - (divWidth/2);
            div.style.display = "block";
        }
        else
        { 
            //hide background filter             
            var bgDiv= document.getElementById(bgDivId); 
            if (bgDiv!=null)                                
                bgDiv.style.display = "none";                             
            div.style.display = "none";
        }
    }
}

function showItemPrice(ddl, ctrlId, cd, dvd, mp3) 
{
    if (ddl == null) return;
    var idx = document.getElementById(ddl.id).selectedIndex;
    var ctrl = document.getElementById(ctrlId);
    if (ctrl == null) return
        
    if (ddl.options[idx].value == '1')
        ctrl.innerHTML = cd;
    else if (ddl.options[idx].value == '2')
        ctrl.innerHTML = dvd;
    if (ddl.options[idx].value == '3')
        ctrl.innerHTML = mp3;
}

function disableLoginButton(ctrl_id) {
    var ctrl = document.getElementById(ctrl_id);
    //if (ctrl != null) {
    //    ctrl.disabled = true;
    //}
    return true;
}

function redirectParent(url) {
    var parentWindow = window.opener;
    if (parentWindow != null) {
        parentWindow.location = url
        parentWindow.focus();
    }
    window.close();
}	


