function getOffset(element)
{
	valueT = 0;
	valueL = 0;
	do
	{
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
};

function getElementPosition(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ScrollToElement(element){

  var posX = 0;
  var posY = 0;
              
  while(element != null){
    posX += element.offsetLeft;
    posY += element.offsetTop;
    element = element.offsetParent;
  }
                        		      
 window.scrollTo(posX, posY);

}


//Used to support rollover images
function rollImg(btnID, img) 
{
    if(document.images) 
    {
        
        var btn = document.getElementById(btnID);
        if(btn)
            btn.src = img;
    }
}

//Used to catch the enter key in a textbox and click a button
function catchEnterKey(txtID, btnID)
{
    var txt = document.getElementById(txtID);
    var btn = document.getElementById(btnID);
    
    if(event.keyCode == 13 && txt && btn)
    { 
        btn.click(); 
        event.handled='true';
    }
}

//Used to open up new windows for descriptions
function newWin(contentURL, windowName)
{
    var inWindow = window.open(contentURL, windowName, 'scrollbars=yes,toolbar=no,location=yes,resizable=yes,width=640,height=480');
	inWindow.focus();
}

function clickLinkById(ele)
{
    var linkElement = document.getElementById(ele);
    if(linkElement)
    {
        document.location.href=linkElement.href;
    }
}

function disableItem(itemID)
{
    var item = document.getElementById(itemID);
    alert(item);
    if(item)
        item.disabled = true;
}

function getYScroll() {

    var yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }

    return yScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}

function centerWin(url, windowName, width, height)
{
    var bw, bh, bl, bt;
    
    if (document.all)
    {
        alert('document.all');
        bw = document.body.clientWidth;
        bh = document.body.clientHeight;
        bl = window.screenLeft;
        bt = window.screenTop;
    }
    else if (document.layers)
    {
        bw = window.outerWidth;
        bh = window.outerHeight;
        bl = window.screenX;
        bt = window.screenY;
    }

    var leftPos = Math.floor((bw-width)/2) + bl;
    var topPos = Math.floor((bh-height)/2) + bt;
    
    //<!-- window.open(url, windowName, 'height=' + height + ', width=' + width + ', top=' + topPos + ', left=' + leftPos + 'resizable=no, toolbar=no, menubar=no, titlebar=no, alwaysraised=yes, dependent=yes'); -->
    
    //alert(bw + ' ' + bh + ' ' + bl + ' ' + bt + ' ' + leftPos + ' ' + topPos);
}

var inputPrompt;
var inputCover;
var waitSender;
function EnterPromotionCode(message, inputBlockID, focusID, sender, doingPost) {

    if (waitSender) {//alert('herea');
        waitSender = null;
        return true;
    }
    else {//alert('herec');
        inputPrompt = document.getElementById(inputBlockID);
        if (sender && inputPrompt) {
            var pageinfo = getPageSize();
            var pos = getElementPosition(sender);
            pos[0] = (pageinfo[2] / 2) - (inputPrompt.style.width.replace("px", "") / 2);
            pos[1] = (pageinfo[3] / 2) - (inputPrompt.style.height.replace("px", "") / 2) + getYScroll();
            inputPrompt.style.position = 'absolute';
            inputPrompt.style.display = 'block';
            inputPrompt.style.zIndex = '50';
            inputPrompt.style.posLeft = pos[0] + 'px';
            inputPrompt.style.posTop = pos[1] + 'px';
            inputPrompt.style.left = pos[0] + 'px';
            inputPrompt.style.top = pos[1] + 'px';

            inputCover = document.getElementById('inputCover');
            if (inputCover) {
                inputCover.style.width = pageinfo[0] + 'px';
                inputCover.style.height = pageinfo[1] + 'px';
                inputCover.style.display = 'block';
            }

            if (document.getElementById(focusID))
                document.getElementById(focusID).focus();
        }

        if (doingPost)
            waitSender = sender;
            
        return false;
    }
}

function submitInput() {
    if (inputPrompt) {
        if (inputCover)
            inputCover.style.display = 'none';
        inputPrompt.style.display = 'none';

        if (waitSender != null) {//alert('hereb');
            waitSender.click();
        }
        else {
            var url = '' + document.location;
            var txtBoxes = inputPrompt.getElementsByTagName('input');
            var inputVals = '';
            for (i = 0; txtBoxes[i]; i++) {
                if (txtBoxes[i].getAttribute('type') == 'text') {
                    if (url.indexOf(txtBoxes[i].getAttribute('id') + '=') > -1) {
                        var subTemp = url.substring(url.indexOf(txtBoxes[i].getAttribute('id') + '='));
                        subTemp = subTemp.substring(0, subTemp.indexOf('&') + 1);
                        url = url.replace(subTemp, '');
                    }
                    url = url + txtBoxes[i].getAttribute('id') + '=' + txtBoxes[i].value + '&';
                }
            }
            document.location.href = url;
        }
    }
}

function cancelInput() {
    if (inputPrompt) {
        inputPrompt.style.display = 'none';
        if (inputCover)
            inputCover.style.display = 'none';
    }
    waitSender = false;
}
function GetInput(message)
{
    return prompt(message, '');
}


try
{
    checkForFrame();
}
catch(e)
{
}

function checkForFrame()
{
    try
    {
        if (top.location != location)
        {
            top.location.href = document.location.href ;
        }
    }
    catch(ex){}
}

function toggleElementDisplay(eleID)
{
    try {
        var eleDisp = document.getElementById(eleID);
        if (eleDisp) {
            if (eleDisp.style.display == 'none' || eleDisp.style.display == '') {
                eleDisp.style.display = 'block';
            }
            else {
                eleDisp.style.display = 'none';
            }
        }
    }
    catch (e) { }
}