var URL = 'http://www.citi-talk.com/';

var map = null;

var geocoder = null;

var marker = null;

var xmlhttp;

function forgotPass(email){
	var url="config/forgot_pass.php?email="+email;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if(xmlhttp.responseText==''){
				$m('reset_title').innerHTML = 'Reset Password Successfull!';
				$m('reset_body').innerHTML = '<br>A new password has sent to your email address, please check your inbox !';
				$m('forgotpass_submit').style.display = 'none';
			}
			else{
				$m('forgotpass_error').style.display = 'block';
				$m('forgotpass_error').innerHTML = xmlhttp.responseText;				
			}
			$m('forgotpass_submit').disabled = false;
			$m('forgotpass_load').innerHTML = '';
		}
		else{
			$m('forgotpass_error').style.display = 'none';
			$m('forgotpass_submit').disabled = true;
			$m('forgotpass_load').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;Saving...';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}

function activeAccount(key, uid){

	var url="config/edit_profile.php?key="+key+"&uid="+uid+"&act=activation";

	url=url+"&sid="+Math.random();

	xmlhttp=GetXmlHttpObject();

	xmlhttp.onreadystatechange=function() {

		if (xmlhttp.readyState==4 && xmlhttp.status==200){

			if(xmlhttp.responseText==''){

				$m('warning_message').style.display = 'block';

  				$m('warning_message').innerHTML = 'Your changes has been saved.';

				$('#warning_message').fadeOut(4000);

				window.location = 'editprofile.php?q=me';

			}else{

				document.getElementById('signup_err').style.display = 'block';

				document.getElementById('signup_err').innerHTML = xmlhttp.responseText;

			}

			$m('submit_activation').disabled = false;

			$m('activation_loading').innerHTML = '';

		}

		else{

			$m('submit_activation').disabled = true;

			$m('activation_loading').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;Saving...';

		}

	}

	xmlhttp.open("GET", url, true);

	xmlhttp.send();

}
function startUpload(form, upload_path, save, width, height){

	var iframe = document.createElement("iframe");

	iframe.setAttribute("id","ajax-temp");

	iframe.setAttribute("name","ajax-temp");

	iframe.setAttribute("width","0");

	iframe.setAttribute("height","0");

	iframe.setAttribute("border","0");

	iframe.setAttribute("style","width: 0; height: 0; border: none;");

	form.parentNode.appendChild(iframe);

	window.frames['ajax-temp'].name="ajax-temp";
	$m('upload_img_loading').style.display = 'block';

	$m('upload_area').style.display = 'none';	

	form.setAttribute("target", 'ajax-temp');

	form.setAttribute("action", 'config/upload.php?upload_path='+upload_path+'&save='+save+'&width='+width+'&height='+height+'&sid='+Math.random());

	form.setAttribute("method","post");

	form.setAttribute("enctype","multipart/form-data");

	form.setAttribute("encoding","multipart/form-data");

	form.submit();

}
function $m(theVar){

	return document.getElementById(theVar)

}
function load_image(path, file_name, divId){

	var x = path.substr(3);
	var width = (divId=='preview_slideshow') ? '100px' : '';

	window.setTimeout("$m('upload_area').style.display = 'block';", 1000);

	window.setTimeout("$m('upload_img_loading').style.display = 'none';", 1000);

	hide_dialog('fade', 'popup_upload_image');

	$m(divId).innerHTML = '<img src='+x+file_name+'?sid='+Math.random()+' width='+width+' />';

}
function signup(username, email, pass, verif_pass){

	document.getElementById('signup_err').style.display = 'none';

	var url="config/signup.php?username="+username+"&email="+email+"&pass="+pass+"&verif="+verif_pass;

	url=url+"&sid="+Math.random();

	xmlhttp=GetXmlHttpObject();

	xmlhttp.onreadystatechange=function() {

		if (xmlhttp.readyState==4 && xmlhttp.status==200){

			if(xmlhttp.responseText==''){

				load_content('thanks', 'slide', '30%', '25%', '35%');

				window.setTimeout("window.location = 'editprofile.php?q=me'", 3000);

			}else{

				document.getElementById('signup_err').style.display = 'block';

				document.getElementById('signup_err').innerHTML = xmlhttp.responseText;

			}

			document.getElementById('signup_submit').disabled = false;

			document.getElementById('signup_load').innerHTML = '';

		}

		else{

			document.getElementById('signup_submit').disabled = true;

			document.getElementById('signup_load').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;Saving...';

		}

	}

	xmlhttp.open("GET", url, true);

	xmlhttp.send();

}
function addComment(id, name, comment, type, title){

	comment = encodeURIComponent(comment);

	var url="config/comment.php?id="+id+"&name="+name+"&comment="+comment+"&type="+type+"&title="+title;

	url=url+"&sid="+Math.random();

	xmlhttp=GetXmlHttpObject();

	if(name == '' || name == 'Your name ...' || comment == '' || comment == 'Write a comment ...'){

		alert('Please give valid details'); 

	}else{

		xmlhttp.onreadystatechange=function() {

			if (xmlhttp.readyState==4 && xmlhttp.status==200){

				document.getElementById('add_'+type+'_comment').disabled =false;

				document.getElementById('toggle').style.display = 'block';

				document.getElementById(type+'_comment').style.display = 'none';

				document.getElementById(type+'_comment').disabled = false;

				document.getElementById(type+'_comment').value = '';

				document.getElementById(type+'_comment_name').disabled = false;

				$("ul#update_comment").prepend(xmlhttp.responseText);

				$("ul#update_comment li:first").fadeIn("slow");

			}

			else{

				document.getElementById('add_'+type+'_comment').disabled = true;

				document.getElementById(type+'_comment_name').disabled = true;

				document.getElementById(type+'_comment').disabled = true;

			}

		}

		xmlhttp.open("GET", url, true);

		xmlhttp.send();

	}

}
function addEvents(id, store_id, name, s_date, s_time, e_date, e_time, cat, where, more, user, is_end_time, act){

	var x;

	more = encodeURIComponent(more);

	if(act=='add' && cat=='News') x = 'f_';

	else if(act=='edit') x = 'e_';

	else x = '';

	var is_end = (is_end_time=='none') ? 0 : 1;
	var url="config/events.php?id="+id+"&store_id="+store_id+"&name="+name+"&s_date="+s_date+"&s_time="+s_time+"&e_date="+e_date+"&e_time="+e_time+"&cat="+cat+"&where="+where+"&more="+more+"&user="+user+"&is_end="+is_end+"&act="+act;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if(xmlhttp.responseText=='')
				window.location = 'events.php?eid='+id;
			else{
				document.getElementById(x+'event_err').style.display = 'block';
				document.getElementById(x+'event_err').innerHTML = xmlhttp.responseText;
			}
			document.getElementById(x+'create_event').disabled = false;
			document.getElementById(x+'event_submit').innerHTML = '';
		}
		else{ 
			document.getElementById(x+'create_event').disabled = true;
			document.getElementById(x+'event_submit').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;Saving...';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
/*function resetAddEvent(){

	document.getElementById('events_upcoming').style.display = 'block';

	document.getElementById('events_detail').style.display = 'none'; 

	document.getElementById('end_date_time').style.display = 'none';   

	document.getElementById('event_err').style.display = 'none'

	document.getElementById('e_name').value='What is your plan ?';

	document.getElementById('e_name').style.color = '#999';

	document.getElementById('e_where').value='Where ?';

	document.getElementById('e_where').style.color = '#999';

	document.getElementById('e_more').value = '';

	document.getElementById('e_more').style.display = 'none';

	document.getElementById('toggle').style.display = 'block';

}*/
function adminContent(term, page){
	var url="config/admin_content.php?term="+term+"&p="+page;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById('load_admin_'+term).innerHTML = '';
			document.getElementById('tab_content_'+term).innerHTML = xmlhttp.responseText;
		}
		else{
			document.getElementById('load_admin_'+term).innerHTML = '<i>Loading..</i>';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
function editPassword(uid, cur_pass, new_pass, verif_pass){
	//alert(cur_pass);
	var url="config/edit_profile.php?uid="+uid+"&cur="+cur_pass+"&new_pass="+new_pass+"&verif_pass="+verif_pass+"&act=password";
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById('warning_message').style.display = 'block';
			document.getElementById('edit_pass_loading').innerHTML = '';
			document.getElementById('warning_message').innerHTML = xmlhttp.responseText;
			document.getElementById('submit_password').disabled = false;
			$("#warning_message").fadeOut(4000);
		}
		else{
			document.getElementById('submit_password').disabled = true;
			document.getElementById('edit_pass_loading').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;&nbsp;Saving...';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
function editProfile(uid, uname, fname, email, bmonth, bdate, byear, bprivacy, sex, sprivacy, loc, web, about, status, role){	

	web = encodeURIComponent(web);

	about = encodeURIComponent(about);	

	var url="config/edit_profile.php?uid="+uid+"&uname="+uname+"&fname="+fname+"&email="+email+"&bmonth="+bmonth+"&bdate="+bdate+"&byear="+byear+"&bprivacy="+bprivacy+"&sex="+sex+"&sprivacy="+sprivacy+"&loc="+loc+"&web="+web+"&about="+about+"&status="+status+"&role="+role+"&act=profile";
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById('warning_message').style.display = 'block';
			document.getElementById('edit_prof_loading').innerHTML = '';
			document.getElementById('warning_message').innerHTML = xmlhttp.responseText;
			document.getElementById('submit_profile').disabled = false;
			$("#warning_message").fadeOut(4000);
		}
		else{
			document.getElementById('submit_profile').disabled = true;
			document.getElementById('edit_prof_loading').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;&nbsp;Saving...';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
function setRSSdefault(type, id){
	var url="config/AjaxDeleteComment.php?id="+id+"&rss_type="+type;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200){
		  alert('This RSS Feed has been set as default');
	  }
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
function addRSS(title, link, type, act){
	var x = (act=='add') ? '' : 'e_';
	link = encodeURIComponent(link);
	var url="config/rss.php?title="+title+"&link="+link+"&type="+type+"&act="+act;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if(xmlhttp.responseText=="") {
				if(act=='add'){
					hide_dialog('fade', 'slide');
					window.location = URL+'category.php?tid='+type;
				}else{
					hide_dialog('fade', 'slide');					
				}
			}
			else{
				document.getElementById(x+'add_rss_error').style.display = 'block';
				document.getElementById(x+'add_rss_error').innerHTML = xmlhttp.responseText;				
			}
			document.getElementById(x+'rss_title').disabled = false;
			document.getElementById(x+'rss_link').disabled = false;
			document.getElementById(x+'rss_type').disabled = false;
			document.getElementById(x+'submit_rss').disabled = false;
		}else{
			document.getElementById(x+'rss_title').disabled = true;
			document.getElementById(x+'rss_link').disabled = true;
			document.getElementById(x+'rss_type').disabled = true;
			document.getElementById(x+'submit_rss').disabled = true;
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}

function load_content(name, id, width, top, left){
	var name = encodeURIComponent(name);
	document.getElementById('fade').style.display = 'block';
	document.getElementById(id).style.display = 'none';
	divId = document.getElementById(id);
	divId.style.width = width;
	divId.style.top = top;	
	divId.style.left = left;	
	var url="config/load_content.php?name="+name+"&id="+id;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			document.getElementById('loading').style.display = 'none';
			divId.style.display = 'block';
			divId.innerHTML = xmlhttp.responseText;			
		}else{
			divId.style.display = 'none';
			document.getElementById('loading').style.display = 'block';
			document.getElementById('loading').innerHTML = 'Loading ...';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}

function addSlide(id, title, teaser, link, act){
	var x = (act=='add') ? '' : 'e_';
	link = encodeURIComponent(link);
	var url="config/slide.php?id="+id+"&title="+title+"&teaser="+teaser+"&link="+link+"&act="+act;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			if(xmlhttp.responseText=="") {
				if(act == 'add'){
					hide_dialog('fade', 'slide');
					window.location = 'index.php';
				}else
					hide_dialog('fade', 'slide');
			}
			else{
				document.getElementById(x+'add_slide_err').style.display = 'block';
				document.getElementById(x+'add_slide_err').innerHTML = xmlhttp.responseText;				
			}
			document.getElementById(x+'submit_slide').disabled = false;
			document.getElementById(x+'ajax_loading').innerHTML = '';			
		}else{		  
			document.getElementById(x+'submit_slide').disabled = true;
			document.getElementById(x+'ajax_loading').innerHTML =  '<img src="images/loading.gif" align="absmiddle">&nbsp;Saving...';
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
function admin_action(id, act, rid){
	var bg = $('tr#user_'+id).css('backgroundColor');
	var url="config/AjaxDeleteComment.php?id="+id+"&act="+act+"&rid="+rid+"&type=admin_act";
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200){
	  	if(act=='delete_user'){
			if(confirm("Are you sure want to delete this user ?"))
				$('div#user_'+id).slideUp('slow', function() {$(this).remove();});
			return false;
		}else if(act=='delete_store'){
			if(confirm("Are you sure want to delete this store ?"))
				$('div#store_'+id).slideUp('slow', function() {$(this).remove();});
			return false;
		}else if(act=='delete_shout'){	
			if(confirm("Are you sure want to delete this shout ?"))
				$('div#shout_'+id).slideUp('slow', function() {$(this).remove();});
			return false;

		}else if(act=='delete_event'){	

			if(confirm("Are you sure want to delete this event ?"))

				$('div#event_'+id).slideUp('slow', function() {$(this).remove();});

		}else if(act=='delete_comment'){	

			if(confirm("Are you sure want to delete this comment ?"))

				$('div#comment_'+id).slideUp('slow', function() {$(this).remove();});

		}else{
			if(bg == 'transparent' || bg == 'white')
				$('tr#user_'+id).css("backgroundColor","#eee");
			else
				$('tr#user_'+id).css("backgroundColor","white");
		}
	  }
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
$(function() {

	$(".delete").click(function() {

		var nid = $(this).attr("id");

		var type = $(".delete_type").attr("id");	

		var dataString = 'nid='+nid+'&type='+type;

		if(confirm("Are you sure want to delete this?")){

			$.ajax({

				type: "POST",

				url: "config/AjaxDeleteComment.php",

				data: dataString,

				cache: false,

				success: function(html){

					$('div#'+nid).slideUp('slow', function() {$(this).remove();});

				}

			});

		}

		return false;

	});

});
$(function() {

	$(".delete_comment").live("click",function() {

		var cid = $(this).attr("id");

		var type = $(".delete_type").attr("id");	

		var dataString = 'cid='+cid;

		if(confirm("Are you sure want to delete this?")){

			$.ajax({

				type: "POST",

				url: "config/AjaxDeleteComment.php",

				data: dataString,

				cache: false,

				success: function(html){

					$('li#'+type+'_'+cid).slideUp('slow', function() {$(this).remove();});

				}

			});

		}

		return false;

	});

});
function editStoreGallery(id){
	q = id;
	chk = document.form_edit_gallery.del;
	rad = document.form_edit_gallery.def;
	del = '';
	def = '';
	if(!rad.length){
		if(rad.checked){
			def += rad.value;
		}
	}else{
		for(var i=0; i<rad.length; i++){
			if(document.form_edit_gallery.def[i].checked){
				def += document.form_edit_gallery.def[i].value;
			}
		}
	}
	if(!chk.length){
		if(chk.checked){
			del += chk.value;
		}
	}else{
		for(var i=0; i<chk.length; i++){
			if(document.form_edit_gallery.del[i].checked){
				del += document.form_edit_gallery.del[i].value + ',';
			}
		}
	}
	var url="config/update_store_gallery.php?id="+q+"&default="+def+"&delete="+del;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200){
		hide_dialog('fade', 'edit_store_gallery');
		window.location = "store.php?sid="+q;
		document.getElementById('submitEditStoreGallery').disabled = false;
		document.getElementById('cancel').disabled = false;
		//document.getElementById('edit_store_gallery_err').innerHTML = xmlhttp.responseText;
	  }else{		  
		document.getElementById('submitEditStoreGallery').disabled = true;
		document.getElementById('cancel').disabled = true;
		document.getElementById('edit_store_gallery_err').innerHTML = 'Please wait ...';
	  }
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}

function addStoreGallery(id){
	q = id;
	var url="config/upload_store_gallery.php?id="+q;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200){
		hide_dialog('fade', 'add_photo_store_gallery');
		window.location = "store.php?sid="+q;
		document.getElementById('submitStoreGallery').disabled = false;
		document.getElementById('cancel').disabled = false;
		document.getElementById('img_gallery').disabled = false;
		document.getElementById("gallery_store_err").style.display = 'none';
	  }else{
		  document.getElementById('submitStoreGallery').disabled = true;
		  document.getElementById('cancel').disabled = true;
		  document.getElementById('img_gallery').disabled = true;
		  document.getElementById("gallery_store_err").innerHTML = 'Please wait ...';
	  }
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}

function getCoordinate(address) {
	geocoder = new GClientGeocoder();
	if (geocoder) {
		geocoder.getLatLng(
		address, function(point) {
				if (point) {
					document.getElementById('lat').value = point.lat();
					document.getElementById('lng').value = point.lng();
				}
			}		
		);
	}
}

function loadStoreMap(lat, lng, id) {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(id));
		//map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		//map.addControl(new GScaleControl());
		map.setUIToDefault();
		//map.addControl(new GOverviewMapControl());
		var point = new GLatLng(lat, lng);
		map.setCenter(point, 15);
		var marker = new GMarker(point, {draggable: false});
		map.addOverlay(marker);
	}
}

function loadEditMap(sid, lat, lng) {
	document.getElementById('lat_edit').value = lat;
	document.getElementById('lng_edit').value = lng;
	document.getElementById('store_id').value = sid;
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById('map_edit'));
		//map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		//map.addControl(new GScaleControl());
		map.setUIToDefault();
		//map.addControl(new GOverviewMapControl());
		var point = new GLatLng(lat, lng);
		map.setCenter(point, 17);
		
		var marker = new GMarker(point, {draggable: true});
		GEvent.addListener(marker, "dragstart", function() {
			map.closeInfoWindow();
		});
		GEvent.addListener(marker, "dragend", function() {
			document.getElementById('lat_edit').value = marker.getPoint().lat();
			document.getElementById('lng_edit').value = marker.getPoint().lng();
		 });
		map.addOverlay(marker);
	}
}
function editMap(id, lat, lng){
	var url="config/edit_store.php?id="+id+"&lat="+lat+"&lng="+lng;
	url=url+"&sid="+Math.random();
	xmlhttp=GetXmlHttpObject();
	xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200){
		hide_dialog('fade', 'suggest_place');
		window.location = "store.php?sid="+id;		
		document.getElementById('lat_edit').disabled = false;
		document.getElementById('lng_edit').disabled = false;
		document.getElementById('cancel').disabled = false;
		document.getElementById('submitEditMap').disabled = false;
	  }else{
		document.getElementById('lat_edit').disabled = true;
		document.getElementById('lng_edit').disabled = true;
		document.getElementById('cancel').disabled = true;
		document.getElementById('submitEditMap').disabled = true;
	  }
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}
//	FOR LOGIN
function login(email, pass){
	xmlhttp=GetXmlHttpObject();
	var url="config/ajax_login.php?email="+email+"&pass="+pass;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=LoginStateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function LoginStateChanged()
{
	if (xmlhttp.readyState==4) {
		if(xmlhttp.responseText=="") {
			hide_dialog('fade', 'login_form');
			window.location = "index.php";	
		}
		else {
			document.getElementById("ajax_err").style.display = 'block';
			document.getElementById("ajax_err").innerHTML = xmlhttp.responseText;
		}
		document.getElementById('email').disabled = false;
		document.getElementById('pass').disabled = false;	
		document.getElementById('submit').disabled = false;	
		document.getElementById('cancel').disabled = false;	
	}else{
		document.getElementById("ajax_err").innerHTML = '<img src='+URL+'/images/loading.gif height=15 width=15 align=absmiddle> loading..';
		document.getElementById('email').disabled = true;
		document.getElementById('pass').disabled = true;	
		document.getElementById('submit').disabled = true;	
		document.getElementById('cancel').disabled = true;	
	}
}
//	END FOR LOGIN
function add_store(id, name, type, addr, text, username){
	type = encodeURIComponent(type);
	username = encodeURIComponent(username);
	var url="config/store.php?id="+id+"&name="+name+"&type="+type+"&addr="+addr+"&text="+text+"&username="+username;

	url=url+"&sid="+Math.random();

	xmlhttp=GetXmlHttpObject();

	xmlhttp.onreadystatechange=function() {

		if (xmlhttp.readyState==4 && xmlhttp.status==200){

			if(xmlhttp.responseText==''){

				window.location = 'store.php?sid='+id;

			}else{

				document.getElementById('add_store_error').style.display = 'block';

				document.getElementById('add_store_error').innerHTML = xmlhttp.responseText;

			}

			document.getElementById('create_store').disabled = false;

			document.getElementById('store_load').innerHTML = '';

		}

		else{

			document.getElementById('create_store').disabled = true;

			document.getElementById('store_load').innerHTML = '<img src="images/loading.gif" align="absmiddle">&nbsp;&nbsp;Saving...';

		}

	}

	xmlhttp.open("GET", url, true);

	xmlhttp.send();

}
function liveEdit(id, field, value, divId, txtId){

	value = encodeURIComponent(value);

	txtId = document.getElementById(txtId);

	divId = document.getElementById(divId);

	if(txtId.style.display == 'none'){

		txtId.style.display = 'block';

		var x = divId.innerHTML;

		x = (txtId==divId) ? '' : x.replace(/<br>/g, "\n");

		txtId.value = x;

		txtId.focus();

		divId.style.display = 'none';

	}else{

		var url="config/live_edit.php?id="+id+"&value="+value+"&field="+field;

		url=url+"&sid="+Math.random();

		xmlhttp=GetXmlHttpObject();

		xmlhttp.onreadystatechange=function() {

		  if (xmlhttp.readyState==4 && xmlhttp.status==200){

		  	txtId.style.display = 'none';

			divId.style.display = 'block';

			if(txtId!=divId){

				var x = txtId.value;

				x = x.replace(/\n/g, "<br>");

				divId.innerHTML = x;

			}

			txtId.disabled = false;

		  }else

		  	txtId.disabled = true;

		}

		xmlhttp.open("GET", url, true);

		xmlhttp.send();

	}

}

//	FOR AUTO SUGGESTION

function autoSuggest(val, table, field, result_id, input_id, field_search){
	rid = result_id;
	iid = input_id;
	xmlhttp=GetXmlHttpObject();
	var url="config/search.php?val="+val+"&table="+table+"&field="+field+"&input_id="+input_id+"&result_id="+result_id+"&field_search="+field_search;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=autoSuggestStateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function autoSuggestStateChanged(){
	if (xmlhttp.readyState==4) {
		e = document.getElementById(rid);
		if(xmlhttp.responseText != "") {
			e.innerHTML = xmlhttp.responseText;
			e.style.display = 'block';			
		}
		document.getElementById(iid).style.background = '';
	}
	else{
		document.getElementById(iid).style.background = 'white url('+URL+'/images/loading.gif) no-repeat right';
		e.style.display = 'none';
	}
}

//	END FOR AUTO SUGGESTION

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	{
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

//	ACORDION
var ContentHeight = 200;
var TimeToSlide = 250.0;
var openAccordion = 1;

function runAccordion(index){
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
   
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "')", 33);
 
  openAccordion = nID;
}

function animate(lastTick, timeLeft, closingId, openingId)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
   
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }
 
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft + ",'"
      + closingId + "','" + openingId + "')", 33);
}

