var local = "No";

function finishLogin(){
	Modalbox.hide();
	
	is_advertise = window.location.href.indexOf( "advertise" );
	is_events = window.location.href.indexOf( "events" );
	is_listings = window.location.href.indexOf( "listings" );
	//alert( window.location.href + " : " + is_advertise + " " + is_events + " " + is_listings );
	if( ( -1 != is_advertise ) || ( -1 != is_events ) || ( -1 != is_listings ) ){
		window.location.reload();
	}else{
		window.location.href = "my_account.php";
	}
}

function addPicture(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/addpic_processor.php?action=add" : "http://www.ethiopianbiz.com/addpic_processor.php?function=add_pic&action=add";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4){
			if(xmlHttp.responseText=="Yes"){
				document.getElementById( "addpic" ).innerHTML = "<div style='padding-top: 25px;'>You have logged in successfuly. You will momentarily be taken to your account page.</div> <div style='width: 100%; text-align: center' align=center><img src='assets/images/spinner.gif' /></div>";
				//setTimeout( finishLogin, 3000 );
			}else{
				document.getElementById( "info" ).innerHTML = "The file you tried to upload is either in the wrong format or may be too large.";
			}
			//Modalbox.resizeToContent();
		}
	}
	xmlHttp.send( 'picture=' + document.forms['addpicform'].picture.name );
}

function processLogin(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/signin_processor.php?function=auth&action=login" : "http://www.ethiopianbiz.com/signin_processor.php?function=auth&action=login";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4){
			if(xmlHttp.responseText=="Yes"){
				document.getElementById( "signin" ).innerHTML = "<div style='padding-top: 25px;'>You have logged in successfuly. You will momentarily be taken to your account page.</div> <div style='width: 100%; text-align: center' align=center><img src='assets/images/spinner.gif' /></div>";
				setTimeout( finishLogin, 3000 );
			}else{
				document.getElementById( "info" ).innerHTML = "Invalid username or password. Try again!";
			}
			Modalbox.resizeToContent();
		}
	}
	xmlHttp.send( 'username=' + document.forms['signinform'].username.value + '&password=' + document.forms['signinform'].password.value );
}

