﻿var ival;

var bimg =
{
	enlarge: function(obj) {
		document.getElementById('bimage').src = obj;
		document.getElementById('divbimg').style.display = 'block';
	},
	close: function() {
		document.getElementById('bimage').src = '/images/loader.gif';
		document.getElementById('divbimg').style.display = 'none';
	}
}
function ZoomIn(imgName, bimg,simg, maxWidth, maxHeight,swidth,sheight) {

	//alert(ival);
	if (ival == null) {
		var imgThumb, maxWidth, maxHeight, curx, cury, dx, dy;

		imgThumb = eval("document.getElementById('" + imgName + "')");

	    var maintablewidth = document.getElementById("tblmain").parentNode.getAttribute("width");
	    var maintableheight = document.getElementById("tblmain").parentNode.getAttribute("height");
	    var dialogwidth = eval("document.getElementById('" + imgName + "')").width ;
	    var dialogheight = eval("document.getElementById('" + imgName + "')").height;
	    var totalInnerSapce = (maintablewidth - dialogwidth);
	    var totalInnerSapceHeight = (maintableheight - dialogheight);
        eval("document.getElementById('" + imgName + "')").style.left = totalInnerSapce + "px";
	    eval("document.getElementById('" + imgName + "')").style.top = totalInnerSapceHeight + "px";
        
		curx = swidth;
		cury = sheight;

		stepx = maxWidth / 12;
		stepy = maxHeight / 12;

		// ival = new();
		functionRef = "resize('" + imgName + "', " + stepx + ", " + stepy + ", " + maxWidth + ", " + maxHeight + ")";
		ival = setInterval(functionRef,15);

		imgThumb.className = "magbimg";
		imgThumb.title = "Click to close";
		imgThumb.src = bimg;
		imgThumb.onclick = function() { ZoomOut(imgName, bimg, simg, maxWidth, maxHeight, swidth, sheight); };
	}
}
function ZoomOut(imgName, bimg, simg, maxWidth, maxHeight, swidth, sheight) {
	if (ival == null) {
		var imgThumb;
		imgThumb = eval("document.getElementById('" + imgName + "')");

		imgThumb.src = simg;
		imgThumb.width = swidth;
		imgThumb.height = sheight;

		imgThumb.className = "magimg";
		imgThumb.title = "Click to enlarge";
		imgThumb.onclick = function() { ZoomIn(imgName, bimg, simg, maxWidth, maxHeight, swidth, sheight); };
	}
}

function resize(imgName, dx, dy, maxWidth, maxHeight) {
	var imgThumb, curx, cury;
	imgThumb = eval("document.getElementById('"+imgName+"')");
    curx = imgThumb.width;
    cury = imgThumb.height;
    if ((curx<maxWidth-dx) && (cury<maxHeight-dy)){
	    imgThumb.height = cury + dy;
	    imgThumb.width = curx + dx;
    }
    else{
    	clearInterval(ival);
    	ival = null;
    imgThumb.height = maxHeight;
    imgThumb.width = maxWidth;
   }
   setImagePosition(imgName);
}

function setImagePosition(imgName) {


	var maintablewidth = document.getElementById("tblmain").parentNode.getAttribute("width");
	var maintableheight = document.getElementById("tblmain").parentNode.getAttribute("height");
	var browserwidth = document.body.offsetWidth;
	var browserheight = window.screen.height;

	var dialogwidth = eval("document.getElementById('" + imgName + "')").width ;

	var dialogheight = eval("document.getElementById('" + imgName + "')").height;

	var totalInnerSapce = (maintablewidth - dialogwidth);
	var totalInnerSapceHeight = (maintableheight - dialogheight);
	var leftSpacing = (totalInnerSapce / 2) + ((browserwidth - 949) / 2);
	var topSpacing = (((browserheight * 4 / 5) - dialogheight) / 2)+ f_scrollTop() ;

	if (topSpacing + totalInnerSapce > browserheight) {
		topSpacing = (topSpacing) + totalInnerSapceHeight + (browserheight / 2);
	}


	eval("document.getElementById('" + imgName + "')").style.left = leftSpacing + "px";
	eval("document.getElementById('" + imgName + "')").style.top = topSpacing + "px";



}
function preloadImages() {
	var args = preloadImages.arguments;
	document.arrImg = new Array(args.length);
	for (var x = 0; x < args.length; x++) {
		document.arrImg[x] = new Image;
		document.arrImg[x].src = args[x];
	}
}

function switchBottomTabs(open, count) {
	document.getElementById('tab' + open).setAttribute('background', '/images/tab_active.jpg');
	document.getElementById('page' + open).style.display = 'block';

	for (var x = 1; x <= count; x++) {
    if (x.toString() != open) {
    document.getElementById('tab' + x.toString()).setAttribute('background', '/images/tab_inactive.jpg');
    document.getElementById('page' + x.toString()).style.display = 'none';
    }
    }

    }
    function switchBottomBTabs(open, count) {
    document.getElementById('tab' + open).setAttribute('background', '/images/btab_active.jpg');
    document.getElementById('page' + open).style.display = 'block';

    for (var x = 1; x <= count; x++) {
    if (x.toString() != open) {
    document.getElementById('tab' + x.toString()).setAttribute('background', '/images/btab_inactive.jpg');
    document.getElementById('page' + x.toString()).style.display = 'none';
    }
    }

    }
    function switchBottomSATabs(open, count) {
    document.getElementById('page' + open).style.display = 'block';

    if (open!='2')
    document.getElementById('tab' + open).setAttribute('background', '/images/tab_active.jpg');
    else
    document.getElementById('tab' + open).setAttribute('background', '/images/btab_active.jpg');


    for (var x = 1; x <= count; x++) {
    if (x.toString() != open) {
    document.getElementById('page' + x.toString()).style.display = 'none';
    if(x.toString() != '2')
    document.getElementById('tab' + x.toString()).setAttribute('background', '/images/tab_inactive.jpg');
    else
    document.getElementById('tab' + x.toString()).setAttribute('background', '/images/btab_inactive.jpg');
    
    }
    }

    }
    function setPosition(objID, x) {

    var width = 960;
    if (document.compatMode && document.compatMode != "BackCompat")
    width = document.documentElement.clientWidth;
    else
    width = document.body.clientWidth;
    if (width < 960)
                 leftalig = x;
             else
                 leftalig = ((width - 960) * (1 / 2)) + x;
             
            leftalig = leftalig.toString() + "px";
            document.getElementById(objID).style.left = leftalig;
        }
