// JavaScript Document

function findCity(zip) {
	javascript:ajax_loadContent('found-cities','/find-cities.php?zip='+zip,'Searching...');	
}

function searchSite(kw, city, zip) {
	if(!kw.value) return false;
	else {
		javascript:ajax_loadContent('content','/search.php?ajax=1&kw='+kw.value+'&city='+city.value+'&zip='+zip.value,'<div align=center><img src="/images/loading.gif"></div>');	
	}
}

function changeTab(cur) {
	//alert(cur);

	var srch = document.getElementById('search_tab');
	var add_biz = document.getElementById('add_business_tab');
	var register = document.getElementById('register_tab');
	var login = document.getElementById('login_tab');
	
	var srch_action = document.getElementById('search_action');
	var add_action = document.getElementById('add_action');
	var register_action = document.getElementById('register_action');
	var login_action = document.getElementById('login_action');
	
	if(cur=='search') {
		srch.src = 'http://www.losca.com/images/search-on.jpg';
		add_biz.src = 'http://www.losca.com/images/add_your_busines.jpg';
		register.src = 'http://www.losca.com/images/register.jpg';
		login.src = 'http://www.losca.com/images/login.jpg';

		srch_action.style.display = 'block';
		add_action.style.display = 'none';
		register_action.style.display = 'none';
		login_action.style.display = 'none';
		
		return true;
	}
	if(cur=='add') {
		srch.src = 'http://www.losca.com/images/search.jpg';
		add_biz.src = 'http://www.losca.com/images/add_your_busines-on.jpg';
		register.src = 'http://www.losca.com/images/register.jpg';
		login.src = 'http://www.losca.com/images/login.jpg';

		srch_action.style.display = 'none';
		add_action.style.display = 'block';
		register_action.style.display = 'none';
		login_action.style.display = 'none';
		
		return true;
	}
	if(cur=='register') {
		srch.src = 'http://www.losca.com/images/search.jpg';
		add_biz.src = 'http://www.losca.com/images/add_your_busines.jpg';
		register.src = 'http://www.losca.com/images/register-on.jpg';
		login.src = 'http://www.losca.com/images/login.jpg';

		srch_action.style.display = 'none';
		add_action.style.display = 'none';
		register_action.style.display = 'block';
		login_action.style.display = 'none';
		
		return true;
	}
	if(cur=='login') {
		srch.src = 'http://www.losca.com/images/search.jpg';
		add_biz.src = 'http://www.losca.com/images/add_your_busines.jpg';
		register.src = 'http://www.losca.com/images/register.jpg';
		login.src = 'http://www.losca.com/images/login-on.jpg';

		srch_action.style.display = 'none';
		add_action.style.display = 'none';
		register_action.style.display = 'none';
		login_action.style.display = 'block';
		
		return true;
	}

	return true;
}

function hoverTab(cur,action) {
	//alert(cur);

	var srch = document.getElementById('search_tab');
	var add_biz = document.getElementById('add_business_tab');
	var register = document.getElementById('register_tab');
	var login = document.getElementById('login_tab');
	
	if(cur=='search' && srch.src!='http://www.losca.com/images/search-on.jpg' && action=='over') {
		srch.src = 'http://www.losca.com/images/search-hover.jpg';
		return true;
	}
	if(cur=='search' && srch.src!='http://www.losca.com/images/search-on.jpg' && action=='out') {
		srch.src = 'http://www.losca.com/images/search.jpg';
		return true;
	}
	if(cur=='add' && add_biz.src!='http://www.losca.com/images/add_your_busines-on.jpg' && action=='over') {
		add_biz.src = 'http://www.losca.com/images/add_your_busines-hover.jpg';
		return true;
	}
	if(cur=='add' && add_biz.src!='http://www.losca.com/images/add_your_busines-on.jpg' && action=='out') {
		add_biz.src = 'http://www.losca.com/images/add_your_busines.jpg';
		return true;
	}
	if(cur=='register' && register.src!='http://www.losca.com/images/register-on.jpg' && action=='over') {
		register.src = 'http://www.losca.com/images/register-hover.jpg';
		return true;
	}
	if(cur=='register' && register.src!='http://www.losca.com/images/register-on.jpg' && action=='out') {
		register.src = 'http://www.losca.com/images/register.jpg';
		return true;
	}
	if(cur=='login' && login.src!='http://www.losca.com/images/login-on.jpg' && action=='over') {
		login.src = 'http://www.losca.com/images/login-hover.jpg';
		return true;
	}
	if(cur=='login' && login.src!='http://www.losca.com/images/login-on.jpg' && action=='out') {
		login.src = 'http://www.losca.com/images/login.jpg';

		return true;
	}

	return true;
}

