//javascript 
function requiredInput(inputLable, msg){
	document.getElementById('td_'+inputLable).innerHTML=msg
}

function login(){
	xmlhttp = checkBrwser()
	if(xmlhttp){
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				/*var data=xmlhttp.responseText.split(';;;')
				document.getElementById("mainData").innerHTML=data[0]
				document.getElementById("loginArea").innerHTML=data[1]
				document.getElementById("loadDiv").style.visibility='hidden'*/
				window.location=wwwroot+'users/';
			}else{
				requestNotReady()
			}
		}
		var username=document.getElementById("username").value
		var password=MD5(document.getElementById("password").value)
		xmlhttp.open("GET",wwwroot+'ajax/?module=users&action=login&username='+username+'&password='+password,true)
		xmlhttp.send(null)
	}
}

function requestNotReady(){
	if(xmlhttp.readyState==0){
		document.getElementById("loadDiv").style.visibility='visible'
	}else if(xmlhttp.readyState==1){
		document.getElementById("loadDiv").style.visibility='visible'
	}else if(xmlhttp.readyState==2){
		document.getElementById("loadDiv").style.visibility='visible'
	}else if(xmlhttp.readyState==3){
		document.getElementById("loadDiv").style.visibility='visible'
	}
}

function checkBrwser(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if(xmlhttp==''){
		return false;
	}else{
		return xmlhttp
	}
}

function viewEditDiv(page, lable){
	//alert(page)
	//alert(lable)
	if(lable=='content'){
		window.location=wwwroot
	}else{
		xmlhttp = checkBrwser()
		if(xmlhttp){
			xmlhttp.onreadystatechange=function(){
				if(xmlhttp.readyState==4){
					document.getElementById("editDataDiv").innerHTML=xmlhttp.responseText
					document.getElementById("editDataDiv").style.visibility='visible'
					document.getElementById("loadDiv").innerHTML=''
				}else{
					requestNotReady()
				}
			}
			
			xmlhttp.open("GET",wwwroot+'ajax/?module='+page+'&action='+lable,true)
			xmlhttp.send(null)
		}
	}
}

function closeDiv(divId){
	document.getElementById(divId).style.visibility='hidden'
	document.getElementById("loadDiv").style.visibility='hidden'
	document.getElementById("editDataDiv").style.visibility='hidden'
}

function startUpload(name){
	document.getElementById('preview_'+name).innerHTML='<img src="'+wwwroot+'images/loading.gif" />'
	return true
}

function stopUpload(name, img){
	var data=img.split(";;;");
	document.getElementById('preview_'+name).innerHTML=data[0]
	if(data[1]!=''){
		document.getElementById('hidden_file_'+name).value=data[1]
	}
	return true
}

function logout(){
	xmlhttp = checkBrwser()
	if(xmlhttp){
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				var data=xmlhttp.responseText.split(';;;')
				document.getElementById("mainData").innerHTML=data[0]
				document.getElementById("loginArea").innerHTML=data[1]
				document.getElementById("loadDiv").style.visibility='hidden'
			}else{
				requestNotReady()
			}
		}
		xmlhttp.open("GET",wwwroot+'ajax/?module=users&action=logout', true)
		xmlhttp.send(null)
	}
}

function showCPanel(){
	xmlhttp = checkBrwser()
	if(xmlhttp){
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				document.getElementById("mainData").innerHTML=xmlhttp.responseText
				document.getElementById("loadDiv").style.visibility='hidden'
			}else{
				requestNotReady()
			}
		}
		xmlhttp.open("GET",wwwroot+'ajax/?module=users&action=showCPanel', true)
		xmlhttp.send(null)
	}
}

