

/*
	durgle.base.js
	version 1.7
	first created: 10/27/03
	last revised: 9/16/07
	http://www.durgle.com
	talk@durgle.com
*/


// -------- BEGIN DEBUG -----------


// Set debug to show alerts
var debug = 0;
//var debug = 1;


// Show that debug is activated
if (debug) {
	window.onload = function() {
		alert("Debug Activated");
	}
}


// -------- END DEBUG -----------


// -------- BEGIN SETTINGS -----------


// Animation Frame rate per second
// unused now, integration within 2 months, err - maybe
var fRate = 24;


// -------- END SETTINGS -----------


// Get a reference to an object
function $d(TheID) { 
	return document.getElementById(TheID);
}


// Get a reference to an object
function $(TheID) { 
	return document.getElementById(TheID);
}


// Get a reference to an object with the style attribute
// why doesn't prototype offer this? :P
function $ds(x) {
	return $d(x).style;
}


// stop a form from being submitted, form onsubmit=ff(); ff = formFalse();
function ff() {
	return false;
}

// incase we forget :P
function formFalse() { ff(); }


// -------- BEGIN STRING, INT AND ARRAY FUNCTIONS -----------


// Trim a string on the left and right sides
function Trim(x) {
	//return x.replace(/^\s+|\s+$d/g,"");
}


// Split JavaScript by a semicolon
function splitSemi(x) {
	y = x.split(";");
	return y;	
}


// Print an array
function printr(arr) {
	for (var i = 0; i < arr.length; i++) {
		document.write(arr[i] + "<br />");
	}
}


// string to array split by commas
function str2arr(str) {
	var arr = str.split(",");
	return arr;
}


// Remove an array element by index
Array.prototype.removeByValue = function(value){
	for (var i = this.length; i >= 0; i--) {
		if (this[i] == value) {
			this.splice(i,1); 
			return value; 
		}
	}
}



// Store a string into an input field
function spt(x, y) {
	$d(x).value = y;
}


// hexadecimal to decimal
function hex2dec(hex) {
	return(parseInt(hex,16));
}


// decimal to hexadecimal
function dec2hex(dec) {
	return (dec < 16 ? "0" : "") + dec.toString(16);
}


// -------- END STRING, INT AND ARRAY FUNCTIONS -----------


// -------- BEGIN OPACITY, FADING AND VIEWING -----------


// Hide or show an object
function toggle(x) {
	if ($ds(x).display = 'none') {
		$ds(x).display = 'block';
	} else {
		alert('sdfvw');
		$ds(x).display = 'none';
	}
};


// Fade an element in or out via opacity
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	// determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpacity('" + id + "'," + i + ")",(timer * speed));
		timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpacity('" + id + "'," + i + ")",(timer * speed));
			timer++;
		}
	}
}


// Change the opacity for different browsers
function changeOpacity(id, opacity) {
	var object = $d(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
} 


// -------- BEGIN OPACITY, FADING AND VIEWING -----------



// -------- BEGIN STYLESHEET FUNCTIONS -----------



// Set the active style sheet from an alternate style sheet
function disableStyleSheet(mysrc) {
	if (debug) {
		alert('removing styl sheet: ' + mysrc);
	}
	var i, a;
	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if (a.getAttribute("rel").indexOf("style") != -1) {
			if (a.getAttribute("src").indexOf(mysrc) != -1) {
				if (debug) {
					alert('stylesheet match');
				}
				a.disabled = true;
			}
		}
	}
}


// Set the active style sheet from an alternate style sheet
function disableFirstStyleSheet() {
	document.getElementsByTagName('link')[0].disabled = true;
}



// -------- END STYLESHEET FUNCTIONS -----------



// -------- BEGIN "DIMENSIONS" INFORMATION -----------


// Get an objects width
function getW(x) {
	if ($d(x).clientWidth) {
		var w = $d(x).clientWidth;
	} else {
		if ($d(divID).offsetWidth) {
			var w = $d(divID).offsetWidth;
		}
	}
	return w;
};


// Get an objects height
function getH(x) {
	if ($d(x).clientHeight) {
		var h = $d(x).clientHeight;
	} else {
		if ($d(divID).offsetHeight) {
			var h = $d(divID).offsetHeight;
		}
	}
	return h;
};


// Get an objects x coordinate
Object.prototype.getX = function () {
	var x = $ds(this).left;
	return x;
}