function couponDetail(coupon_id) {
	window.open('http://losca.com/coupon_detail.php?id='+coupon_id,'Coupon'+coupon_id, "height=500,width=500,status=no,toolbar=no,menubar=no,location=no");
}

function registerRating(star,business_id) {
	var i = 1;
	for(i=1;i<=star;i++) {
		document.getElementById('star-'+business_id+'-'+i).src="/images/star_yellow.gif";
	}
	for(i=5;i>star;i--) {
		document.getElementById('star-'+business_id+'-'+i).src="/images/star_blue.gif";
	}
	document.getElementById("rating-"+business_id).value = star;
}

function hoverStar(star,action,business_id) {
	var start = 6+business_id.length;
	var id = star.id.substring(start,start+1);
	var rating = document.getElementById("rating-"+business_id).value;
	if(id!=rating) {
		if(action=="over") star.src="/images/star_yellow.gif";
		else star.src = "/images/star_blue.gif";
	}
}

function saveReview(business_id) {
	var url = "/add-review.php?go=1";
	var form = document.getElementById('review_form-'+business_id);
	for(i=0; i<form.elements.length; i++)
	{
		url += "&" + form.elements[i].name + "=" + form.elements[i].value;
	}
	document.getElementById("save-review-"+business_id).style.visibility="visible";
	javascript:ajax_loadContent("save-review-"+business_id,url,"Processing...");	
	form.review.value=''; 
	form.reviewer_name.value=''; 
	registerRating(0,business_id);
}

function editBlurb() {
	document.getElementById('cur-blurb').style.display='none';
	document.getElementById('new-blurb').style.display='inline';
}

function editDisplayName() {
	document.getElementById('cur-displayname').style.display='none';
	document.getElementById('new-displayname').style.display='inline';
}

function editAlbumName(album_id) {
	document.getElementById('album_name_'+album_id).style.display='none';
	document.getElementById('new_album_name_'+album_id).style.display='inline';
}

function editUpdate(update_id) {
	document.getElementById('cur-update-'+update_id).style.display='none';
	document.getElementById('new-update-'+update_id).style.display='inline';
}

function editConfig(update_id) {
	document.getElementById('cur-update-'+update_id).style.display='none';
	document.getElementById('new-update-'+update_id).style.display='inline';
}

function addPeer(user_id) {
	javascript:ajax_loadContent('add-peer','/add-peer.php?user_id='+user_id,'Processing...');	
}

function deletePeer(user_id) {
	if(window.confirm("Are you sure you want to remove this user as a peer?")) {
		javascript:ajax_loadContent('peer-'+user_id,'/delete-peer.php?user_id='+user_id,'Processing...');	
	}
}

function deleteBlog(blog_id) {
	if(window.confirm("Are you sure you want to remove this blog? This can not be undone!")) {
		javascript:ajax_loadContent('blog-'+blog_id,'/delete-blog.php?blog_id='+blog_id,'Deleting...');	
	}
}

function delCategory(category_id) {
	if(window.confirm("Are you sure you want to remove this category and all ads within? This can not be undone!")) {
		javascript:ajax_loadContent('category-'+category_id,'/del-category.php?category_id='+category_id,'Deleting...');	
	}
}

