﻿// DOM helper functions
function getElementStyle(id, styleName) 
{
    if(!document.getElementById)
         return;

    var _element = document.getElementById(id);

    if(!_element)
        return;

    var value = _element.style[toCamelCase(styleName)];

    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(_element, "").getPropertyValue(styleName);
       
        else if(_element.currentStyle)
            value = _element.currentStyle[toCamelCase(styleName)];
     
     return value;
}

function setElementStyle(objId, style, value)
{
    document.getElementById(objId).style[style] = value;
}

function toCamelCase( sInput )
{
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? 
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    
    return ret;
}

function showDiv(id)
{
    var divToShow = document.getElementById(id);
    if(divToShow)
        divToShow.style.display = "block";
        
    //return false;
}

function showDivReturnFalse(id)
{
    showDiv(id);
    
    return false;
}

function hideDivReturnFalse(id)
{
    hideDiv(id);
    
    return false;
}

function hideDiv(id)
{
    var divToHide = document.getElementById(id);
    if(divToHide)
        divToHide.style.display = "none";
        
    //return false;
}

function flipDiv(id)
{
    var divToFlip = document.getElementById(id);
    
    if(divToFlip)
    {
        if(divToFlip.style.display == "none")
            divToFlip.style.display = "block";
        else
            divToFlip.style.display = "none";
    }
}
    
function setInnerHTML(id, innerHTML)
{
    var ele = document.getElementById(id);
    if(ele)
        ele.innerHTML = innerHTML;
}

// Reset TextBoxes in the specified container ID.
// container can be div, table, anything.
function resetTextBoxes(containerId)
{
    var _container = document.getElementById(containerId);
    var inputs;
    
    if(_container)
    {
        inputs = _container.getElementsByTagName("input");
        if(inputs)
        {
            for(i=0;i<inputs.length;i++)
            {
                if(inputs[i].type == "text")
                    inputs[i].value = "";
            }
        }
    }
}


// Open Window PopUp
function openWindow(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
	
	cookie_str = document.cookie;
	cookie_str.toString();
	pos_start  = cookie_str.indexOf(name);
	pos_start  = cookie_str.indexOf('=', pos_start);
	pos_end    = cookie_str.indexOf(';', pos_start); 
	if (pos_end <= 0) pos_end = cookie_str.length;
		cookie_val = cookie_str.substring(pos_start + 1, pos_end);
	if (cookie_val  == "done")
	    return;
	    
	    window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

// View Large Imges
function viewLargeImg(path, name)
{  
    document.getElementById(name).src = path;   
}


// Image Controls
var sRepeat=null;
function doScrollerIE(dir, src, amount) 
{
//alert(amount)
    if (amount==null)
    {amount=20;}
    
    if (dir=="right")
    {
        document.getElementById(src).scrollLeft+=amount;        
    }
    else
    {
        document.getElementById(src).scrollLeft -=amount;       
    }
    
    if (sRepeat==null)
    {
        sRepeat = setInterval("doScrollerIE('" + dir + "','" + src + "'," + amount + ")",100);
        return false;
    }
    return false;
}
window.document.onmouseout = new Function("clearInterval(sRepeat);sRepeat=null");
window.document.ondragstart = new Function("return false");



////////////////////////////////////////////////////////////////////
// Function Title :Check Empty Space.
// Function Desc : 
///////////////////////////////////////////////////////////////////
function isEmpty(ctrl)
{   
    var obj = document.getElementById(ctrl);
   
    if((obj.value == null) || (obj.value == ""))
    {
        return false;
    }   
    return true;   
}

// Add to Favorite
function AddtoFavorite(favoriteUrl,favoriteTitle)
{	
	window.external.AddFavorite(favoriteUrl,favoriteTitle);
}

////////////////////////////////////////////////////////
// This returns x coordinate of mouse position
////////////////////////////////////////////////////////
function getMousePosX(e)
{
    var browserType = (document.all) ? ("ie"):("ns");
    var mouseX;
    
    return (browserType == "ie") ? (event.clientX) : (e.clientX);
}

////////////////////////////////////////////////////////
// This returns y coordinate of mouse position
////////////////////////////////////////////////////////
function getMousePosY(e)
{
    var browserType = (document.all) ? ("ie"):("ns");
    var mouseY;
    
    return mouseY = (browserType == "ie") ? (event.clientY) : (e.clientY);    
}

/////////////////////////////////////////////////////////////
// This returns current scroll position
// usage: var curScrollPos = getCurrentScrollPosition();
//        var x = curScrollPos.X;
//        var y = curScrollPos.Y;
////////////////////////////////////////////////////////////
function getCurrentScrollPosition()
{
    var de = document.documentElement;
    var b = document.body;
    var curPosition = {};
    
    curPosition.X = document.all ? (!de.scrollLeft ? b.scrollLeft : de.scrollLeft) : (window.pageXOffset ? window.pageXOffset : window.scrollX);
    curPosition.Y = document.all ? (!de.scrollTop ? b.scrollTop : de.scrollTop) : (window.pageYOffset ? window.pageYOffset : window.scrollY);
        
    return curPosition;
}   

////////////////////////////////////////////////////////////////
// This returns correct current scroll position and returns
////////////////////////////////////////////////////////////////
function getCorrectScrollPosition()
{
    var _scrollPos = getCurrentScrollPosition();
    
    // correct current Y scroll position
    if(_scrollPos.Y <= 100)
        _scrollPos.Y = 0
    else if(_scrollPos.Y > 100 && _scrollPos.Y <= 200)
        _scrollPos.Y -= 100;
    else
        _scrollPos.Y -= 150; 
        
    // corrent current X scroll position if needed
    
    return _scrollPos;          
}

 