var site = "" + location.href;

if(site.indexOf("ospos.net") > -1 || site.indexOf("ospserver.net") > -1) {
	site = site.replace("developer.ospos.net", "developer.bada.com");
	site = site.replace("developer.ospserver.net", "developer.bada.com");
	location.href = site;
}

$.ajax({
	url: "http://developer.bada.com/common/forum/forumTopXmlData.do",
	datatype : 'xml',
	success: function(osp){
		$('#siteInfo').ready(function() {
			// header
			// top menu
			$(osp).find('top').each(function(){
				$(this).find('forum').each(function(){
					$('#ospTopmenu').replaceWith($(this).text());
				});
			});

			$('#btn_logout').attr('href', 'http://developer.bada.com/member/logoutBridge.do?rtnURL='+window.location.pathname+window.location.search);
			$('#btn_login').attr('href', 'http://developer.bada.com/member/loginForm.do?rtnURL='+window.location.pathname+window.location.search);
		});
	}
});

$(document).ready(function() {
	var menu = ["MC01050900", "MC01051200", "MC01051300", "MC01051400"];
	for (i = 0; i < menu.length; i++) {
		$('#MDmenu_' + menu[i]).after('<ul class="localDepth02">' + $('#sideMenuListAlt_' + menu[i]).html() + '</ul>');
	}
});

function sendPost() {
	if ($('#topic').val() == '') {
		  alert("Please input the Subject");
		  $('#topic').focus();
		  return false;
	} else if ($('#post_content').val() == '') {
			alert("Please input the Post Content");
			$('#post_content').focus();
			return false;
	}

	var err = false;

	$('#bb_attachments_file_sample input').each(function() {
		if (!uploadCheck($(this)) && !err) {
			alert("Please check allowed file types.");
			err = true;
		}
	});

	$('#bb_attachments_file_input_4 input').each(function() {
		if (!uploadCheck($(this)) && !err) {
			alert("Please check allowed file types.");
			err = true;
		}
	});

	$('#bb_attachments_file_input_6 input').each(function() {
		if (!uploadCheck($(this)) && !err) {
			alert("Please check allowed file types.");
			err = true;
		}
	});

	if (!err) {
		$('#postform')[0].submit();
	} else {
		return false;
	}
}

function showPostForm(login) {
	if (login) {
		$('#tableBtn').hide();

		$('#H2postForm').show();
		$('#postform').show();
	} else {
		showLoginMsg();
	}
}

function hidePostForm() {
	$('#tableBtn').show();

	$('#H2postForm').hide();
	$('#postform').hide();
}

function showLoginMsg() {
	$('#login_msg').show();
}


function check_submit(){
	if (document.getElementById('topic').value=='') {
		  alert("Please provide a topic value");
		  document.getElementById('topic').focus();
		  return false;
	} else if (document.getElementById('post_content').value=="") {
			alert("Please provide a post_content value");
			document.getElementById('post_content').focus();
			return false;
	}
}

var allowFileExt = new Array('txt', 'xls', 'xlsx', 'doc', 'docx', 'ppt', 'pptx', 'pdf', 'bmp', 'gif', 'jpeg', 'jpg', 'png', 'zip', 'gz');

function uploadCheck(object) {
	var file = object.val();
	if (!file) return true;

	var arr = file.split('.');
	var last = arr.length - 1;

	if (indexArray(allowFileExt,arr[last])) { return true; }
	object.val('');
	return false;
}

function indexArray(arr,find) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i] == find) {
			return true;
		}
	}

	return false;
}