function processSignup(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/add_biz_listing_processor.php?action=signup" : "http://www.ethiopianbiz.com/add_biz_listing_processor.php?action=signup";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				document.getElementById( "signup" ).innerHTML = "<div>You have successfuly signed up for your FREE EthiopianBiz.com account.<br /><a href=\"javascript:Modalbox.show('signin.php', {title: 'Sign in', width: 400, loadingString: 'Please wait. Loading...'});\">Log in</a> in to your new account.</div>";	
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			//Modalbox.resizeToContent();
		}
	}
	agree = ( true == document.forms['signupform'].agree.checked ) ? "checked" : '';
	
	with( document.forms['signupform'] ){
		if( true == operation_hrs_applicable.checked ){
			if( true == two_hour_sets.checked ){
				operation_hours = "";
				if( true == monday.checked ){
					operation_hours = "Mon: " + mo_a1.value + "-" + mo_a2.value + ", " + mo_b1.value + "-" + mo_b2.value
				}else{
					operation_hours = "Mon: Closed"; 
				}
				if( true == tuesday.checked ){
					operation_hours = operation_hours + ", Tue: " + tu_a1.value + "-" + tu_a2.value + ", " + tu_b1.value + "-" + tu_b2.value
				}else{
					operation_hours = operation_hours + ", Tue: Closed"
				}
				if( true == wednesday.checked ){
					operation_hours = operation_hours + ", Wed: " + we_a1.value + "-" + we_a2.value + ", " + we_b1.value + "-" + we_b2.value
				}else{
					operation_hours = operation_hours + ", Wed: Closed"
				}
				if( true == thursday.checked ){
					operation_hours = operation_hours + ", Thu: " + th_a1.value + "-" + th_a2.value + ", " + th_b1.value + "-" + th_b2.value
				}else{
					operation_hours = operation_hours + ", Thu: Closed"
				}
				if( true == friday.checked ){
					operation_hours = operation_hours + ", Fri: " + fr_a1.value + "-" + fr_a2.value + ", " + fr_b1.value + "-" + fr_b2.value
				}else{
					operation_hours = operation_hours + ", Fri: Closed"
				}
				if( true == saturday.checked ){
					operation_hours = operation_hours + ", Sat: " + sa_a1.value + "-" + sa_a2.value + ", " + sa_b1.value + "-" + sa_b2.value
				}else{
					operation_hours = operation_hours + ", Sat: Closed"
				}
				if( true == sunday.checked ){
					operation_hours = operation_hours + ", Sun: " + su_a1.value + "-" + su_a2.value + ", " + su_b1.value + "-" + su_b2.value
				}else{
					operation_hours = operation_hours + ", Sun: Closed"
				}
			}else{
				operation_hours = "";
				if( true == monday.checked ){
					operation_hours = "Mon: " + mo_a1.value + "-" + mo_a2.value
				}else{
					operation_hours = "Mon: Closed"; 
				}
				if( true == tuesday.checked ){
					operation_hours = operation_hours + ", Tue: " + tu_a1.value + "-" + tu_a2.value
				}else{
					operation_hours = operation_hours + ", Tue: Closed"
				}
				if( true == wednesday.checked ){
					operation_hours = operation_hours + ", Wed: " + we_a1.value + "-" + we_a2.value
				}else{
					operation_hours = operation_hours + ", Wed: Closed"
				}
				if( true == thursday.checked ){
					operation_hours = operation_hours + ", Thu: " + th_a1.value + "-" + th_a2.value
				}else{
					operation_hours = operation_hours + ", Thu: Closed"
				}
				if( true == friday.checked ){
					operation_hours = operation_hours + ", Fri: " + fr_a1.value + "-" + fr_a2.value
				}else{
					operation_hours = operation_hours + ", Fri: Closed"
				}
				if( true == saturday.checked ){
					operation_hours = operation_hours + ", Sat: " + sa_a1.value + "-" + sa_a2.value
				}else{
					operation_hours = operation_hours + ", Sat: Closed"
				}
				if( true == sunday.checked ){
					operation_hours = operation_hours + ", Sun: " + su_a1.value + "-" + su_a2.value
				}else{
					operation_hours = operation_hours + ", Sun: Closed"
				}
			}
		}else{
			operation_hours = "NA";
		}
	}
	
	body = 
		'biz_name=' + document.forms['signupform'].biz_name.value + 
		'&category=' + document.forms['signupform'].category.value + 
		'&street=' + document.forms['signupform'].street.value + 
		'&city=' + document.forms['signupform'].city.value + 
		'&state=' + document.forms['signupform'].state.value + 
		'&zip=' + document.forms['signupform'].zip.value + 
		'&phone=' + document.forms['signupform'].phone.value + 
		'&email_address=' + document.forms['signupform'].email_address.value + 
		'&website=' + document.forms['signupform'].website.value + 
		
		'&operation_hours=' + operation_hours + 
		
		'&username=' + document.forms['signupform'].username.value + 
		'&password=' + document.forms['signupform'].password.value +
		'&confirm_password=' + document.forms['signupform'].confirm_password.value +
		'&agree=' + agree;
	xmlHttp.send( body );
}

function finishAddEvent(){
	Modalbox.hide();
	window.location.href = "my_account.php";
}

function processAddEvent(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/add_event_processor.php?action=submit" : "http://www.ethiopianbiz.com/add_event_processor.php?action=submit";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				document.getElementById( "addeventform" ).innerHTML = "<div style='padding-top: 25px;'>You have successfuly added your event. <br />You will momentarily be taken to your account page page.</div> <div style='width: 100%; text-align: center' align=center><img src='assets/images/spinner.gif' /></div>";
				setTimeout( finishAddEvent, 3000 );
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			Modalbox.resizeToContent();
		}
	}
	if( "No" == document.forms['addeventform'].logged_in.value ){
		auth = '&username=' + document.forms['addeventform'].username.value + '&password=' + document.forms['addeventform'].password.value;
	}else{
		auth = '';
	}
	body = 
		'logged_in=' + document.forms['addeventform'].logged_in.value +
		'&event_name=' + document.forms['addeventform'].event_name.value + 
		'&host=' + document.forms['addeventform'].host.value + 
		'&start_month=' + document.forms['addeventform'].start_month.value + 
		'&start_day_of_month=' + document.forms['addeventform'].start_day_of_month.value + 
		'&start_year=' + document.forms['addeventform'].start_year.value + 
		'&start_hour=' + document.forms['addeventform'].start_hour.value + 
		'&start_minute=' + document.forms['addeventform'].start_minute.value + 
		'&start_ampm=' + document.forms['addeventform'].start_ampm.value + 
		'&end_month=' + document.forms['addeventform'].end_month.value + 
		'&end_day_of_month=' + document.forms['addeventform'].end_day_of_month.value + 
		'&end_year=' + document.forms['addeventform'].end_year.value + 
		'&end_hour=' + document.forms['addeventform'].end_hour.value + 
		'&end_minute=' + document.forms['addeventform'].end_minute.value + 
		'&end_ampm=' + document.forms['addeventform'].end_ampm.value + 
		'&street=' + document.forms['addeventform'].street.value + 
		'&city=' + document.forms['addeventform'].city.value + 
		'&state=' + document.forms['addeventform'].state.value + 
		'&zip=' + document.forms['addeventform'].zip.value + 
		'&phone=' + document.forms['addeventform'].phone.value + 
		'&message=' + document.forms['addeventform'].message.value +
		auth +
		'&biz_id=' + document.forms['addeventform'].biz_id.value;
	xmlHttp.send( body );
}

