// Political Connect Global JavaScript Utility

//Global Variables
var gstrImg = "ctl00_ContentPlaceHolder1_";
var gstrTxt = "ctl00_ContentPlaceHolder1_";
//var gstrTxt = "ctl00$ContentPlaceHolder1$";

//Toggle Visibility
function dispHandle(obj) 
{
    if (obj.style.display == "none") {
        obj.style.display = "block";
        document.getElementById('SaveButton').style.display = "block";
    } else {
        obj.style.display = "none";
        document.getElementById('SaveButton').style.display = "none"; 
    }
}

//Toggle Visibility - New 1/9/10 - KM
function ShowHideDiv(id)
{
    var o = document.getElementById(id);
    //var s = document.getElementById('SaveButton')
    
    if(o != null)
    {
        if(o.style.display == 'block')
            o.style.display = 'none';
            //s.style.display = 'none';
        else
            o.style.display = 'block';
            //s.style.display = 'block';              
    }
}


//Sets Correct BucketID
function bucketClick(bID)
{
    window.location.href="EditBucket.aspx?ID=" + bID;
}

//Sets bgimage for mouseover
function mouseOverChangeImage(item)
{
    item.style.backgroundImage= 'url(images/topbarbgred.jpg)';
}

//Sets bgimage for mouseout
function mouseOutChangeImage(item)
{
    item.style.backgroundImage= 'url(images/topbarbgblue.jpg)';
}
			
//Sets cursor to hand for mouseover
function mouseOverToHand(item)
{
    item.style.cursor= 'pointer';
}

//Set bgcolor of item for mouseover
function mouseOverChangeBGcolor(item)
{
    item.style.backgroundColor='#FFFF66';
}

//Set bgcolor of item for mouseout
function mouseOutChangeBGcolor(item)
{
    item.style.backgroundColor='#FFFFFF';
}

//Set bgcolor and cursor of restricted area for mouseover
function mouseOverRestrictBGcolor(item)
{
    item.style.backgroundColor='#FFCCCC'; 
    item.style.cursor = 'no-drop';
}

//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 "Color":
            ht = 200;
            wd = 300;
            break;
        case "Font":
            ht = 560;
            wd = 500;
            break;
        case "Upload":
            ht = 400;
            wd = 540;
            break;
        case "PhotoEdit":
            ht = 540;
            wd = 400;
            break; 
        case "ContentEdit":
            ht = 500;
            wd = 640;
            break;                        
        case "ContentPhoto":
            ht = 320;
            wd = 440;
            break; 
        case "ArticleEdit":
            ht = 570;
            wd = 640;
            break; 
        case "ArticlePhoto":
            ht = 320;
            wd = 440;
            break;             
    }
    //window.showModalDialog("Select" + type + ".aspx?ID="+id,"","dialogHeight:"+ht+"px;dialogWidth:"+wd+"px;status:no")
    window.open('/PoliticalConnect.Web.UI/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')
}

//Returns Font from Select
function returnFont(f) 
{
    var qs = new Querystring()
    var iID = qs.get("ID")
        FontString = f.style.fontFamily
        window.opener.document.getElementById(gstrTxt + 'txtFontValue'+iID).value = FontString;
        window.opener.document.getElementById(gstrTxt + 'txtFontValue'+iID).style.fontFamily = FontString;
        window.close();
}

//Color Select
 function cO(theTD) 
{
    color = theTD.style.backgroundColor;
    previewColor(color); 	
    setTextField(color); 
}

function cC(theTD) 
{ 	
    color = theTD.style.backgroundColor; 	
    setTextField(color); 	
    returnColor(color); 
} 
function setTextField(ColorString)
{ 	
    document.getElementById('ColorText').value = ColorString.toUpperCase(); 
} 
function returnColor(ColorString) 
{
var qs = new Querystring()
var iID = qs.get("ID")
    window.opener.document.getElementById(gstrTxt + 'txtColorValue'+iID).value = ColorString.toUpperCase();
    window.opener.document.getElementById(gstrTxt + 'txtColorDisp'+iID).style.backgroundColor = ColorString.toUpperCase();
    window.close();
}
function userInput(theinput) 
{	 	
    previewColor(theinput.value); 
} 
function previewColor(theColor) 
{ 
    try 
    { 		
        document.getElementById('PreviewDiv').style.backgroundColor = theColor; 
    } 
    catch (e) 
    {} 
}
function okButton()
{ 	
    theColor = document.getElementById('ColorText').value; 	
    returnColor(theColor);
}
//End Color Select