function delGenre(genre_id) {
	if(window.confirm("Are you sure you want to remove this genre? This can not be undone!")) {
		javascript:ajax_loadContent('genre-'+genre_id,'/del-genre.php?genre_id='+genre_id,'Deleting...');	
	}
}

function deleteAd(post_id) {
	if(window.confirm("Are you sure you want to remove this ad? This can not be undone!")) {
		javascript:ajax_loadContent('ad-'+post_id,'/delete-ad.php?post_id='+post_id,'Deleting...');	
	}
}

function deleteEvent(event_id) {
	if(window.confirm("Are you sure you want to remove this event? This can not be undone!")) {
		javascript:ajax_loadContent('event-'+event_id,'/delete-event.php?event_id='+event_id,'Deleting...');	
	}
}

function deletePage(id) {
	if(window.confirm("Are you sure you want to remove this page? This can not be undone!")) {
		javascript:ajax_loadContent('page-'+id,'/delete-page.php?id='+id,'Deleting...');	
	}
}

function deleteAlbum(album_id) {
	if(window.confirm("Are you sure you want to delete this album and all the artwork in it? This can not be undone!")) {
		javascript:ajax_loadContent('album-'+album_id,'/delete-album.php?album_id='+album_id,'Deleting...');	
	}
}

function deletePhoto(photo_id) {
	if(window.confirm("Are you sure you want to delete this image? This can not be undone!")) {
		javascript:ajax_loadContent('photo-'+photo_id,'/delete-photo.php?photo_id='+photo_id,'Deleting...');	
	}
}

function deleteDir(id) {
	if(window.confirm("Are you sure you want to delete this entry? This can not be undone!")) {
		javascript:ajax_loadContent('dir-'+id,'/delete-dir.php?id='+id,'Deleting...');	
	}
}

function loadImage(artwork_id) {
	var collection = document.getElementById('collections_album');
	
	if(collection.value!='0') {
		var user_id = document.getElementById('collections_album').value;
		javascript:ajax_loadContent('featuredArt','/_view_photo.php?collections='+user_id+'&photo='+artwork_id,'Grabbing Media...');	
	}
	else {
		javascript:ajax_loadContent('featuredArt','/_view_photo.php?photo='+artwork_id,'Grabbing Media...');	
	}
}

function loadAlbum(album_id) {
	document.getElementById('my-artwork').className = 'current';
	document.getElementById('my-collection').className = '';
	document.getElementById('my-personal').className = '';
	var viewAll;
	
	if( document.getElementById('view-all').checked == true) {
		viewAll = 1;
	}
	else {
		viewAll = 0;
	}

	javascript:ajax_loadContent('curAlbum','/_album-transition.php?viewall='+viewAll+'&album_id='+album_id,'Getting album...');	
}

function loadPersonalAlbum(album_id) {
	document.getElementById('my-artwork').className = '';
	document.getElementById('my-collection').className = '';
	document.getElementById('my-personal').className = 'current';
	var viewAll;
	
	if( document.getElementById('view-all').checked == true) {
		viewAll = 1;
	}
	else {
		viewAll = 0;
	}

	javascript:ajax_loadContent('curAlbum','/_album-transition.php?viewall='+viewAll+'&album_id='+album_id,'Getting album...');	
}

function loadCollections(user_id) {
	document.getElementById('my-artwork').className = '';
	document.getElementById('my-collection').className = 'current';
	document.getElementById('my-personal').className = '';
	var viewAll;
	
	if( document.getElementById('view-all').checked == true) {
		viewAll = 1;
	}
	else {
		viewAll = 0;
	}

	javascript:ajax_loadContent('curAlbum','/_album-transition.php?viewall='+viewAll+'&album_id=collection&user_id='+user_id,'Getting album...');	
}

function viewAllCurrent() {
	var artwork = document.getElementById('my-artwork');
	var collection = document.getElementById('my-collection');
	var personal = document.getElementById('my-personal');
	
	if(artwork.className=='current') { 
		loadAlbum(document.getElementById('album_id').value);
	}
	if(collection.className=='current') {
		loadCollections(document.getElementById('collections-album').value);
	}
	if(personal.className=='current') {
		loadPersonalAlbum(document.getElementById('personal-album').value);
	}
}