//	FOR TAB
$(document).ready(function() {
	
 //Default Action
 $(".tab_content_most").hide(); //Hide all content
 $(".tab_content_last").hide(); //Hide all content
 $("ul.tabs_most li:first").addClass("active").show(); //Activate first tab
 $("ul.tabs_last li:first").addClass("active").show(); //Activate first tab
 $(".tab_content_most:first").show(); //Show first tab content
 $(".tab_content_last:first").show(); //Show first tab content
 //On Click Event
 $("ul.tabs_most li").click(function() {
	 $("ul.tabs_most li").removeClass("active"); //Remove any "active" class
	 $(this).addClass("active"); //Add "active" class to selected tab
	 $(".tab_content_most").hide(); //Hide all tab content
	 var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
	 $(activeTab).fadeIn(); //Fade in the active content
	 return false;
 });
 //On Click Event
 $("ul.tabs_last li").click(function() {
	 $("ul.tabs_last li").removeClass("active"); //Remove any "active" class
	 $(this).addClass("active"); //Add "active" class to selected tab
	 $(".tab_content_last").hide(); //Hide all tab content
	 var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
	 $(activeTab).fadeIn(); //Fade in the active content
	 return false;
 });
}); 
//	END FOR TAB

$(document).ready(function() {
	$(".edit_profile_form").hide(); //Hide all content
	$("ul.tabs li:first").addClass("leftMenuActiveTab").show(); //Activate first tab
	$(".edit_profile_form:first").show(); //Show first tab content
	
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("leftMenuActiveTab"); //Add "active" class to selected tab
		$(".edit_profile_form").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
}); 
//	FOR SHOUTBOX
$(function() {
	$(".submitShoutbox").click(function() {
		var name = $("#shout_name").val();
		var shout = $("#shout").val();
		var dataString = 'shout_name='+ name + '&shout=' + shout;
		if(name == '' || name == 'Your name ...' || shout == '') alert('Please give valid details');     
		else{ 
			document.getElementById('shout_name').disabled = true;
			document.getElementById('shout').disabled = true;
			document.getElementById('submitShoutbox').disabled = true;
			$.ajax({
			type: "POST",
			url: URL+"/config/shoutbox.php",
			data: dataString,
			cache: false,
				success: function(html){
					document.getElementById('shout_name').disabled = false;

					document.getElementById('shout').disabled = false;

					document.getElementById('submitShoutbox').disabled = false;

					//document.getElementById('shout_name').value = 'Your name ...';			

					document.getElementById('shout_name').style.color = '#959394';

					document.getElementById('shout').value = '';

					document.getElementById('shout').style.display = 'none';

					document.getElementById('toggleShoutbox').style.display = 'block';

					document.getElementById('submitShoutbox').style.display='none';

					$("ol#update").append(html);

					$("ol#update li:last").fadeIn("slow");

				}
			});
		}
	return false;
	});
});
//	END FOR SHOUTBOX