// Get an objects y coordinate
Object.prototype.getY = function (x) {
	var y = $ds(x).top;
	return y;
}


// -------- END "DIMENSIONS" INFORMATION -----------


// -------- BEGIN MISCELLANEOUS FUNCTIONS -----------


// Create a div
function createDiv(myL, x, y, w, h, bg) {
	myL = document.createElement("DIV"); 
	document.body.appendChild(myL); 
	myL.style.position = 'absolute';
	myL.style.background = bg;
	myL.style.top = y;
	myL.style.left = x;
	myL.style.width = w;
	myL.style.height = h;
	myL.style.innerHTML = "&nbsp;";
	myL.style.border = "1px solid red";
}


// Set new colors of divs with an __indexOf("color")
function setNewColors() {
	var i, a, j;
	j = 0;
	for(i = 0; (a = document.getElementsByTagName("div")[i]); i++) {
		if (a.getAttribute("id")) {
			if (a.getAttribute("id").indexOf("color") != -1) {
				//alert(pColors2[j]);
				//a.style.background = pColors2[i];
				//alert(a.getAttribute("id"));
			}
		}
	j++;
	}
};


function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
		return;
	}
} 


function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}


function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}


// -------- END MISCELLANEOUS FUNCTIONS -----------


// -------- BEGIN IMAGE PRELOADING AND ROLLOVER FUNCTIONS -----------


// Create new image object with location
function newImage(imgSrc) {
	var imgName = new Image();
	imgName.src = imgSrc;
	return imgName;
}


// Rollover
function change(imgName, imgLocation) {
	document[imgName].src = imgLocation ;
}


// Images are not preloaded yet
var preloadFlag = false;


// Preload images
function loadImages() {
	if (document.images) {
		home_over = newImage("images/rollover-home-over.gif");
		preloadFlag = true;
	}
}


// -------- END IMAGE PRELOADING AND ROLLOVER FUNCTIONS -----------


// -------- BEGIN FORM CHECKING FUNCTIONS -----------


// Toggle the signup form input and adjust based on the account type
function signupToggle(dv) {
	document.getElementById("newuser").style.display = 'none'; 
	document.getElementById("model").style.display = 'none'; 
	document.getElementById("producer").style.display = 'none'; 
	document.getElementById("musician").style.display = 'none'; 
	document.getElementById("label").style.display = 'none'; 
	document.getElementById(dv).style.display = 'block';
}


// Put the focus on a form element and change the background color
function focusFormElement(elementID) {
	$(elementID).focus();
}


// Check and see if an input box is filled in or not
function validateRequired(field,alerttxt) {
	with (field) {
		if (value == null || value == "") {
			alert(alerttxt);
			return false;
		} else {
 			return true;
		}
	}
}


// Make sure that all of the form is filled out
function checkForm(aForm) {
	formLength = aForm.elements.length;
	formErrors = 0;
	for (i = 0; i < formLength; i++) {
		formElementType = aForm.elements[i].type;
		formElementValue = aForm.elements[i].value;
		formElementName = aForm.elements[i].name;
		formElementID = aForm.elements[i].id;

		if (formElementType == "text" || formElementType == "password") {
			if (formElementValue == "" || formElementValue == null) {
				aForm.elements[i].style.backgroundColor = "red";
				aForm.elements[i].onfocus = function() {
					document.forms[0].elements[i].style.backgroundColor = "white";
				}
				formErrors += 1;
			}
		}
		if (formElementType == "select-one") {
			if (formElementValue == "") {
				aForm.elements[i].style.backgroundColor = "red";
				formErrors += 1;
			}
		}
		if (formElementType == "checkbox") {
			if (aForm.elements[i].id == "thirteen" || aForm.elements[i].id == "terms") {
				if (aForm.elements[i].checked == false) {
					aForm.elements[i].style.backgroundColor = "red";
					formErrors += 1;
				}
			}
		}
	}
  	if (formErrors > 0) {
  		errorStr = "You have left (" + formErrors + ") fields empty";
  	    alert(errorStr);
    	return false;
  	} else {
  		return true;
	}
}


// See if a checkbox is checked or not
function checkFormChecked(BoxID, errorStr) {
	if ($(BoxID).checked == false) {
		alert(errorStr);
		return false;
	} else {
		return true;
	}
}

// -------- END FORM CHECKING FUNCTIONS -----------


// EOF