		var objDiv = null;		
        function initAJAX() {
        	objDiv = document.getElementById('message');            
            //x_loadFlash(loadFlashCallBack);
        }
        function getValue(id) {
        	if (objElement = document.getElementById(id)) {
                return objElement.value;
            } else {
            	return null;
            }
        }        
		function sendMessageCallBack(result) {
            try {               
                document.getElementById('sendButton').disabled = "";
                if (result) {
                	document.getElementById('status').innerHTML = "done.";
                } else {
                	document.getElementById('status').innerHTML = "error sending mail.";
                }                
            } catch(ex) {
            	alert(ex);
            }
		}      
        function isValidEmail(strEmail){
  			validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
            return (strEmail.search(validRegExp) != -1);
		}		
		function SetCookie(name,value,days) {
			if (days) {
				var date = new Date();
				date.setTime(date.getTime()+(days*24*60*60*1000));
				var expires = "; expires="+date.toGMTString();
			}
			else var expires = "";
			document.cookie = name+"="+value+expires+"; path=/";
		}
		
		function ReadCookie(name) {
			var nameEQ = name + "=";
			var ca = document.cookie.split(';');
			for(var i=0;i < ca.length;i++) {
				var c = ca[i];
				while (c.charAt(0)==' ') c = c.substring(1,c.length);
				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}
		
		function DeleteCookie(name) {
			createCookie(name,"",-1);
		}
		
		var _sajaxDebugMode = false;
		var _sajaxRequestType = "POST";

		function sajax_debug(text) {
			if (_sajaxDebugMode)
				alert("RSD: " + text)
		}
 		function sajax_init_object() {
 			sajax_debug("sajax_init_object() called..")

 			var A;
			try {
				A=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					A=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (oc) {
					A=null;
				}
			}
			
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
			if (!A)
				sajax_debug("Could not create connection object.");
			return A;
		}
		function sajax_do_call(func_name, args) {
			sajax_debug("sajax_do_call() called..");
			var i, x, n;
			var uri;
			var post_data;

			uri = "index.php";
			if (_sajaxRequestType == "GET") {
				if (uri.indexOf("?") == -1)
					uri = uri + "?rs=" + encodeURIComponent(func_name);
				else
					uri = uri + "&rs=" + encodeURIComponent(func_name);
				for (i = 0; i < args.length-1; i++)
					uri = uri + "&rsargs[]=" + encodeURIComponent(args[i]);
				if (pageid != "undefined") {
					uri = uri + "&rsargs[pageid]=" + encodeURIComponent(pageid);	
				}
				uri = uri + "&rsrnd=" + new Date().getTime();
				post_data = null;
			} else {
				post_data = "rs=" + encodeURIComponent(func_name);
				for (i = 0; i < args.length-1; i++) {
					post_data = post_data + "&rsargs[]=" + encodeURIComponent(args[i]);
				}
				if (pageid != "undefined") {
					post_data = post_data + "&rsargs[pageid]=" + encodeURIComponent(pageid);	
				}
			}

			x = sajax_init_object();
			
			x.open(_sajaxRequestType, uri, true);
			if (_sajaxRequestType == "POST") {
				x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
				x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			x.onreadystatechange = function() {
				if (x.readyState != 4)
					return;
				sajax_debug("received " + x.responseText);

				var status;
				var data;
				status = x.responseText.charAt(0);
				data = x.responseText.substring(2);
				if (status == "-")
					alert("Error: " + data);
				else
					args[args.length-1](data);
			}
			x.send(post_data);
			sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
			sajax_debug(func_name + " waiting..");
			delete x;
		}
		
		// wrapper for dochangeprovince
		function x_dochangeprovince() {
			sajax_do_call("dochangeprovince",
				x_dochangeprovince.arguments);
		}

		
		// wrapper for addtonotebook
		function x_addtonotebook() {
			sajax_do_call("addtonotebook",
				x_addtonotebook.arguments);
		}

		
		// wrapper for sendtofriend
		function x_sendtofriend() {
			sajax_do_call("sendtofriend",
				x_sendtofriend.arguments);
		}
						

         