function finishAddGenListing(){
	Modalbox.hide();
	window.location.href = "my_account.php";
}

function processAddGenListing(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/add_gen_listing_processor.php?action=add" : "http://www.ethiopianbiz.com/add_gen_listing_processor.php?action=add";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				document.getElementById( "add_gen_listing" ).innerHTML = "<div>You have successfuly posted your listing.<br />You will momentarily be taken to your account page.</div> <div style='width: 100%; text-align: center' align=center><img src='assets/images/spinner.gif' /></div>";
				setTimeout( finishAddGenListing, 3000 );
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			Modalbox.resizeToContent();
		}
	}
	//agree = ( true == document.forms['addgenlistingform'].agree.checked ) ? "checked" : '';
	if( "No" == document.forms['addgenlistingform'].logged_in.value ){
		auth = '&username=' + document.forms['addgenlistingform'].username.value + '&password=' + document.forms['addgenlistingform'].password.value;
	}else{
		auth = '';
	}
	body = 
		'logged_in=' + document.forms['addgenlistingform'].logged_in.value +
		'&listing_name=' + document.forms['addgenlistingform'].listing_name.value + 
		'&category=' + document.forms['addgenlistingform'].category.value + 
		'&city=' + document.forms['addgenlistingform'].city.value + 
		'&state=' + document.forms['addgenlistingform'].state.value + 
		'&zip=' + document.forms['addgenlistingform'].zip.value + 
		'&description=' + document.forms['addgenlistingform'].description.value + 
		'&phone=' + document.forms['addgenlistingform'].phone.value + 
		'&email_address=' + document.forms['addgenlistingform'].email_address.value + 
		'&website=' + document.forms['addgenlistingform'].website.value + 
		auth +
		'&biz_id=' + document.forms['addgenlistingform'].biz_id.value;
	xmlHttp.send( body );
}

function semicolonize( str ){
	if( "" == str ){
		return '';
	}else
		return str + '; ';
}

function formatOH( day1, day2, hour1, hour2 ){
	if( "Closed" != hour1 ){
		return day1 + ' - ' + day2 + ', ' + hour1 + ' - ' + hour2;
	}else{
		if( day1 != day2 ){
			return day1 + ' - ' + day2 + ', ' + "Closed";
		}else{
			return day1 + ', ' + "Closed";
		}
	}
}

function processForgotPassword(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/forgot_password_processor.php" : "http://www.ethiopianbiz.com/forgot_password_processor.php";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4){
			document.getElementById( "info" ).innerHTML = xmlHttp.responseText;
			if( "Your" == xmlHttp.responseText.substr( 0, 4 ) ){
				document.getElementById( "forgot_table" ).style.display = 'none';
			}
			Modalbox.resizeToContent();
		}
	}
	xmlHttp.send( 'email_address=' + document.forms['forgotpasswordform'].email_address.value );
	document.getElementById( "info" ).innerHTML = "Please wait while your request is being processed... ";
}

function finishUpdate(){
	window.location.href = "my_account.php";
}