//	RATE
$(document).ready(function(){
	$(".like").click(function(){
		var sid = $(".sid").attr("id");
		var vote = $(this).attr("id");
		//alert(sid);
		//alert(vote);
		var dataString = 'sid='+sid+'&vote='+vote;
		$("#votebox").slideDown("slow");		
		$("#flash").fadeIn("slow");		
		$.ajax({
			type: "POST",
			url: "config/rate.php",
			data: dataString,
			cache: false,
			success: function(html){
				$("#flash").fadeOut("slow");
				$("#rate_content").html(html);
				document.getElementById('').disabled = true;
			}
		});
	});
	// Close button action
	$("#close").click(function(){
		$("#votebox").slideUp("slow");
	});
});

//	END FOR RATE

//	FOR LOGIN
function show_dialog(showId, hideId){
	document.getElementById(showId).style.display = 'block';
	document.getElementById(hideId).style.display = 'block';
}
function hide_dialog(showId, hideId){
	document.getElementById(showId).style.display = 'none';
	document.getElementById(hideId).style.display = 'none';
}
//	END FOR LOGIN//	FOR TOGGLE DISPLAY IN ADD ARTICLE
function toggleDisplay(id_show, id_hide){
	var p = document.getElementById(id_show).style.display;
	if(p == 'block'){
		document.getElementById(id_hide).style.padding = '3px 5px';
		document.getElementById(id_show).style.display = 'none';
	}
	else {
		document.getElementById(id_hide).style.padding = '3px 5px 15px 5px';
		document.getElementById(id_show).style.display = 'block';
	}
}
//	END FOR TOGGLE DISPLAY IN ADD ARTICLE

