// JScript File

//Global Variables
var gstrImg = "ctl00_ContentPlaceHolder1_";
var gstrTxt = "ctl00_ContentPlaceHolder1_";

//Sets cursor to hand for mouseover
function mouseOverToHand(item)
{
    item.style.cursor= 'pointer';
}

//document.getElementById(id); 
function disp(ctl,tf)
{
    var obj = document.getElementById(ctl)
    if (tf == 't') {
        obj.style.display = "inline-block";
    } else {
        obj.style.display = "none";
    }
}

//Display Progress Indicator
function dispProg(ctl,tf)
{
    if (Page_ClientValidate() == true) {
        var obj = document.getElementById(ctl)
        if (tf == 't') {
            obj.style.display = "inline-block";
            obj.innerHTML = "<img src='/images/ajax.gif' height='16' /> &nbsp;Please wait... Uploading Files...";
        } else {
            obj.style.display = "none";
        }
    }
}

//Toggle Visibility
function dispHandle(obj) 
{
    if (obj.style.display == "none") {
        obj.style.display = "block";
    } else {
        obj.style.display = "none";
    }
}

//ImageSelect Returns Image    
function returnImage(img) 
{
    var qs = new Querystring();
    var iID = qs.get("ID");
    var imgPrev = window.opener.document.getElementById(gstrImg + "imgPrev"+iID);
    var imgVal = window.opener.document.getElementById(gstrTxt + "txtImageValue"+iID);
        imgPrev.src = img.src;
        imgVal.value = img.src;
        imgPrev.style.width = img.width;
        imgPrev.style.height = img.height;
        window.close();
}

//ImageSelect Returns No Image
function returnNoImage()
{
    var qs = new Querystring()
    var iID = qs.get("ID")
        window.opener.document.getElementById(gstrImg + "imgPrev"+iID).src = '';
        window.opener.document.getElementById(gstrTxt + "txtImageValue"+iID).value = '';
        window.close();
}

//QueryString Constructor
function Querystring_get(key, default_) {
    if (default_ == null) default_ = null;
	
    var value=this.params[key]
    if (value==null) value=default_;
	
    return value
} 

//Parses Query String
function Querystring(qs) {
    this.params = new Object()
    this.get=Querystring_get
	
    if (qs == null)
        qs=location.search.substring(1,location.search.length)

    if (qs.length == 0) return

    qs = qs.replace(/\+/g, ' ')
    var args = qs.split('&') // parse out name/value pairs separated via &
	
    for (var i=0;i<args.length;i++) {
        var value;
        var pair = args[i].split('=')
        var name = unescape(pair[0])

        if (pair.length == 2)
	        value = unescape(pair[1])
        else
	        value = name
		
        this.params[name] = value
    }
}

//Opens Popup Window. Size based on type requested
function popupWindow(type,id,pageId)
{
    var ht;
    var wd;

    switch (type) {
        case "Image":
            ht = 500;
            wd = 700;
            break;
        case "Upload":
            ht = 400;
            wd = 540;
            break;
        case "PhotoEdit":
            ht = 500;
            wd = 440;
            break;    
        case "BucketEdit":
            ht = 500;
            wd = 640;
            break;
        case "HeroImages":
            ht = 600;
            wd = 660;
            break;
        case "Portfolio":
            ht = 600;
            wd = 660;
            break;
        case "PortfolioEdit":
            ht = 440;
            wd = 540;
            break;
    }
    window.open('/EditPages/Select' + type + '.aspx?ID='+id+'&pageId='+pageId,'_popup_'+type+'_'+id,'height='+ht+',width='+wd+',status=no,resizable=no,scrollbars=yes,toolbar=no,location=no,menubar=no')
}

//Auto Tabs
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

    if(input.value.length >= len && !containsElement(filter,keyCode)) 


    {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }


function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
else
    index++;
    return found;
}

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
    }

return true;
}
// End Auto Tabs
