// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function viewDiv(div) {
	document.getElementById(div).style.display="block";
}

function hideDiv(div) {
	document.getElementById(div).style.display="none";
}
function sameBilling() {
	var billingy = document.getElementById("BILLINGY").checked;
	var billingn = document.getElementById("BILLINGN").checked;
	if(billingy == true && billingn == false) {
		var company = document.getElementById("COMPANY").value;
		var contact = document.getElementById("CONTACT").value;
		var address = document.getElementById("ADDRESS").value;
		var address_cont = document.getElementById("ADDRESS2").value;
		var city = document.getElementById("CITY").value;
		var state = document.getElementById("STATE").selectedIndex;
		var zip = document.getElementById("ZIP").value;
		var email = document.getElementById("EMAIL").value;
		var phone1 = document.getElementById('PHONE1').value;
		var phone2 = document.getElementById('PHONE2').value;		
		var phone3 = document.getElementById('PHONE3').value;
		var phone_ext = document.getElementById('PHONE_EXT').value;
		document.getElementById("BILLING_COMPANY").value=company;
		document.getElementById("BILLING_CONTACT").value=contact;
		document.getElementById("BILLING_ADDRESS").value=address;
		document.getElementById("BILLING_ADDRESS2").value=address_cont;
		document.getElementById("BILLING_CITY").value=city;
		document.getElementById("BILLING_STATE").selectedIndex=state;
		document.getElementById("CCZIP").value=zip;
		document.getElementById("BILLING_EMAIL").value=email;
		document.getElementById("BILLINGPHONE1").value=phone1;	
		document.getElementById("BILLINGPHONE2").value=phone2;
		document.getElementById("BILLINGPHONE3").value=phone3;	
		document.getElementById("BILLINGPHONE_EXT").value=phone_ext;
	} else if(billingy == false && billingn == true) {
		document.getElementById("BILLING_COMPANY").value='';
		document.getElementById("BILLING_CONTACT").value='';
		document.getElementById("BILLING_ADDRESS").value='';
		document.getElementById("BILLING_ADDRESS2").value='';
		document.getElementById("BILLING_CITY").value='';
		document.getElementById("BILLING_STATE").selectedIndex='';
		document.getElementById("CCZIP").value='';
		document.getElementById("BILLING_EMAIL").value='';
		document.getElementById("BILLINGPHONE1").value='';	
		document.getElementById("BILLINGPHONE2").value='';
		document.getElementById("BILLINGPHONE3").value='';	
		document.getElementById("BILLINGPHONE_EXT").value='';
	}
}
function sameBillingPublic() {
	var billingy = document.getElementById("BILLINGY").checked;
	var billingn = document.getElementById("BILLINGN").checked;
	if(billingy == true && billingn == false) {
		var company = document.getElementById("COMPANY").value;
		var contact = document.getElementById("CONTACT").value;
		var address = document.getElementById("ADDRESS").value;
		var city = document.getElementById("CITY").value;
		var state = document.getElementById("STATE").selectedIndex;
		var zip = document.getElementById("ZIP").value;
		var email = document.getElementById("EMAILADDRESS").value;
		var phone1 = document.getElementById('PHONE1').value;
		var phone2 = document.getElementById('PHONE2').value;		
		var phone3 = document.getElementById('PHONE3').value;
		var phone_ext = document.getElementById('PHONE_EXT').value;
		document.getElementById("BILLING_COMPANY").value=company;
		document.getElementById("BILLING_CONTACT").value=contact;
		document.getElementById("BILLING_ADDRESS").value=address;
		document.getElementById("BILLING_CITY").value=city;
		document.getElementById("BILLING_STATE").selectedIndex=state;
		document.getElementById("CCZIP").value=zip;
		document.getElementById("BILLING_EMAIL").value=email;
		document.getElementById("BILLINGPHONE1").value=phone1;	
		document.getElementById("BILLINGPHONE2").value=phone2;
		document.getElementById("BILLINGPHONE3").value=phone3;	
		document.getElementById("BILLINGPHONE_EXT").value=phone_ext;
	} else if(billingy == false && billingn == true) {
		document.getElementById("BILLING_COMPANY").value='';
		document.getElementById("BILLING_CONTACT").value='';
		document.getElementById("BILLING_ADDRESS").value='';
		document.getElementById("BILLING_CITY").value='';
		document.getElementById("BILLING_STATE").selectedIndex='';
		document.getElementById("CCZIP").value='';
		document.getElementById("BILLING_EMAIL").value='';
		document.getElementById("BILLINGPHONE1").value='';	
		document.getElementById("BILLINGPHONE2").value='';
		document.getElementById("BILLINGPHONE3").value='';	
		document.getElementById("BILLINGPHONE_EXT").value='';
	}
}
function chooseState() {
	var area = document.getElementById('AREA');
	var billing = document.getElementById('BILLINGCHOICE');
	var defaultn = document.getElementById('DEFAULTN');
	var nationalPricing = document.getElementById('nationalPricing');
	var statePricing = document.getElementById('statePricing');
	if(area.options[area.selectedIndex].value == 'NAT') {
		viewDiv('natDiv');
		hideDiv('stateDiv');
		if(defaultn.checked == true && billing.value == 'lead' && nationalPricing.style.display == 'none') {
			viewDiv('nationalPricing');
			hideDiv('statePricing');
			hideDiv('monthlyPricing');
		} else if(defaultn.checked == true && billing.value == 'month' && nationalPricing.style.display == 'none') {
			hideDiv('nationalPricing');
			hideDiv('statePricing');
			viewDiv('monthlyPricing');
		}
	} else if(area.options[area.selectedIndex].value == 'SBS') {
		hideDiv('natDiv');
		viewDiv('stateDiv');
		if(defaultn.checked == true && billing.value == 'lead' && statePricing.style.display == 'none') {
			viewDiv('statePricing');
			hideDiv('nationalPricing');
			hideDiv('monthlyPricing');
		} else if(defaultn.checked == true && billing.value == 'month' && statePricing.style.display == 'none') {
			hideDiv('nationalPricing');
			hideDiv('statePricing');
			viewDiv('monthlyPricing');
		}
	} else {
		hideDiv('natDiv');
		hideDiv('stateDiv');
	}
}
function enterPricing() {
	var area = document.getElementById('AREA');
	var billing = document.getElementById('BILLINGCHOICE');
	var defaulty = document.getElementById('DEFAULTY').checked;
	var defaultn = document.getElementById('DEFAULTN').checked;
	if(defaulty == true && defaultn == false) {
		hideDiv('nationalPricing');
		hideDiv('statePricing');
		hideDiv('monthlyPricing');
	} else if(defaulty == false && defaultn == true) {
		if(area.value == 'NAT' && billing.value=='lead') {
			viewDiv('nationalPricing');
			hideDiv('statePricing');
			hideDiv('monthlyPricing');
		} else if(area.value == 'SBS' && billing.value=='lead') {
			viewDiv('statePricing');
			hideDiv('nationalPricing');
			hideDiv('monthlyPricing');
		} else if(billing.value=='month') {
			hideDiv('statePricing');
			hideDiv('nationalPricing');
			viewDiv('monthlyPricing');
		}
	} else {
		hideDiv('nationalPricing');
		hideDiv('statePricing');
		hideDiv('monthlyPricing');
	}
}
function doNav(theUrl) {
	document.location.href = theUrl;
}
function showSelected() {
	var selectedStates = $('selectedStates');
	var states = $('STATES[]');
	var stateList = '';
	var x = 0;
	for(i=1;i<=states.length;i++) {
		if(states.options[i].selected == true) {
			if(stateList == '') {
				stateList = states.options[i].value;
			} else {
				stateList = stateList+', '+states.options[i].value;	
			}
			x++;
		}
		var output = stateList+'<br>'+x+' state';
		if(x != 1) {
			output = output+'s';
		}
		output = output+' selected';
		selectedStates.innerHTML = output;
	}
}
function moneyFormat(id) {
	var amount = document.getElementById(id).value;
	if(amount.indexOf(".") == -1) {
		document.getElementById(id).value = amount+'.00';
	}
}
function submitImageForm() {
	var form = parent.document.getElementById("imageForm");
	form.action="franchise_imageupload.php";
	form.target="imageUploadFrame";
	form.submit();	
}
function updateContacted(id) {
	var checked = document.getElementById('contacted'+id).checked;
	if(checked == true) {
		var contacted = 'yes';
	} else {
		var contacted = 'no';
	}
	new Ajax.Request('ajax_leadcontacted.php?id='+id+'&contacted='+contacted+'&table=franchise_requests',
		 {
			method:'get',
			onComplete: function(transport){
			  var response = transport.responseText || "no response text";
			  if(response == 'failed') {
				alert('There was a problem marking this lead contacted.  Please try again.');  
			  }
			},
			onFailure: function(){ alert('There was a problem marking this lead contacted.  Please try again.') }
		  });
}
function updateLeadPaidStatus(id) {
	var checked = document.getElementById('paid'+id).checked;
	if(checked == true) {
		var paid = 'yes';
	} else {
		var paid = 'no';
	}
	new Ajax.Request('ajax_leadpaid.php?id='+id+'&paid='+paid+'&table=franchoice_leads',
		 {
			method:'get',
			onComplete: function(transport){
			  var response = transport.responseText || "no response text";
			  if(response == 'failed') {
				alert('There was a problem marking this lead paid.  Please try again.');  
			  }
			},
			onFailure: function(){ alert('There was a problem marking this lead paid.  Please try again.') }
		  });
}
function updateBizLeadContacted(id) {
	var checked = document.getElementById('contacted'+id).checked;
	if(checked == true) {
		var contacted = 'yes';
	} else {
		var contacted = 'no';
	}
	new Ajax.Request('ajax_leadcontacted.php?id='+id+'&contacted='+contacted+'&table=businesses_leads',
		 {
			method:'get',
			onComplete: function(transport){
			  var response = transport.responseText || "no response text";
			  if(response == 'failed') {
				alert('There was a problem marking this lead contacted.  Please try again.');  
			  }
			},
			onFailure: function(){ alert('There was a problem marking this lead contacted.  Please try again.') }
		  });
}
function showOrdersMenu() {
	var menu = document.getElementById('ordersMenu');
	if(menu.style.display == 'block') {
		hideDiv('ordersMenu');
	} else {
		viewDiv('ordersMenu');	
	}
}
function showAffiliatesMenu() {
	var menu = document.getElementById('affiliatesMenu');
	if(menu.style.display == 'block') {
		hideDiv('affiliatesMenu');
	} else {
		viewDiv('affiliatesMenu');	
	}
}
function changeCursor(tableRow, highLight) {
	if (highLight) {
		tableRow.style.cursor="pointer";
	}
}
function addBookmark() {
	var url = 'http://www.ibizzilla.com';
	var title = 'iBizZilla.com - Get Results...buy and sell a biz here!';
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}
function removeMessage(id) {
	$(id).remove();	
}
function openPhoto(img) {
	window.scrollTo(0,200);
	var w = document.viewport.getWidth();
	var start = w/2;
	var left = start - 350;
	new Effect.Move('loadingFrame',{x:left,y:200,mode:'absolute',duration:0});
	new Effect.SlideDown('loadingFrame',{duration:.5});
	new Ajax.Request('ajax_largeimage.php?img='+img,
		 {
			method:'get',
			onSuccess: function(text){
			  var response = text.responseText || "no response text";
			  document.getElementById('content').innerHTML = response;
				var w = document.viewport.getWidth();
				var start = w/2;
				var left = start - 350;
				new Effect.Move('largePhotoFrame',{x:left,y:200,mode:'absolute',duration:0});
			  document.getElementById('img'+img).onload = function() {
			    new Effect.SlideUp('loadingFrame',{duration:.5});
				new Effect.SlideDown('largePhotoFrame',{queue:'end'});  
			  }
			},
			onFailure: function(){ 
				alert('Something went wrong...')
				new Effect.SlideUp('loadingFrame');
			}
		  });
	return false;
}
function closePhoto() {
	new Effect.SlideUp('largePhotoFrame');
	return false;
}
function openEventPhoto(id) {
	window.scrollTo(0,200);
	var w = document.viewport.getWidth();
	var start = w/2;
	var left = start - 350;
	new Effect.Move('loadingFrame',{x:left,y:200,mode:'absolute',duration:0});
	new Effect.SlideDown('loadingFrame',{duration:.5});
	new Ajax.Request('ajax_largeimage.php?eventid='+id,
		 {
			method:'get',
			onSuccess: function(text){
			  var response = text.responseText || "no response text";
			  document.getElementById('content').innerHTML = response;
				var w = document.viewport.getWidth();
				var start = w/2;
				var left = start - 350;
				new Effect.Move('largePhotoFrame',{x:left,y:200,mode:'absolute',duration:0});
			  document.getElementById('img'+id).onload = function() {
			    new Effect.SlideUp('loadingFrame',{duration:.5});
				new Effect.SlideDown('largePhotoFrame',{queue:'end'});  
			  }
			},
			onFailure: function(){ 
				alert('Something went wrong...')
				new Effect.SlideUp('loadingFrame');
			}
		  });
	return false;
}
function openEventPhotoApproval(id) {
	window.scrollTo(0,200);
	var w = document.viewport.getWidth();
	var start = w/2;
	var left = start - 350;
	new Effect.Move('loadingFrame',{x:left,y:200,mode:'absolute',duration:0});
	new Effect.SlideDown('loadingFrame',{duration:.5});
	new Ajax.Request('ajax_largeimage.php?eventid='+id+'&action=approval',
		 {
			method:'get',
			onSuccess: function(text){
			  var response = text.responseText || "no response text";
			  document.getElementById('content').innerHTML = response;
				var w = document.viewport.getWidth();
				var start = w/2;
				var left = start - 350;
				new Effect.Move('largePhotoFrame',{x:left,y:200,mode:'absolute',duration:0});
			  document.getElementById('img'+id).onload = function() {
			    new Effect.SlideUp('loadingFrame',{duration:.5});
				new Effect.SlideDown('largePhotoFrame',{queue:'end'});  
			  }
			},
			onFailure: function(){ 
				alert('Something went wrong...')
				new Effect.SlideUp('loadingFrame');
			}
		  });
	return false;
}
function getDDCal(id,month,year) {
	if(document.getElementById('cal'+id).style.display == 'none') {
		new Effect.Appear('cal'+id,{duration:.2});
	}
	document.getElementById('cal'+id).innerHTML = '<div id="contentLoading" style="display:none;" align="center"><br>Loading...<br /><br /><img src="images/loader_gray.gif" width="24" height="24" /></div>';
	new Effect.Appear('contentLoading',{duration:.1});
	new Ajax.Request('dd_cal.php?month='+month+'&year='+year+'&id='+id,
		 {
			method:'get',
			onComplete: function(transport){
				new Effect.Fade('contentLoading',{duration:.1});
				var response = transport.responseText || "no response text";
				document.getElementById('cal'+id).innerHTML = response;
				$('innercal'+id).hide();
			  	new Effect.Appear('innercal'+id, { duration:.3, queue: 'end' });
			},
			onFailure: function(){ alert('Something went wrong...Please select a date again.') }
		  });
}
function closeDDCal(id) {
	new Effect.Fade('cal'+id,{duration:.2});
}
function selectDay(id,month,day,year) {
	
	new Effect.Fade('cal'+id,{duration:.2});
	document.getElementById('caldate'+id).value = month+'/'+day+'/'+year;
}
function getDDTime(id,time) {
	if(document.getElementById('time'+id).style.display == 'none') {
		new Effect.Appear('time'+id,{duration:.2});
	}
	document.getElementById('time'+id).innerHTML = '<div id="contentLoading" style="display:none;" align="center"><br>Loading...<br /><br /><img src="images/loader_gray.gif" width="24" height="24" /></div>';
	new Effect.Appear('contentLoading',{duration:.1});
	new Ajax.Request('dd_time.php?time='+time+'&id='+id,
		 {
			method:'get',
			onComplete: function(transport){
				new Effect.Fade('contentLoading',{duration:.1});
				var response = transport.responseText || "no response text";
				document.getElementById('time'+id).innerHTML = response;
				$('innertime'+id).hide();
			  	new Effect.Appear('innertime'+id, { duration:.3, queue: 'end' });
			},
			onFailure: function(){ alert('Something went wrong...Please select a time again.') }
		  });
}
function closeDDTime(id) {
	new Effect.Fade('time'+id,{duration:.2});
}
function selectTime(id) {
	
	new Effect.Fade('time'+id,{duration:.2});
	var sel = $('timeSelector').selectedIndex;
	var time = $('timeSelector').options[sel].text;
	$('timefield'+id).value = time;
}
function submitLoginForm(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
if(keynum == 13) {
document.getElementById('popupLogin').submit();
}
}
function showPopupProfile(id) {
	$('profile'+id).show();
}
function hidePopupProfile(id) {
	$('profile'+id).hide();
}
function toggleBizLoopOptions(id) {
	new Effect.toggle('bloptions'+id,'slide',{duration:.2});
}
function togglePersonalInfo() {
	new Effect.toggle('personalInfo','slide',{duration:.2});
	return false;
}
function toggleAboutMe() {
	new Effect.toggle('aboutMeOpen','slide',{duration:.2});
	if($('aboutMeOpen').style.display != 'none') {
		$('aboutMeToggleLink').innerHTML = 'More';
	} else {
		$('aboutMeToggleLink').innerHTML = 'Close';
	}
	return false;
}
function showMap() {
	$('mapLink').innerHTML = 'Hide Map';
	$('mapLink').href = 'javascript:hideMap();';
	new Effect.SlideDown('mapContainer',{duration:.2});
	closePromo();
	closeNeed();
}
function hideMap() {
	$('mapLink').innerHTML = 'View On Map';
	$('mapLink').href = 'javascript:showMap();';
	 new Effect.SlideUp('mapContainer',{duration:.2});
}
function openPromo() {
	//$('promoShort').hide();
	$('promoFull').show();
	if($('mapLink').innerHTML != 'View On Map') {
		hideMap();
	}
	closeNeed();
}
function closePromo() {
	//$('promoShort').show();
	$('promoFull').hide();
}
function openNeed() {
	$('needFull').show();
	if($('mapLink').innerHTML != 'View On Map') {
		hideMap();
	}
	closePromo();
}
function closeNeed() {
	$('needFull').hide();
}
function openFullPromo(id) {
	$('promoShort'+id).hide();
	$('promoFull'+id).show();
	$('promoLink'+id).innerHTML = 'Hide Promotion';
	$('promoLink'+id).href = 'javascript:closeFullPromo('+id+')';
}
function closeFullPromo(id) {
	$('promoShort'+id).show();
	$('promoFull'+id).hide();
	$('promoLink'+id).innerHTML = 'View / Edit Promotion';
	$('promoLink'+id).href = 'javascript:openFullPromo('+id+')';
}

