﻿/* global load
--------------------------------------------------------------------------------*/
//try { document.domain = "tunewiki.com"; } catch (error) { };

/* global functions
--------------------------------------------------------------------------------*/

String.prototype.trim = function() {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function clearText(objTextBox, defaultText) {
	if (objTextBox.value == defaultText) {
		objTextBox.value = "";
		objTextBox.setAttribute("style", "color: #000000;");
	}
}

function resetText(objTextBox, defaultText) {
	if (objTextBox.value == "") {
		objTextBox.value = defaultText;
		objTextBox.setAttribute("style", "color: #B0B0B0;");
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function strcmp(str1, str2){
    return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
}

function ord(string){
    return (string+'').charCodeAt(0);
}

function toFriendlyUrl(strIn) {
	if (!strIn || strIn.length == 0) {
		return "-";
	}
	strIn = strIn.trim();
	strIn = strIn.toLowerCase();
	array = strIn.split("");
	strOut = "";
	strPrev = ""
	for (var char in array) {
		if ((ord(array[char]) >= ord("0") && ord(array[char]) <= ord("9")) ||
			(ord(array[char]) >= ord("a") && ord(array[char]) <= ord("z")) ||
			(ord(array[char]) > 191)) {
			strOut += array[char];
			strPrev = array[char];
		} else if (strPrev != "-" && array[char] == " ") {
			strOut += "-";
			strPrev = "-";
		}
	}
	if (strOut.charAt(strOut.length - 1) == "-") {
		strOut = strOut.substring(0, strOut.length - 1);
	}
	if (strOut.length <= 0) {
		strOut = "-";
	}
	return strOut;
}

function urlencode(str){
	str = str.replace(/&quot;/g, escape('"'));
	str = str.replace(/\'/g, escape("'"));
	str = str.replace(/\"/g, escape('"'));
	str = str.replace(/&/g, escape("&"));
	return str;
}

function getClass(object) {
	return Object.prototype.toString.call(object);
}


function gotoArtistPage(artistName){
    location.href='/lyrics/' + encodeURIComponent(artistName) + '.aspx';
}

function gotoSongPage(artistName, songName, albumName) {
    var url = '/lyrics/' + artistName + '/' + songName + '.aspx';
    location.href=url;
}

function toTitleCase(str) {
	if ((str.toLowerCase() == str || str.toUpperCase() == str) && str.trim().charAt(0).toUpperCase() != str.trim().charAt(0).toLowerCase()) {
		var up = true;
		var result = "";
		var next = "";
		for (var i = 0; i < str.length; i++) {
			next = str.charAt(i);
			result += (up ? next.toUpperCase() : next.toLowerCase());
			up = ("!&()-_\\/;:,.? ".indexOf(next) != -1);
		}
		return result;
	} else {
		return str;
	}
}