function processUpdate(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/update_biz_listing_processor.php?action=update" : "http://www.ethiopianbiz.com/update_biz_listing_processor.php?action=update";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				document.getElementById( "info" ).innerHTML = "Your business detail has been successfuly updated.";
				//setTimeout( finishUpdate, 3000 );
				finishUpdate();
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			//Modalbox.resizeToContent();
		}
	}
	operation_hours = "";
	if( false == document.forms['updateform'].dont_change_hours.checked ){
		if( false == document.forms['updateform'].operation_hrs_applicable.checked ){	
			with( document.forms['updateform'] ){
				if( true == two_hour_sets.checked ){
					operation_hours = "";
					if( true == monday.checked ){
						operation_hours = "Mon: " + mo_a1.value + "-" + mo_a2.value + " and " + mo_b1.value + "-" + mo_b2.value
					}else{
						operation_hours = "Mon: Closed"; 
					}
					if( true == tuesday.checked ){
						operation_hours = operation_hours + ", Tue: " + tu_a1.value + "-" + tu_a2.value + " and " + tu_b1.value + "-" + tu_b2.value
					}else{
						operation_hours = operation_hours + ", Tue: Closed"
					}
					if( true == wednesday.checked ){
						operation_hours = operation_hours + ", Wed: " + we_a1.value + "-" + we_a2.value + " and " + we_b1.value + "-" + we_b2.value
					}else{
						operation_hours = operation_hours + ", Wed: Closed"
					}
					if( true == thursday.checked ){
						operation_hours = operation_hours + ", Thu: " + th_a1.value + "-" + th_a2.value + " and " + th_b1.value + "-" + th_b2.value
					}else{
						operation_hours = operation_hours + ", Thu: Closed"
					}
					if( true == friday.checked ){
						operation_hours = operation_hours + ", Fri: " + fr_a1.value + "-" + fr_a2.value + " and " + fr_b1.value + "-" + fr_b2.value
					}else{
						operation_hours = operation_hours + ", Fri: Closed"
					}
					if( true == saturday.checked ){
						operation_hours = operation_hours + ", Sat: " + sa_a1.value + "-" + sa_a2.value + " and " + sa_b1.value + "-" + sa_b2.value
					}else{
						operation_hours = operation_hours + ", Sat: Closed"
					}
					if( true == sunday.checked ){
						operation_hours = operation_hours + ", Sun: " + su_a1.value + "-" + su_a2.value + " and " + su_b1.value + "-" + su_b2.value
					}else{
						operation_hours = operation_hours + ", Sun: Closed"
					}
				}else{
					operation_hours = "";
					if( true == monday.checked ){
						operation_hours = "Mon: " + mo_a1.value + "-" + mo_a2.value
					}else{
						operation_hours = "Mon: Closed"; 
					}
					if( true == tuesday.checked ){
						operation_hours = operation_hours + ", Tue: " + tu_a1.value + "-" + tu_a2.value
					}else{
						operation_hours = operation_hours + ", Tue: Closed"
					}
					if( true == wednesday.checked ){
						operation_hours = operation_hours + ", Wed: " + we_a1.value + "-" + we_a2.value
					}else{
						operation_hours = operation_hours + ", Wed: Closed"
					}
					if( true == thursday.checked ){
						operation_hours = operation_hours + ", Thu: " + th_a1.value + "-" + th_a2.value
					}else{
						operation_hours = operation_hours + ", Thu: Closed"
					}
					if( true == friday.checked ){
						operation_hours = operation_hours + ", Fri: " + fr_a1.value + "-" + fr_a2.value
					}else{
						operation_hours = operation_hours + ", Fri: Closed"
					}
					if( true == saturday.checked ){
						operation_hours = operation_hours + ", Sat: " + sa_a1.value + "-" + sa_a2.value
					}else{
						operation_hours = operation_hours + ", Sat: Closed"
					}
					if( true == sunday.checked ){
						operation_hours = operation_hours + ", Sun: " + su_a1.value + "-" + su_a2.value
					}else{
						operation_hours = operation_hours + ", Sun: Closed"
					}
				}
			}
		}else{
			operation_hours = "NA";	
		}
	}
	body = 
		'biz_name=' + document.forms['updateform'].biz_name.value + 
		'&category=' + document.forms['updateform'].category.value + 
		'&street=' + document.forms['updateform'].street.value + 
		'&city=' + document.forms['updateform'].city.value + 
		'&state=' + document.forms['updateform'].state.value + 
		'&zip=' + document.forms['updateform'].zip.value + 
		'&phone=' + document.forms['updateform'].phone.value + 
		'&email_address=' + document.forms['updateform'].email_address.value + 
		'&website=' + document.forms['updateform'].website.value + 
		'&dont_change_hours=' + document.forms['updateform'].dont_change_hours.checked + 
		'&operation_hours=' + operation_hours +
		'&username=' + document.forms['updateform'].username.value;
	xmlHttp.send( body );
}