function findFriends() {
	document.getElementById('findfriends-link').style.display = 'none';
	document.getElementById('findfriends-search').style.display = 'inline';
}

function giveStar(artwork_id, user_id) {
	javascript:ajax_loadContent('give-star','/give-star.php?photo='+artwork_id+'&user_id='+user_id,'Incrementing...');	
	document.getElementById('star-count').innerHTML = document.getElementById('star-count-incremented').innerHTML;
}

function addToCollection(artwork_id) {
	javascript:ajax_loadContent('add-to-collection','/add-to-collection.php?photo='+artwork_id,'Adding...');	
}

function addToFeatured(folder_name) {
	javascript:ajax_loadContent('featured-'+folder_name,'/add-to-featured.php?folder_name='+folder_name,'Featuring...');	
}

function featureAlbum(album_id) {
	javascript:ajax_loadContent('album-'+album_id,'/feature-album.php?album_id='+album_id,'Featuring...');	
}

function addToFeaturedDir(id) {
	javascript:ajax_loadContent('dir-'+id,'/add-to-featured-dir.php?id='+id,'Featuring...');	
}

function removeFromCollection(artwork_id) {
	javascript:ajax_loadContent('photo-'+artwork_id,'/remove-from-collection.php?photo='+artwork_id,'Removing...');	
}

function removeFromFeatured(artwork_id) {
	javascript:ajax_loadContent('photo-'+artwork_id,'/remove-from-featured.php?photo='+artwork_id,'Removing...');	
}

function removeFeaturedDir(dir_id) {
	javascript:ajax_loadContent('dir-'+dir_id,'/remove-from-featured-dir.php?dir='+dir_id,'Removing...');	
}

function validate_required(field,alerttxt)
{
with (field)
{
	if (value==null||value=="")
	  {alert(alerttxt);return false;}
	else {return true}
}
}

function validate_form(thisform)
{
	thisform = document.getElementById(thisform);
	with (thisform)
	{
		if (validate_required(email,"Email must be filled out!")==false) {
				email.focus();
				return false;
		}
	}
}

/* Drop down JS */
window.onerror = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var menuActive = 0;
var menuOn = 0;
var onLayer;
var timeOn = null;

function showLayer(layerName,aa){
var x =document.getElementById(aa);
var tt =findPosX(x);
var ww =findPosY(x)+20;

if (timeOn != null) {
clearTimeout(timeOn);
hideLayer(onLayer);
}
if (IE4) {
var layers = eval('document.all["'+layerName+'"].style');
layers.left = tt;
eval('document.all["'+layerName+'"].style.display="block"');
}
else {
if(document.getElementById){
var elementRef = document.getElementById(layerName);
if((elementRef.style)&& (elementRef.style.visibility!=null)){
elementRef.style.display = 'block';
elementRef.style.left = tt;
elementRef.style.top = ww;
}
}
}
onLayer = layerName
}

function hideLayer(layerName){
if (menuActive == 0)
{
if (IE4){
eval('document.all["'+layerName+'"].style.display="none"');
}
else{
if(document.getElementById){
var elementRef = document.getElementById(layerName);
if((elementRef.style)&& (elementRef.style.display!=null)){
elementRef.style.display = 'none';
}
}
}
}
}

function btnTimer() {
timeOn = setTimeout("btnOut()",600)
}

function btnOut(layerName){
if (menuActive == 0){
hideLayer(onLayer)
}
}

var item;
function menuOver(itemName,ocolor){
item=itemName;
itemName.style.backgroundColor = ocolor; //background color change on mouse over
clearTimeout(timeOn);
menuActive = 1
}

function menuOut(itemName,ocolor){
if(item)
itemName.style.backgroundColor = ocolor;
menuActive = 0
timeOn = setTimeout("hideLayer(onLayer)", 100)
}

function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
/* END DROP DOWN JS */