// Author: Al Sierra
// Version: 3.27.2009
// Description: AJAX for main functions
var nycs = {};
nycs.main = {};
nycs.main._divShutter = false;
nycs.main._divWindow = false;
nycs.main.inDocumentRef = false;
nycs.main.Init = 
	function(inDocumentRef) { 	
		nycs.main.inDocumentRef = inDocumentRef;
	};
nycs.main.CreateShutterScreens = 
	function(){
		// find our shutter DIV
		nycs.main._divShutter = $('shutter-MAIN');
		if(!nycs.main._divShutter) {
			// shutter not found, create
			nycs.main._divShutter = nycs.main.inDocumentRef.createElement('div');
			nycs.main._divShutter.id = 'shutter-MAIN';
			nycs.main._divShutter.style.display = 'none';
			nycs.main._divShutter.style.background = '#000000';
			nycs.main._divShutter.style.top = '0px';
			nycs.main._divShutter.style.left = '0px';
			nycs.main._divShutter.style.position = 'absolute';
			nycs.main._divShutter.style.height = '2000px';
			nycs.main._divShutter.style.width = '100%';
			nycs.main._divShutter.style.zIndex = '1000';
			nycs.main._divShutter.onclick = function(){nycs.main.CancelModalWindow();}
			nycs.main.inDocumentRef.body.appendChild(this._divShutter);
		}
		// find our window DIV
		nycs.main._divWindow = $('shutter-WINDOW');
		if(!nycs.main._divWindow) {
			// popup DIV not found, create
			nycs.main._divWindow = nycs.main.inDocumentRef.createElement('div');
			nycs.main._divWindow.id = 'shutter-WINDOW';
			nycs.main._divWindow.style.display = 'none';
			nycs.main._divWindow.style.zIndex = '2000';
			nycs.main.inDocumentRef.body.appendChild(this._divWindow);
		}
	};
nycs.main.ValidateString =
	 function (s){
        if(s==undefined || s==null || s.length==0) {
            return false;
        }
        
        // Check for white space
        reWhiteSpace = new RegExp(/^\s+$/);
        if (reWhiteSpace.test(s)) {
            return false;
        }
     
        //Check for html tags
        reHtmlTags = new RegExp(/<(.|\n)/);
        if (reHtmlTags.test(s)) {
            return false;
        }
        return true;
    };
nycs.main.ValidateEmail = 
	function (email) {
        //Check if there is valid password data
        if(email==undefined || email==null || email.length==0) {
            return false;
        }
        // Check for white space
        reWhiteSpace = new RegExp(/^\s+$/);
        if (reWhiteSpace.test(email)) {
            return false;
        }
        //Check for proper email format
        var e1=email.indexOf("@");
        if (e1==-1) {
            return false;
        }else {
            var emailsub1 = email.substr(e1+1);
            var esub1=emailsub1.indexOf(".");
            if (esub1==-1) {
                return false;
            }
        }
        return true;
    };
nycs.main.ValidateNumber = 
	function (number) {
	 	reNumeric = new RegExp(/^[0-9]+$/);
        if (!reNumeric.test(number)) {
        	return false;
        }
        return true;
    };
nycs.main.ValidateHtmlTags = 
	function (s) {
	 	//Check for html tags
        reHtmlTags = new RegExp(/<(.|\n)/);
        if (reHtmlTags.test(s)) {
            return false;
        }
        return true;
    };
nycs.main.HtmlPopUp = 
	function(URL){
	 	var day = new Date();
		var id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=850,height=850,left = 215,top = -25');");
	};
nycs.main.GetMayorMessage = 
	function(){
		var msg_data = {};
		nycs.main.CreateShutterScreens();
		msg_data.cmd = 'getmayormessage';
		new Ajax.Request("scripts/php/modal_window.php?", {
			parameters: $H(msg_data).toQueryString(),
			evalScripts: true,
			onSuccess: function(transport) {
				try {
					var JSON = eval("("+transport.responseText+")");
					if (JSON.emsg) {
						alert(JSON.emsg);
						return false;
					}
					$('shutter-WINDOW').innerHTML = JSON.html;
					
				}catch(e) {
					alert("The server's response could not be understood.\nPlease try again.");
					return false;
				}
			},
			onComplete: function(){
				Effect.Center($('shutter-WINDOW'));
			 	new Effect.Appear($('shutter-WINDOW'),{duration: .1, to:1.0});
				new Effect.Appear($('shutter-MAIN'),{duration: 2, from: 0.0, to:0.45 }); 
			}			
		}); 
	 };	
nycs.main.CancelModalWindow=
	function(){
		$('shutter-WINDOW').fade({ duration: .1, to:0.0 });
		$('shutter-WINDOW').innerHTML = '';
		$('shutter-MAIN').fade({ duration: 1, to:0.0 });
	};	