/*function processGenListingAuth(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/edit_gen_listing_processor.php?action=login" : "http://www.ethiopianbiz.com/auth.php?function=auth&action=login";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4){
			if(xmlHttp.responseText == "Yes"){
				//document.getElementById( "signin" ).innerHTML = "<div style='padding-top: 25px;'>You have signed in successfuly. You will momentarily be taken to your account page.</div> <div style='width: 100%; text-align: center' align=center><img src='assets/images/spinner.gif' /></div>";
				//setTimeout( finishLogin, 3000 );
				Modalbox.show( 'edit_gen_listing.php', {title: 'Edit Listing', params: Form.serialize('genlistingauthform'), method: 'post', width: 510, loadingString: 'Please wait. Loading...'} );
			}else{
				document.getElementById( "info" ).innerHTML = "Invalid password. Try again!";
			}
		}
	}
	xmlHttp.send( 'id=' + document.forms['genlistingauthform'].id.value + '&password=' + document.forms['genlistingauthform'].password.value );
	document.getElementById( "info" ).innerHTML = "Please wait while your request is being processed...";
}*/

function processEditGenListing(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/edit_gen_listing_processor.php?action=update" : "http://www.ethiopianbiz.com/edit_gen_listing_processor.php?action=update";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				//document.getElementById( "add_gen_listing" ).innerHTML = "<div>You have successfuly signed up for your FREE EthiopianBiz account.<br /><a href=\"javascript:Modalbox.show('signin.php', {title: 'Sign in', width: 400, loadingString: 'Please wait. Loading...'});\">Login</a> in to your new account or <a href='javascript:Modalbox.hide();'>continue</a>.</div>";
				document.getElementById( "info" ).innerHTML = "The listing was successfuly updated.";
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			Modalbox.resizeToContent();
		}
	}
	body = 
		'listing_name=' + document.forms['editgenlistingform'].listing_name.value + 
		'&category=' + document.forms['editgenlistingform'].category.value + 
		'&city=' + document.forms['editgenlistingform'].city.value + 
		'&state=' + document.forms['editgenlistingform'].state.value + 
		'&zip=' + document.forms['editgenlistingform'].zip.value + 
		'&description=' + document.forms['editgenlistingform'].description.value + 
		'&phone=' + document.forms['editgenlistingform'].phone.value + 
		'&email_address=' + document.forms['editgenlistingform'].email_address.value + 
		'&website=' + document.forms['editgenlistingform'].website.value +
		'&id=' + document.forms['editgenlistingform'].id.value;
	xmlHttp.send( body );
}

function processEditEvent(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/edit_event_processor.php?action=update" : "http://www.ethiopianbiz.com/edit_event_processor.php?action=update";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				//document.getElementById( "add_gen_listing" ).innerHTML = "<div>You have successfuly signed up for your FREE EthiopianBiz account.<br /><a href=\"javascript:Modalbox.show('signin.php', {title: 'Sign in', width: 400, loadingString: 'Please wait. Loading...'});\">Login</a> in to your new account or <a href='javascript:Modalbox.hide();'>continue</a>.</div>";
				document.getElementById( "info" ).innerHTML = "The event was successfuly updated.";
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			Modalbox.resizeToContent();
		}
	}
	body = 
		'event_name=' + document.forms['editeventform'].event_name.value + 
		'&host=' + document.forms['editeventform'].host.value + 
		'&start_month=' + document.forms['editeventform'].start_month.value + 
		'&start_day_of_month=' + document.forms['editeventform'].start_day_of_month.value + 
		'&start_year=' + document.forms['editeventform'].start_year.value + 
		'&start_hour=' + document.forms['editeventform'].start_hour.value + 
		'&start_minute=' + document.forms['editeventform'].start_minute.value + 
		'&start_ampm=' + document.forms['editeventform'].start_ampm.value + 
		'&end_month=' + document.forms['editeventform'].end_month.value + 
		'&end_day_of_month=' + document.forms['editeventform'].end_day_of_month.value + 
		'&end_year=' + document.forms['editeventform'].end_year.value + 
		'&end_hour=' + document.forms['editeventform'].end_hour.value + 
		'&end_minute=' + document.forms['editeventform'].end_minute.value + 
		'&end_ampm=' + document.forms['editeventform'].end_ampm.value + 
		'&street=' + document.forms['editeventform'].street.value + 
		'&city=' + document.forms['editeventform'].city.value + 
		'&state=' + document.forms['editeventform'].state.value + 
		'&zip=' + document.forms['editeventform'].zip.value + 
		'&phone=' + document.forms['editeventform'].phone.value + 
		'&message=' + document.forms['editeventform'].message.value +
		'&id=' + document.forms['editeventform'].id.value;
	xmlHttp.send( body );
}

