var $_GET=Array()
$chunks=window.location.href.split("/");
for($x=0; $x<$chunks.length; $x++){
	if($chunks[$x].search("_")){
		$parts=$chunks[$x].split("_");
		$_GET[$parts[0]]=$parts[1];
	}
}

function amILocal($needle){
	$haystack=window.location.href;
	if($haystack.search($needle)>=0){
		return true;
	} else {
		return false;
	}
}

if(amILocal(LOCAL_HOST)){
	ROOT="http://"+LOCAL_HOST+"/"+LOCAL_FOLDER+"/";
	AJAXURLstop=LOCAL_FOLDER;
} else {
	ROOT="http://"+LIVE_URL+"/";
	AJAXURLstop=LIVE_URL;
}

function createCookie(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;
}

URLparts=window.location.href.split("/");
addParts=true;
AJAXlink="";
for(i=URLparts.length-2; i>0; i--){
	if(URLparts[i]==AJAXURLstop){
		addParts=false;
	}
	if(addParts){
		AJAXlink+="../";
	}
}
AJAXlink+="ajax/ajax.php?page=";

var Expanders=Array();


window.addEvent("domready", function(){

    $$("#menu ul li").each(function(element){
        element.onmouseover=function(){
            if(element.childNodes.length>0){
                for(i=0; i<element.childNodes.length; i++){
                    if(element.childNodes[i].tagName=="UL"){
                        $(element.childNodes[i]).setStyle("display", "block");
                    }
                }
            }
        }
        element.onmouseout=function(){
            if(element.childNodes.length>0){
                for(i=0; i<element.childNodes.length; i++){
                    if(element.childNodes[i].tagName=="UL"){
                        $(element.childNodes[i]).setStyle("display", "none");
                    }
                }
            }
        }
    });





    if($$("input.ajaxvalidation").length>0){
        $$("input.ajaxvalidation").each(function(element, index){
            ajaxTable=element.value.split("::")[0];
            ajaxColumns=element.value.split("::")[1].split("|");
            theForm=element.getParent();
            for(i=0; i<theForm.childNodes.length; i++){
                if(theForm.childNodes[i].tagName=="INPUT"){
                    for(j=0; j<ajaxColumns.length; j++){
                        if(theForm.childNodes[i].name==ajaxColumns[j]){
                            if(!theForm.childNodes[i].id){
                                theForm.childNodes[i].id="validateField"+i+index;
                            }
                            theForm.childNodes[i].notifyField=new Element("DIV");
                            theForm.childNodes[i].notifyField.setStyles({
                                backgroundColor:"#C00",
                                color:"#FFF",
                                padding:0,
                                opacity:0,
                                height:0,
                                marginTop:"-5px",
                                marginBottom:5,
                                fontSize:10
                            });
                            theForm.childNodes[i].notifyField.expander=new Fx.Styles(theForm.childNodes[i].notifyField, {duration:500, wait:false});
                            theForm.childNodes[i].notifyField.innerHTML="Already Taken";
                            theForm.childNodes[i].notifyField.injectAfter(theForm.childNodes[i]);
                            theForm.childNodes[i].onblur=function(){
                                this.searchObject=new Ajax(AJAXlink+"ajaxvalidate", {
                    				method:'POST',
				                    data:{table:ajaxTable, column:this.name, value:this.value, element:this.id, rand:new Date()},
				                    evalScripts:true
                    			}).request();
                            }
                        }
                    }
                }
            }
        });
    }

    if($$("form.validate").length>0){
        $$("form.validate")[0].onsubmit=function(){
    		dontsend=0;
    		$$("form.validate .required").each(function(element){
    			if(element.value==""){
    				element.fader=new Fx.Styles(element);
    				element.fader.start({
    					backgroundColor:"#FFCCCC"
    				});
    				dontsend=1;
    			} else {
    				element.fader=new Fx.Styles(element);
    				element.fader.start({
    					backgroundColor:"#FFFFFF"
    				});
    			}
    		});
    		if(dontsend==1){
    			return false;
    		} else {
    			return true;
    		}
    	}
    }

});