// JavaScript Document
	/*************************************** NAVIGATION *******************************************/
	
	var urls = new Array("index.php", "kunstenaars.php", "albums.php", "nuwetunes.php", "bespreekings.php", "kontak.php", "nuus.php");


	function gotoPage(index){
		setPage(urls[index]);
	}
	
	function setPage(pageURL){
		document.location.href = pageURL;
	}	
	
	function bookmarkSite(){
		window.external.AddFavorite("http://www.mozi.co.za", "MOZI RECORDS");
	}		
	
	function openNewUrl(url){
		if(isValidUrl(url)){
			window.open(url);
		}
	}
	
	/*************************************** DATE & TIME *******************************************/
	
	function parseDate(date){
		//alert(date);
		var pieces = date.split("-");
		if(pieces.length == 3){					
			return pieces[2]+" "+parseMonth(pieces[1])+" "+pieces[0];
		}
		return "Unknown";
	}
	
	function parseMonth(number){
		var newNum = null;
		if(isNaN((newNum=parseFloat(number))) || newNum < 1){
			return "-"+number+"-";
		}
		switch(newNum){
			case(1):	return "Januarie";	case(2):	return "Febuarie";		case(3):	return "Maart";
			case(4):	return "April";		case(5):	return "Mei";			case(6):	return "Junie";
			case(7):	return "Julie";		case(8):	return "Augustus";		case(9):	return "September";
			case(10):	return "Oktober";	case(11):	return "November";		case(12):	return "December";
		}
	}
	
	function parseTime(time){
		var split = time.split(":");
		if(split.length == 3){
			time = split[0]+":"+split[1];
			if(parseInt(split[0]) < 12){
				return time+" AM";
			}else if(parseInt(split[0]) >= 12){
				return time+" PM";
			}
		}
		return "Unknown";
	}
	
	function parseWeekday(index){
		var days = new Array("Son", "Maan", "Dins", "Woe", "Don", "Vry", "Sat");
		if(index > -1 && index < 7){
			return days[index];
		}
		return "Unknown";
	}
	
	function parseMySqlDate(){
		var data = document.data_form;
		var years = ["2007", "2008", "2009", "2010"];
		var year = years[data.select_year.selectedIndex];
		var month = data.select_month.selectedIndex+1;
		var day = data.select_day.selectedIndex+1;
		if(month < 10){	month = "0" + month ;		}
		if(day < 10){	day = "0" + day ;		}
		return (year+"-"+month+"-"+day);
	}
										
	function getDateIndexes(date){
		var split = date.split("-");
		if(split.length == 3){					
			return [(split[0] == "2007" ? 0 : (split[0] == "2008" ? 1 : (split[0] == "2009" ? 2 : 3))), split[1]-1, split[2]-1];
		}
		return[0];
	}	
	
	function zeroFill(str, len){
		while(str.length < len){
			str = "0"+str;
		}
		return str;
	}
	
	/*************************************** FORMATTING *******************************************/

	
	function formatForDB(str){
		str = str.replace(new RegExp("\n", "g"), "<>");
		return str.replace(new RegExp("\r", "g"), "");		 
	}
	
	function insertBreakTags(str){
		return str.replace(new RegExp("<>", "g"), "<br>");		 
	}
	
	function insertNewlines(str){
		return str.replace(new RegExp("<>", "g"), "\n");		 
	}
	
	/*************************************** MENU BUTTONS *******************************************/
	
	var menuButtons = new Array();
		
	function setMenuButtons(index){
		var menuBtns = new Array(document.getElementById("nav_btn_0"), document.getElementById("nav_btn_1"), document.getElementById("nav_btn_2"), 
								 document.getElementById("nav_btn_3"), document.getElementById("nav_btn_4"), document.getElementById("nav_btn_5"), 
								 document.getElementById("nav_btn_6"));
		var overBtns = new Array(document.getElementById("nav_over_0"), document.getElementById("nav_over_1"), document.getElementById("nav_over_2"), 
								 document.getElementById("nav_over_3"), document.getElementById("nav_over_4"), document.getElementById("nav_over_5"), 
								 document.getElementById("nav_over_6"));
		for(var i=0; i<menuBtns.length; i++){
			menuButtons[i] = new ActiveButton(menuBtns[i], overBtns[i], overBtns[i]);
			menuButtons[i].setLoaded();
		}
		menuButtons[index].setSelected(true);
	}
						
	function menuButtonOver(index){
		if(pageLoaded){
			menuButtons[index].buttonOver();
		}
	}
		
	function menuButtonOut(index){
		//window.status="outCall: "+index;
		if(pageLoaded){
			menuButtons[index].buttonOut();
		}
	}	
	
	/*************************************** PAGE BUTTONS *******************************************/
	
	var pageButtons = new Array();
	var pageLoaded = false;

	function setPageLoaded(index){
		pageLoaded = true;
		for(var i=0; i<pageButtons.length; i++){
			pageButtons[i].setLoaded();
		}
		setMenuButtons(index);
	}

	function setPageButtons(index, btn, over, down){
		if(index == pageButtons.length){
			pageButtons[index] = new ActiveButton(btn, over, down);
		}
	}
	
	function pageButtonOver(index){
		if(pageLoaded){
			pageButtons[index].buttonOver();
		}
	}
	
	function pageButtonOut(index){
		if(pageLoaded){
			pageButtons[index].buttonOut();
		}
	}
	
	function pageButtonDown(index){
		if(pageLoaded){
			pageButtons[index].buttonDown();
		}
	}
	
	function pageButtonUp(index){
		if(pageLoaded){
			pageButtons[index].buttonUp();
		}
	}
	
	function hiliteImage(img){
	}
	
	function loliteImage(img){
	}
	
	var hiliteCol = "#B90002";
	var loliteCol = "#160b03";
	
	function hiliteText(element){
		element.style.color = hiliteCol;		
	}
	
	function loliteText(element){
		element.style.color = loliteCol;
	}				
	
	function hiliteRow(row){
		if(row != selectedRow){	
			row.style.color = hiliteCol;
			//element.style.backgroundColor = "#EDEDED";
		}		
	}
	
	function loliteRow(row){
		if(row != selectedRow){
			row.style.color = loliteCol;
			//element.style.backgroundColor = "#FFFFFF";
		}	
	}			
	
	var selectedRow = null;
	
	function selectRow(row){
		if(row != selectedRow){
			oldSelRow = selectedRow;
			hiliteRow(selectedRow = row);			
			if(oldSelRow != null){
				loliteRow(oldSelRow);
			}
		}
	}	


	/*************************************** LOGIN & VALIDATION *******************************************/
	
	
	function isValid(field){
		try{
			field = depad(field);
			return (field != null && field.length > 0);
		}catch(ex){ return false;	}
	}
	
	function isValidAddress(add){
		return(isValid(add) && add.indexOf("@") > 0 && (add.lastIndexOf(".") > add.indexOf("@")));
	}
	
	function isValidUrl(url){
		return(isValid(url) && (url.indexOf("http://") > -1 || url.indexOf("https://") > -1) && url.length > 8);
	}
	
	function isValidImage(img){
		return(isValid(img) && (img.indexOf(".gif") > 0 || img.indexOf(".jpg") > 0 || img.indexOf(".jpeg") > 0 
								|| img.indexOf(".png") > 0 || img.indexOf(".wbmp") > 0));
	}

	function depad(string){
		if(string.length > 0){
			while(string.charAt(0) == " "){
				string = string.substring(1, string.length);
			}	
			while(string.charAt(string.length-1) == " "){
				string = string.substring(0, string.length-1);
			}
		}
		return string;
	}
		
	function clearField(field){
		if(dataIndex == -1 && isValid(field.value) && (field.value.indexOf("Enter") == 0 || 
				field.value.indexOf("Provide") == 0 || field.value.indexOf("Specify") == 0)){
			field.value = "";
		}
	}
		
	function isSpecialFree(str){
		var specials = ["~", "`", "!", "@", "#", "$", "%", "^", "&", "+", "=", "[", "{", "]", "}", ";", ":", "\"", "\\", "|", "<", ">", "/", "?"];
		for(var i=0; i<specials.length; i++){
			if(str.indexOf(specials[i]) > -1){
				return false;
			}
		}
		return true;
	}			
	
	function notify(str){
		if(isValid(str)){
			alert(str+"    ");
		}
	}