function popup( URL, title, w, h ){
	if (w == null) {
		w = 600;
	}
	if (h == null) {
		h = 400;
	}
	eval( "window.open( URL, '" + title + "', 'toolbar = 0, scrollbars = 1, location = 0, statusbar = 0, menubar = 0, resizable = 1, width = " + w + ", height = " + h + "' ); " );
}

function citify( theform ){
	state_list = document.forms[ theform ].state;
	selected_state = state_list.options[ state_list.selectedIndex ].value;	
	city_list = document.forms[ theform ].city;
	n_cities = city_list.length;
	for( i = n_cities - 1; i >= 0; i-- ){
		city_list.remove( i );	
	}
	
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/citify.php" : "http://www.ethiopianbiz.com/citify.php";
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response_arr = xmlHttp.responseText.split( "|" );
			if( response_arr[ 0 ] == "Ok" ){
				city_list.options[ city_list.options.length ] = new Option( "Select a city", "" );
				for( i = 1; i < response_arr.length; i++ ){
					city_list.options[ city_list.options.length ] = new Option( response_arr[ i ], response_arr[ i ] );
				}
			}else{
				city_list.options[ city_list.options.length ] = new Option( response_arr[ 1 ], "" );
			}
			//Modalbox.resizeToContent();
		}
	}
	xmlHttp.send( 'state=' + selected_state );
}

function citify_sync( theform ){
	state_list = document.forms[ theform ].state;
	selected_state = state_list.options[ state_list.selectedIndex ].value;	
	city_list = document.forms[ theform ].city;
	n_cities = city_list.length;
	for( i = n_cities - 1; i >= 0; i-- ){
		city_list.remove( i );	
	}
	
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/citify.php" : "http://www.ethiopianbiz.com/citify.php";
	xmlHttp.open('POST', strURL, false);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send( 'state=' + selected_state );
	
	//xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response_arr = xmlHttp.responseText.split( "|" );
			if( response_arr[ 0 ] == "Ok" ){
				city_list.options[ city_list.options.length ] = new Option( "Select a city", "" );
				for( i = 1; i < response_arr.length; i++ ){
					city_list.options[ city_list.options.length ] = new Option( response_arr[ i ], response_arr[ i ] );
				}
			}else{
				city_list.options[ city_list.options.length ] = new Option( response_arr[ 1 ], "" );
			}
		}
	//}
	
}

function processIndividualSignup(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/add_biz_listing_processor.php?action=individual_signup" : "http://www.ethiopianbiz.com/add_biz_listing_processor.php?action=individual_signup";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				Modalbox.title = "Thank you for signing up!";
				document.getElementById( "signup" ).innerHTML = "<div>You have successfuly signed up for your FREE EthiopianBiz.com account.<br /><a href=\"javascript:Modalbox.show('signin.php', {title: 'Login', width: 400, loadingString: 'Please wait. Loading...'});\">Log in</a> in to your new account.</div>";
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			Modalbox.resizeToContent();
		}
	}
	agree = ( true == document.forms['signupform'].agree.checked ) ? "checked" : '';
	body = 
		'biz_name=' + document.forms['signupform'].biz_name.value + 
		'&email_address=' + document.forms['signupform'].email_address.value + 
		'&username=' + document.forms['signupform'].username.value + 
		'&password=' + document.forms['signupform'].password.value +
		'&confirm_password=' + document.forms['signupform'].confirm_password.value +
		'&agree=' + agree;
	xmlHttp.send( body );
}