function showNhide(show, hide){

	document.getElementById(show).style.display = 'block';

	document.getElementById(hide).style.display = 'none';

}
function showEvents(val){
	if(val== 'Events'){
		document.getElementById('event_date_time').style.display = 'block';
	}
	else
		document.getElementById('event_date_time').style.display = 'none';
}
function showSpecialNStore(id, hide, str_1, str_2){
	var q = document.getElementById(id).style.display;
	if(q == 'none'){
		document.getElementById(id).style.display = 'block';
		document.getElementById(hide).innerHTML = str_2;
	}else{
		document.getElementById(id).style.display = 'none';
		document.getElementById(hide).innerHTML = str_1+'<br>';
	}
}

function toggle(id){
	var q = document.getElementById(id).style.display;
	if(q == 'none'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('menu_more').style.background = 'url('+URL+'/images/icon.png) no-repeat 45px -119px';
	}
	else{
		document.getElementById(id).style.display = 'none';
		document.getElementById('menu_more').style.background = 'url('+URL+'/images/icon.png) no-repeat 45px -139px';
	}
}

function showMenuUser(){
	var id = document.getElementById("menu_user").style;
	var my_menu = document.getElementById("my_menu").style;
	if(id.display == 'block'){
		id.display = 'none';
		my_menu.background = 'url('+URL+'images/up_down_cursor.png) no-repeat 73px -48px';
		my_menu.border = 'none';
	}else{
		id.display = 'block';
		my_menu.background = 'white url('+URL+'images/up_down_cursor.png) no-repeat 73px -17px';
		my_menu.borderStyle = 'solid solid none';
		my_menu.borderWidth = '1px 1px 0px';
	}
}

//	ACCORDION MENU
ddaccordion.init({
	headerclass: "accordion_title", //Shared CSS class name of headers group
	contentclass: "accordion_submenu", //Shared CSS class name of contents group
	revealtype: "mouseover", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: true, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