function showPicker(name){
	$('#colorSelector').ColorPicker({
		color: '#0000ff',
		onShow: function (colpkr) {
			$(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			$(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			$('#colorSelector div').css('backgroundColor', '#' + hex);
			document.getElementById('hidden_'+name).value = hex
		}
	});
}

function showPicker1(name){
	$('#menu_background_div').ColorPicker({
		color: '#0000ff',
		onShow: function (colpkr) {
			$(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			$(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			$('#menu_background_div div').css('backgroundColor', '#' + hex);
			document.getElementById('hidden_'+name).value = hex
		}
	});
}

function showPicker2(name){
	$('#menu_color_div').ColorPicker({
		color: '#0000ff',
		onShow: function (colpkr) {
			$(colpkr).fadeIn(500);
			return false;
		},
		onHide: function (colpkr) {
			$(colpkr).fadeOut(500);
			return false;
		},
		onChange: function (hsb, hex, rgb) {
			$('#menu_color_div div').css('backgroundColor', '#' + hex);
			document.getElementById('hidden_'+name).value = hex
		}
	});
}

function showEditor(){
	editor = true;
	tinyMCE.init({
		// General options
		mode : "exact",
		elements : "description",
		theme : "advanced",
		skin : "o2k7",
		skin_variant : "black",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}

function htmlEntitis(string){
	for(var i=0; i< string.length; i++){
		string = string.replace("\"", "&quot;").replace("'", "&#039;").replace("<", "&lt;").replace(">", "&gt;").replace("\\", "&#092;").replace("^", "&#094;").replace(",", "&#44;")
	}
	
	for(var i=0; i< string.length; i++){
		string = string.replace("&", "W3M")
	}
	return string
}

function HideContent(d) {
	if(d.length < 1) { 
		return; 
	}
	document.getElementById(d).style.display = "none";
}

var cX = 0; 
var cY = 0; 
var rX = 0; 
var rY = 0;

function UpdateCursorPosition(e){ 
	cX = e.pageX; 
	cY = e.pageY;
}

function UpdateCursorPositionDocAll(e){ 
	cX = event.clientX; 
	cY = event.clientY;
}

if(document.all) { 
	document.onmousemove = UpdateCursorPositionDocAll; 
}else { 
	document.onmousemove = UpdateCursorPosition; 
}

function AssignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}

	if(document.all) {
		cX += rX; 
		cY += rY;
	}
	//d.style.left = (cX+10) + "px";
	d.style.top = (cY+5) + "px";
}

function DisplayContent(d, allIds){
	//alert(allIds);
	idsArray=allIds.split(';;;');
	for(i=0; i<idsArray.length; i++){
		//alert(idsArray[i])
		if(idsArray[i]!=''){
			document.getElementById('subMenu_'+idsArray[i]).style.display = "none";
		}
	}
	document.getElementById(d).style.display = "block";
}

function HideSubMenu(d){
	document.getElementById(d).style.display = "none";
}

function ShowContent(d, date) {
	if(d.length < 1) { 
		return; 
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
	viewCalendarballoon(date)
}

function ShowSubMenuContent(d, date) {
	if(d.length < 1) { 
		return; 
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
	dd.innerHTML=date
}

function ReverseContentDisplay(d) {
	if(d.length < 1) { 
		return; 
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") { 
		dd.style.display = "block"; 
	}else { 
		dd.style.display = "none"; 
	}
}

function CreateBookmarkLink(url, title) {
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,"");	
	} else if( window.external ) {
		window.external.AddFavorite( url, title); 
	}else if(window.opera && window.print) {  
		document.write('<a href ="javascript:CreateBookmarkLink()");">Add to Favorites</a>');   
	} else if (window.sidebar) {  
		document.write('<a href ="javascript:CreateBookmarkLink()");">Bookmark Page</a>');  
	} else if (window.opera && window.print) {	   
		document.write('<a href ="javascript:CreateBookmarkLink()");">Add Bookmark</a>'); 
	}
}


function temp(form){
	var a = parseFloat(form.Amount.value, 10);
	var f = parseFloat(form.RateFrom.value, 10);
	var t = parseFloat(form.RateTo.value, 10);
	var c = 0;
	c = a * f / t;
	c = Math.round(1000*c)/1000;
	form.Exchange.value = c;
}

function viewWhereUser(){
	
}

var imageNum=1;
function slideShow(){
	
	setInterval("writeImage()", 5000);
	
	
}

function writeImage(){
	document.getElementById("webSiteBanner").innerHTML='<img src="'+wwwroot+'images/slide_show/banner'+imageNum+'.jpg" />';
	if(imageNum>=3){
		imageNum=1;
	}else{
		imageNum++;
	}
}