function processIndividualUpdate(){
	strURL = "Yes" == local ? "http://localhost/ethiopianbiz/update_biz_listing_processor.php?action=individual_update" : "http://www.ethiopianbiz.com/update_biz_listing_processor.php?action=individual_update";
	if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
		var xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){ // For Internet Explorer
		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlHttp.open('POST', strURL, true);
	xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
	xmlHttp.onreadystatechange = function(){
		if( xmlHttp.readyState == 4 ){
			response = xmlHttp.responseText;
			response_arr = response.split( "|" );
			if( response_arr[ 0 ] == "Yes" ){
				document.getElementById( "info" ).innerHTML = "Your detail has been successfuly updated.";
				//setTimeout( finishUpdate, 3000 );
				finishUpdate();
			}else{
				document.getElementById( "info" ).innerHTML = response_arr[ 1 ];
				for( i = 2; i < response_arr.length; i++ ){
					error = response_arr[ i ].split( "-" );
					eltError = document.getElementById( error[ 0 ] );
					if( "ok" == error[ 1 ] ){
						eltError.innerHTML = '';
						eltError.className = '';
					}else{
						eltError.innerHTML = error[ 1 ];
						eltError.className = "info";
					}
				}
			}
			Modalbox.resizeToContent();
		}
	}
	body = 
		'biz_name=' + document.forms['updateform'].biz_name.value + 
		'&email_address=' + document.forms['updateform'].email_address.value + 
		'&username=' + document.forms['updateform'].username.value;
	xmlHttp.send( body );
}

function individual_form(){
	//document.forms[ 'signupform' ].category.disabled = true;
	document.getElementById( 'biz_name_label' ).style.display = 'none';
	document.getElementById( 'indi_name_label' ).style.display = '';
	document.getElementById( 'category_row' ).style.display = 'none';
	//document.forms[ 'signupform' ].street.disabled = true;
	document.getElementById( 'street_row' ).style.display = 'none';
	//document.forms[ 'signupform' ].state.disabled = true;
	document.getElementById( 'state_row' ).style.display = 'none';
	//document.forms[ 'signupform' ].city.disabled = true;
	document.getElementById( 'city_row' ).style.display = 'none';	
	//document.forms[ 'signupform' ].zip.disabled = true;
	document.getElementById( 'zip_row' ).style.display = 'none';
	//document.forms[ 'signupform' ].phone.disabled = true;
	document.getElementById( 'phone_row' ).style.display = 'none';
	//document.forms[ 'signupform' ].email_address.disabled = true;
	//document.forms[ 'signupform' ].website.disabled = true;
	document.getElementById( 'website_row' ).style.display = 'none';
	//document.forms[ 'signupform' ].day1.disabled = true;
	//document.forms[ 'signupform' ].day2.disabled = true;
	//document.forms[ 'signupform' ].hour1.disabled = true;
	//document.forms[ 'signupform' ].hour2.disabled = true;
	//document.forms[ 'signupform' ].operation_hours.disabled = true;
	//document.forms[ 'signupform' ].plus.style.display = 'none';
	document.getElementById( 'operation_hours_row' ).style.display = 'none';
		
	//document.forms[ 'signupform' ].biz_name.style.backgroundColor = '#FFFF66';
	//document.forms[ 'signupform' ].username.style.backgroundColor = '#FFFF66';
	//document.forms[ 'signupform' ].password.style.backgroundColor = '#FFFF66';
	//document.forms[ 'signupform' ].confirm_password.style.backgroundColor = '#FFFF66';
	//Modalbox.resizeToContent();
}

