﻿var rooturl = 'http://www.willowtip.com'

// Common JavaScript Functions //

function removeDefaultText(sender) {
	if (sender.value == sender.defaultValue) {
		sender.value = '';
	}
}

function returnDefaultText(sender) {
	if (sender.value == '') {
		sender.value = sender.defaultValue;
	}
}

function confirmDelete() {
	return window.confirm("Are you sure you want to delete this record?");
}

function confirmOther(message) {
	return window.confirm(message);
}

// Media Chooser Functions //

function openChooser(sender,mediaid,url){
	window.open(rooturl + "/manager/tools/chooser.aspx?sender=" + sender + "&id=" + mediaid + "&url=" + url,'MediaChooser','width=800,height=450,scrollbars=yes,resizable=yes');
}

// Music Player //

function openMusicPlayer(url){
	window.open(rooturl + "/tools/player.aspx?url=" + url,'MusicPlayer','width=650,height=270,scrollbars=no,resizable=yes');
}

// Multiline TextBox Length Function //

function isMaxLength(obj) {
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length > mlength) {
		obj.value = obj.value.substring(0,mlength);
	}
}

//GridView Checkbox Functions//

function ChangeCheckBoxState(id, checkState) {
    var cb = document.getElementById(id);
    if (cb != null)
       cb.checked = checkState;
}

function ChangeAllCheckBoxStates(checkState) {
    // Toggles through all of the checkboxes defined in the CheckBoxIDs array
    // and updates their value to the checkState input parameter
    if (CheckBoxIDs != null) {
        for (var i = 0; i < CheckBoxIDs.length; i++)
           ChangeCheckBoxState(CheckBoxIDs[i], checkState);
    }
}

function ChangeHeaderAsNeeded() {
    // Whenever a checkbox in the GridView is toggled, we need to
    // check the Header checkbox if ALL of the GridView checkboxes are
    // checked, and uncheck it otherwise
    if (CheckBoxIDs != null)
    {
        // check to see if all other checkboxes are checked
        for (var i = 1; i < CheckBoxIDs.length; i++)
        {
            var cb = document.getElementById(CheckBoxIDs[i]);
            if (!cb.checked)
            {
                // Whoops, there is an unchecked checkbox, make sure
                // that the header checkbox is unchecked
                ChangeCheckBoxState(CheckBoxIDs[0], false);
                return;
            }
        }
        
        // If we reach here, ALL GridView checkboxes are checked
        ChangeCheckBoxState(CheckBoxIDs[0], true);
    }
}

// Cookie Code //

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		
		if (c_start != -1) { 
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";",c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name+ "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

// Hide/Show Music Player //

function hidePlayer() {
	var player = $get('ctl00_cphMain_pnlPlayer');
	
	if (player != null) {
		player.style.visibility = "hidden";
	}
}
function showPlayer() {
	var player = $get('ctl00_cphMain_pnlPlayer');
	
	if (player != null) {
		player.style.visibility = "visible";
	}
}

// Flash Clipboard Copy //

function copy(text2copy) {
	if (window.clipboardData) {
		window.clipboardData.setData("Text",text2copy);
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="'+rooturl+'/media/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
}