function openFullPromoPublic(id) {
	$('promoShort'+id).hide();
	$('promoFull'+id).show();
	$('promoLink'+id).innerHTML = 'Hide Promotion';
	$('promoLink'+id).href = 'javascript:closeFullPromoPublic('+id+')';
}
function closeFullPromoPublic(id) {
	$('promoShort'+id).show();
	$('promoFull'+id).hide();
	$('promoLink'+id).innerHTML = 'View Promotion';
	$('promoLink'+id).href = 'javascript:openFullPromoPublic('+id+')';
}
function openFullNeed(id) {
	$('needShort'+id).hide();
	$('needFull'+id).show();
	$('needLink'+id).innerHTML = 'Hide Need';
	$('needLink'+id).href = 'javascript:closeFullNeed('+id+')';
}
function closeFullNeed(id) {
	$('needShort'+id).show();
	$('needFull'+id).hide();
	$('needLink'+id).innerHTML = 'View / Edit Need';
	$('needLink'+id).href = 'javascript:openFullNeed('+id+')';
}

function openFullNeedPublic(id) {
	$('needShort'+id).hide();
	$('needFull'+id).show();
	$('needLink'+id).innerHTML = 'Hide Need';
	$('needLink'+id).href = 'javascript:closeFullNeedPublic('+id+')';
}
function closeFullNeedPublic(id) {
	$('needShort'+id).show();
	$('needFull'+id).hide();
	$('needLink'+id).innerHTML = 'View Need';
	$('needLink'+id).href = 'javascript:openFullNeedPublic('+id+')';
}
function addView(id,type) {
	new Ajax.Request('ajax_promosneedsviews.php?id='+id+'&type='+type,
		 {
			method:'get'
		  });
}
function deleteCareer(id) {
	if(confirm('Are you sure you want to delete this career?')) {
		doNav('admin_careers.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteMeta(id) {
	if(confirm('Are you sure you want to delete this page\'s meta data?')) {
		doNav('admin_meta.php?action=process&section=delete&id='+id);
	}
	return false;
}