var MM_contentVersion = 4;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

function getFlash(width, height, file, loop, alternate, classid, secure)
{
	var code_base;
	if (secure == 'true') {
		code_base = 'https';
	}
	else {
		code_base = 'http';
	}
	if (MM_FlashCanPlay)
	{
		var oeTags = '<OBJECT CLASSID="' + classid + '"'
         + 'WIDTH="' + width + '" HEIGHT="' + height + '"'
         + 'CODEBASE="' + code_base + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
         + '<PARAM NAME="MOVIE" VALUE="' + file + '">'
         + '<PARAM NAME="PLAY" VALUE="true">'
         + '<PARAM NAME="LOOP" VALUE="' + loop + '">'
         + '<PARAM NAME="QUALITY" VALUE="high">'
         + '<PARAM NAME="MENU" VALUE="false">'
         + '<EMBED SRC="' + file + '"'
         + 'WIDTH="' + width + '" HEIGHT="' + height + '"'
         + 'PLAY="true"'
         + 'LOOP="' + loop + '"'
         + 'QUALITY="high"'
         + 'MENU="false"'
         + 'TYPE="application/x-shockwave-flash"'
         + 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
         + '</EMBED>'
         + '</OBJECT>';
		document.write(oeTags);
	}
	else
	{
		var alternateContent = '<IMG SRC="' + alternate + '" HEIGHT="' + height + '" WIDTH="' + width + '" BORDER="0">'
		document.write(alternateContent);
	}
}

function switchMenu(targetId) {
  if (document.getElementById) {
    target = document.getElementById('menu0');
    target.style.display = "none";
    target = document.getElementById('menu2');
    target.style.display = "none";
    target = document.getElementById('menu3');
    target.style.display = "none";
    target = document.getElementById(targetId);
    target.style.display = "inline";
  }
}

function switchImage(image_id, num_images) {
	if (document.getElementById) {
		for (i=1; i <= num_images; i++) {
			var image = 'image' + i;
			document.getElementById(image).style.display = "none";
		}
		document.getElementById(image_id).style.display = "inline";
	}
}

var imagepopup;
var otherpopup;
function popupView(url, features, popup_type) {
	switch (popup_type) {
		case 'image':
		if (!imagepopup || imagepopup.closed) {
	  		imagepopup = window.open(url,'imagepopup',features);
		} else {
			imagepopup.close();
		    imagepopup = window.open(url, 'imagepopup', features);
		}
		break;
		
		case 'other':
		if (!otherpopup || otherpopup.closed) {
	  		otherpopup = window.open(url,'otherpopup',features);
		} else {
			otherpopup.close();
		    otherpopup = window.open(url, 'otherpopup', features);
		}
		break;
		
		default:
		return false;
		break;
	}	
}

function loadLink(method, region, cat, resource, city) {
	var r;
	if (region == '') {
		return false;
	}
    r = '/location/' + method + '/' + region + '/' + cat;
	if (resource) {
		//alert('here');
		r = r + '/' + resource;
	}
	if (city) {
		r = r + '?city=' + city;
	} else {
		r = r + '/';
	}
	//alert(r);
    document.location.href = r;
}

function setUrl(path, dest) {
	if (dest != '') {
		document.location.href = path + dest;
	}
}

function loadGlobalResourceLink(resource_name, cat) {
	var r;
	r = '/' + resource_name + '/' + cat + '/';
	document.location.href = r;
}

function logClick(evnt, campaign_id) {
    var left = true;
    if ((evnt) && evnt.which) {
        if (evnt.which != 1) {
            left = false;
        }
    }
    else if (event && event.button) {
        if (event.button != 1) {
            left = false;
        }
    }
    if (left) {
		var img = new Image();
		img.src = "/ad/log/" + campaign_id + "/";
    }   
}


function logListingClick(evnt, lid, type, tid1, tid2) {
	var left = true;
    if ((evnt) && evnt.which) {
        if (evnt.which != 1) {
            left = false;
        }
    }
    else if (event && event.button) {
        if (event.button != 1) {
            left = false;
        }
    }
    if (left) {
		var img = new Image();
		img.src = "/listing/log_stat/" + lid + "?type=" + type + "&tid1=" + tid1 + "&tid2=" + tid2;
    }   
}

var cap_incr = 0;
function swapCaptcha(lid) {
	var img = new Image(); 
	img_src = '/captcha/create';
	if (lid) {
		img_src += '/'+lid;
	}
	img_src += '?cap_incr='+cap_incr;
	img.src=img_src;
	$('#captcha').attr('src', img.src);
	cap_incr += 1;
}

function swapIdDisplay(show_me, hide_me, type) {
	if (document.getElementById) {
		if (type != 'inline') {
			type = "";
		}
	    target = document.getElementById(show_me);
	    target.style.display = type;
	    target = document.getElementById(hide_me);
	    target.style.display = "none";
	  }
}