function biz_form(){
	/*document.forms[ 'signupform' ].category.disabled = false;
	document.forms[ 'signupform' ].street.disabled = false;
	document.forms[ 'signupform' ].state.disabled = false;
	document.forms[ 'signupform' ].city.disabled = false;
	document.forms[ 'signupform' ].zip.disabled = false;
	document.forms[ 'signupform' ].phone.disabled = false;
	document.forms[ 'signupform' ].email_address.disabled = false;
	document.forms[ 'signupform' ].website.disabled = false;
	document.forms[ 'signupform' ].day1.disabled = false;
	document.forms[ 'signupform' ].day2.disabled = false;
	document.forms[ 'signupform' ].hour1.disabled = false;
	document.forms[ 'signupform' ].hour2.disabled = false;
	document.forms[ 'signupform' ].operation_hours.disabled = false;
	document.forms[ 'signupform' ].plus.style.display = '';
	
	document.forms[ 'signupform' ].biz_name.style.backgroundColor = '#FFFFFF';
	document.forms[ 'signupform' ].username.style.backgroundColor = '#FFFFFF';
	document.forms[ 'signupform' ].password.style.backgroundColor = '#FFFFFF';
	document.forms[ 'signupform' ].confirm_password.style.backgroundColor = '#FFFFFF';*/
	document.getElementById( 'biz_name_label' ).style.display = '';
	document.getElementById( 'indi_name_label' ).style.display = 'none';
	document.getElementById( 'category_row' ).style.display = '';
	document.getElementById( 'street_row' ).style.display = '';
	document.getElementById( 'state_row' ).style.display = '';
	document.getElementById( 'city_row' ).style.display = '';	
	document.getElementById( 'zip_row' ).style.display = '';
	document.getElementById( 'phone_row' ).style.display = '';
	document.getElementById( 'website_row' ).style.display = '';
	document.getElementById( 'operation_hours_row' ).style.display = '';
	//Modalbox.resizeToContent();
}

function hour_sets(){
	if( true == document.getElementById( 'two_hour_sets' ).checked ){
		if( true == document.getElementById( 'monday' ).checked ){ document.getElementById( 'monday_extra' ).style.display = ''; }
		if( true == document.getElementById( 'tuesday' ).checked ){ document.getElementById( 'tuesday_extra' ).style.display = ''; }
		if( true == document.getElementById( 'wednesday' ).checked ){ document.getElementById( 'wednesday_extra' ).style.display = ''; }
		if( true == document.getElementById( 'thursday' ).checked ){ document.getElementById( 'thursday_extra' ).style.display = ''; }
		if( true == document.getElementById( 'friday' ).checked ){ document.getElementById( 'friday_extra' ).style.display = ''; }
		if( true == document.getElementById( 'saturday' ).checked ){ document.getElementById( 'saturday_extra' ).style.display = ''; }
		if( true == document.getElementById( 'sunday' ).checked ){ document.getElementById( 'sunday_extra' ).style.display = ''; }
	}else{
		document.getElementById( 'monday_extra' ).style.display = 'none';
		document.getElementById( 'tuesday_extra' ).style.display = 'none';
		document.getElementById( 'wednesday_extra' ).style.display = 'none';
		document.getElementById( 'thursday_extra' ).style.display = 'none';
		document.getElementById( 'friday_extra' ).style.display = 'none';
		document.getElementById( 'saturday_extra' ).style.display = 'none';
		document.getElementById( 'sunday_extra' ).style.display = 'none';
	}
	/*jQuery(function(){
		$("#mo_b1, #mo_b2, #tu_b1, #tu_b2, #we_b1, #we_b2, #th_b1, #th_b2, #fr_b1, #fr_b2, #sa_b1, #sa_b2, #su_b1, #su_b2" ).timePicker({startTime:new Date(0, 0, 0, 0, 0, 0), endTime:new Date(0, 0, 0, 23, 30, 0), show24Hours:false, separator:':', step: 15});
	});*/
}

function each_day( day ){
	if( true == document.getElementById( day ).checked ){
		document.getElementById( day + '_main' ).style.display = '';
		document.getElementById( day + '_alt' ).style.display = 'none';
		if( true == document.getElementById( 'two_hour_sets' ).checked ){
			document.getElementById( day + '_extra' ).style.display = '';
		}else{
			document.getElementById( day + '_extra' ).style.display = 'none';
		}
	}else{
		document.getElementById( day + '_main' ).style.display = 'none';
		document.getElementById( day + '_alt' ).style.display = '';
		if( true == document.getElementById( 'two_hour_sets' ).checked ){
			document.getElementById( day + '_extra' ).style.display = 'none';
		}
	}
}

function oper_hrs(){
	if( true == document.getElementById( "operation_hrs_applicable" ).checked ){
		document.getElementById( "ohr_table" ).style.display = '';
	}else{
		document.getElementById( "ohr_table" ).style.display = 'none';
	}
}

function show_oper_hrs_editor(){
	if( true == document.getElementById( "dont_change_hours" ).checked ){
		document.getElementById( "modify_hours" ).style.display = 'none';
	}else{
		document.getElementById( "modify_hours" ).style.display = '';
	}
}