// JavaScript Document

href = window.location.href
this_url = href.substr(href.lastIndexOf("/")+1)
page = this_url.replace(".asp", "")

img_arr = new Array()
img_arr[0] = "image_00.jpg"
img_arr[1] = "image_01.jpg"
img_arr[2] = "image_02.jpg"
img_arr[3] = "image_03.jpg"
img_arr[4] = "image_04.jpg"
img_arr[5] = "image_05.jpg"
img_arr[6] = "image_06.jpg"
img_arr[7] = "image_09.jpg"

function swap_menu(id){
	
	obj=document.getElementById(id)
	
	if((obj&&id.indexOf(page)<0)||(page=="")){
		if(obj.className=="menu_item_over"){
			obj.className = "menu_item_out"
		}else{
			obj.className = "menu_item_over"
		}
	}
}
function swap(id){
	obj=document.getElementById(id)
	if(obj){
		if(obj.className.indexOf("_off") > 0 || obj.className.indexOf("_out") > 0){
			obj.className = obj.className.replace("_off", "_on")
			obj.className = obj.className.replace("_out", "_over")
		}else{
			obj.className = obj.className.replace("_on", "_off")
			obj.className = obj.className.replace("_over", "_out")
		}
	}else{
		mgd_alert("Swap Image Failed! Object does not exist.")	
	}
}
function display(id){
	obj=document.getElementById(id)
	if(obj){
		if(obj.style.display=="none"){
			obj.style.display = "block"
		}else{
			obj.style.display = "none"
		}
	}
}
function randomize_photo(id){
	
	var rndm = Math.floor(Math.random()*7)
	
	obj=document.getElementById(id)
	
	if(obj){
		obj.src = "images/photos/"+ img_arr[rndm]
		obj.style.display = "block"
	}
}
function validate(field_str, form_id){
	
	field_arr = field_str.split(",")
	field_error = 0
	
	for(i=0;i<field_arr.length;i++){
		if(field_arr[i].length>0){
			obj = document.getElementById(field_arr[i])
			if(obj){
				if(obj.value.length==0){
					obj.className = "field_error"
					field_error++
				}else{
					obj.className = "field_input"
				}
			}
		}
	}
	if(field_error>0){
		
		error_msg = "Please fill in the missing information and try again. Thank you!"
		msg_obj = document.getElementById("msg_center_error")
		
		if(msg_obj){
			msg_center(error_msg, "e")
		}else{
			alert(error_msg)
		}
		return false
	}else{
		form_obj = document.getElementById(form_id)
		if(form_obj){form_obj.submit()}
		return true
	}
}
function msg_center(txt, typ){

	if(typ=="i"){obj_id="msg_center_info"}
	if(typ=="w"){obj_id="msg_center_warning"}
	if(typ=="e"){obj_id="msg_center_error"}
	
	obj = document.getElementById(obj_id)
	if(obj){
		obj.style.display = "block"
		obj.innerHTML = obj.innerHTML.replace(txt, "") + txt
	}
}
function active_menu(id){

	// CHANGE ACTIVE LINK
	link_obj = document.getElementById(id)
	
	if(link_obj){
		link_obj.className = link_obj.className.replace("_off", "_active")
	}	
}
function delete_action(form_id){
	
	obj = document.getElementById("db_action")
	form_obj = document.getElementById(form_id)
	
	if(obj&&form_obj){
		obj.value = "delete";
		if(confirm("Are you sure?")){
			form_obj.submit()
		}
	}else{
		mgd_alert("There was a javascript error. Please reload the page!");
	}
}
function mgd_alert(msg){
	
	obj = document.getElementById("alert_msg")
	content_obj = document.getElementById("alert_content")
	
	if(obj&&content_obj){
		content_obj.innerHTML = msg
		obj.style.display = "block"
		setTimeout(function(){document.getElementById("alert_msg").style.display='none'},3000)
	}else{
		alert(msg)
	}
	
}
function refresh_div(id, src_id){
	
	obj = document.getElementById(id)
	obj_src = document.getElementById(src_id)
	if(obj&&obj_src){
		obj.innerHTML = obj_src.innerHTML
	}
	
}