function myRnetReg() {
	subWindow = window.open("/user/signup?p=1", "otherpopup", "height=600,width=700");
}

function setTab(tab_id) {
	$('#subNav'+menu_tab).hide();
	$('#subNav'+tab_id).show();
	menu_tab = tab_id;
}

function setPopupBackground(ele_hide, ele_show) {
	$(ele_hide).hide();
	$(ele_show).show();
	$('.iframe_wrapper').height($('#popupBackground').height()); 
	$('.iframe_wrapper').width($('#popupBackground').width());
	
}

function setR(r, msg) {
	if (!confirm('You must be logged in to ' + msg + '. Click ok to sign in or create an account. It only takes a minute!')) {
    	return false;
   	}
   	$("#popupBackground").show().centerInClient();
	if ($.browser.msie) {
		$('.iframe_wrapper').show();
		$('.iframe_wrapper').height($('#popupBackground').height()); 
	   	$('.iframe_wrapper').width($('#popupBackground').width());
	}
   	$('#signinr').val(r);
   	$('#signupr').val(r);
}

function formatDate(ts) {
	var month=new Array(12);
	month[0]="Jan";
	month[1]="Feb";
	month[2]="Mar";
	month[3]="Apr";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="Aug";
	month[8]="Sept";
	month[9]="Oct";
	month[10]="Nov";
	month[11]="Dec";
	
	var d = new Date();
	d.setTime(ts);
	var date_string = month[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear() + ' ';
	var hours = d.getHours();
	var ampm;
	var min;
	if (hours > 12) {
	  hours = hours % 12;
	  ampm = 'pm';
	} else if(hours < 12) {
	  ampm = 'am';
	  if (hours == 0) {
	    hours = 12;
	  }
	} else {
		ampm = 'pm';
	}
	date_string += hours + ':';
	min = d.getMinutes();
	date_string += (min < 10) ? '0' + min : min;
	date_string += ' ' + ampm;
	return date_string;
}

var editing, editobj, editorg, rurl, classorg;

function editReq(obj, url) {
	//$$('.a_element').hide();
	//alert(obj);
    if (!editing) {
        editing = true;
		$.ajax({
		    url: url,
		    type: 'POST',
		    dataType: 'xml',
		    timeout: 5000,
		    error: function(){
		        alert('Error loading XML document');
		    },
		    success: function(xml){
		        alert('called controller');
		    },
			complete: function(xml){
				alert('complete');
			}
		});
	editing = false;
/*
        if (editobj) {
            $(editobj).setStyle('background-color', '');
            $(editobj.id + '_value').empty();
            $(editobj.id + '_value').innerHTML = editorg;
			$(editobj).removeClass('ajaxBox');
			$(editobj).addClass(classorg);
            makeEditable(editobj);
        }

        editobj = obj;
        editorg = $(obj.id + '_value').innerHTML;
		classorg = $(obj).hasClass('field') ? 'field' : 'box';
        obj.addClass('edit-wait');

		var myRequest = new Request({method: 'post', 
		url: rurl, 
		evalScripts: true,
		timeout: 20000,
		onFailure: function() {
            obj.removeClass('edit-wait');
            alert('There was an error processing your request. Please try again.');
            editing = false;
        }
		}).send('part=' + obj.id);
*/
    }
}

function editPart(action, element, part, html, error, onsubmit_method) {
	var form_html = '<form id="ajax-form" action="' + action + '"><input type="hidden" name="updated" value="1" />';
	if (part) {
		form_html += '<input type="hidden" name="part" value="' + part + '" />';
	}
	if (html) {
		form_html += html;
	}
	form_html += '<div class="topspace"><input id="ajax-save" class="btnAction" style="margin-bottom: 0;" type="submit" value="Save" /> or <input id="ajax-cancel" class="btnCancel" style="margin-bottom: 0;" type="button" value="Cancel" /></div></form>';
	$(element).html(form_html);
	/*
    //$(part).empty();
    $(part).html('<form id="ajax-form" action="' + action + '"><input type="hidden" name="updated" value="1" /><input type="hidden" name="part" value="' + part + '" />'
    + html + '<div class="topspace"><input id="ajax-save" class="btnAction" style="margin-bottom: 0;" type="submit" value="Save" /> or <input id="ajax-cancel" class="btnCancel" style="margin-bottom: 0;" type="button" value="Cancel" /></div></form>');
	*/
}

function showSignin() {
    $("#popupBackground").show().centerInClient();
	if ($.browser.msie) {
		$('.iframe_wrapper').show();
		$('.iframe_wrapper').height($('#popupBackground').height()); 
	   	$('.iframe_wrapper').width($('#popupBackground').width());
	}
}

function deleteConfirm(delete_this) {
  if (!confirm("Are you sure you want to delete this " + delete_this + "?")) {
    return false;
  }
}