function AppIsLocal() {
	var url = location.href;
	var temp = url.split("/");
	if(temp[2].toLowerCase()  == "localhost") {
		return true;
	}
	
	return false;
}


//http://localhost/GrooveNet/Web/register/avatar.aspx
var Url = {
	api: "",
	successPage: "",
	profilePage: ""
}

function GetApiUrl() {
	var url = location.href;
	var temp = url.split("/");
	
	if(temp[2].toLowerCase()  == "localhost") {
		//LOCALHOST DEV URLs
		Url.api = "../ajaxvista/v2/default.aspx";
		Url.successPage = "http://localhost/GrooveNet.Web/register/success.aspx";
		Url.profilePage = "http://localhost/GrooveNet.Web/profile/";
	}
	else {
		//PRODUCTION SERVER URLs
		Url.api = "/Ajax/v2/";
		Url.successPage = "/register/success.aspx";
		Url.profilePage = "/profile/";
	}
}

GetApiUrl();

//BEGIN CONFIGURATION
/*
//Online Version
var AjaxUrl = {
	AuthenticateUser: "/Ajax/AuthenticateUser.aspx",
	GetAvatarLogin: "/Ajax/GetAvatarLogin.aspx",
	EpinTopup: "/Ajax/EpinTopup.aspx",
	NewUser: "/Ajax/NewUser.aspx",
	NewAvatar: "/Ajax/NewAvatar.aspx",
	NewMobile: "/Ajax/NewMobile.aspx",
	IsValidated: "/Ajax/IsValidated.aspx",
	ViewUserInfo: "/Ajax/ViewUserInfo.aspx",
	GetAllDropDowns: "/Ajax/GetAllDropdowns.aspx",
	EditUserInfo: "/Ajax/EditUserInfo.aspx",
	Api: "/Ajax/",
	ApiV2: "/Ajax/v2/"
}
*/

//Offline Version
var AjaxUrl = {	
	AuthenticateUser: "http://localhost/GrooveNet.Ajax/AuthenticateUser.aspx",
	GetAvatarLogin: "http://localhost/GrooveNet.Ajax/GetAvatarLogin.aspx",
	EpinTopup: "http://localhost/GrooveNet.Ajax/EpinTopup.aspx",
	NewUser: "http://localhost/GrooveNet.Ajax/NewUser.aspx",
	NewAvatar: "http://localhost/GrooveNet.Ajax/NewAvatar.aspx",
	NewMobile: "http://localhost/GrooveNet.Ajax/NewMobile.aspx",
	IsValidated: "http://localhost/GrooveNet.Ajax/IsValidated.aspx",
	ViewUserInfo: "http://localhost/GrooveNet.Ajax/ViewUserInfo.aspx",
	GetAllDropDowns: "http://localhost/GrooveNet.Ajax/GetAllDropDowns.aspx",
	EditUserInfo: "http://localhost/GrooveNet.Ajax/EditUserInfo.aspx",
	Api: "http://localhost/GrooveNet.Ajax/default.aspx",
	ApiV2: "http://localhost/GrooveNet.Ajax/v2/default.aspx"
}

//END CONFIGURATION

// BEGIN DATA BLOCK
function UserData() {
	this.UserID = "";
	this.UserName = "";
	this.UserPhoto = "";
}

function GroupData() {
	this.GroupID = "";
	this.GroupName = "";
	this.GroupPhoto = "";
}
// END DATA BLOCK

//BEGIN OBJECT LITERALS
var Ajax = {
	SendRequest: function(method, url, data, callback) {
		var request = null;
		if(window.XMLHttpRequest) {
			request = new XMLHttpRequest();
		}
		else if(window.ActiveXObject) {
			try {
				request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				try {
					request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) {
					alert("Your browser doesn't support AJaX");
					return false;
				}
			}
		}
		else {
			alert("Your browser doesn't support AJaX");
			return false;
		}
		
		request.onreadystatechange = function() {
			switch(request.readyState) {
				case 0:
					break;
				case 1:
					window.status = "Loading...";
					break;
				case 2:
					window.status = "Loaded...";
					break;
				case 3:
					window.status = "Interactive...";
					break;
				case 4:
					window.status = "Complete...";
					try {
						if(request.status == 200) {
							window.status = "Done";
							callback(request);
							//request.abort();
						}
						else {
							alert(request.status);
							window.status = "Done";
							alert("AJaX request failed. Try refreshing/reloading the page.");
							return false;
						}
					}
					catch(e) {
					}
					
				default:
					break;
			}
		}
		//alert(this.method);
		var strictPost = false;
		if(method.toLowerCase() == "strictpost") {
			strictPost = true;
			method = "POST";
		}
		
		request.open(method, url, true); //asynchronous
		if(strictPost) {
			request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		}
		
		request.send(data);
	}
}

var Script = {
	funcName: "",
	params: "",
	jsUrl: "",
	interval: null,
	
	//jsUrl: URL of the JS file to include.
	//funcName:  string representation of the first function that needs to be called.
	//params: string representation of the parameters of the first function to be called.
	Load: function(jsUrl, funcName, params) {
		//alert("Script.Load()");
		this.funcName = funcName ? funcName : "";
		this.params = params ? params : "";
		this.jsUrl = jsUrl ? jsUrl : "";
		
		if(funcName) {
			var temp = funcName.split(".");
			if(eval("self." + temp[0])) {
				//alert("exists");
				this.Invoke();
			}
			else {
				//alert("non-existent");
				Ajax.SendRequest("GET", jsUrl, null, Script.Append);
			}
		}
		else {
			Ajax.SendRequest("GET", jsUrl, null, Script.Append);
		}
	},
	
	Append: function(request) {
		var temp = document.createElement("script");
		document.body.appendChild(temp);
		temp.text = request.responseText;
		
		if(this.funcName != "")
			Script.Invoke();
		else
			alert("Script not loaded.");
	},
	
	Invoke: function() {
		var i = 0;
		var temp = this.funcName.split(".");
		var obj = eval("self." + temp[0]);
		if(obj) {
			clearInterval(this.interval);
			var func = this.funcName + "(" + this.params + ")";
			eval(func);
		}
		else {
			i++;
			clearInterval(this.interval);
			window.status = i;
			this.interval = window.setInterval("Script.Invoke()", 100);
		}
	}
}

var Content = {
	id: "",
	callback: null,
	
	Load: function(url, id, callback) {
		this.id = id;
		this.callback = callback;
		Ajax.SendRequest("GET", url, null, Content.LoadComplete);
	},
	
	LoadComplete: function(request) {
		var txt = request.responseText;
		this.Update(txt);
	},
	
	Update: function(txt) {
		var id = document.getElementById(this.id);
		id.innerHTML = txt;
		this.callback();
	}
}

//Updated Version - deprecates XmlRequest and XmlData objects.
var XmlObj = {
	Create: function(methodName, nameList, valueList) {
		try {
			var xmlDoc = document.implementation.createDocument("","",null);
		} 
		catch(e) {
			try {
				var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			} 
			catch(e) {
			}
		}
		
	    var rootNode = xmlDoc.createElement("Request");
	    
	    var elemMethodName = xmlDoc.createElement("MethodName");
	    var textMethodName = xmlDoc.createTextNode(methodName);
	    elemMethodName.appendChild(textMethodName);
	    rootNode.appendChild(elemMethodName);
	    
	    if(nameList && valueList) {
			var dataNode = xmlDoc.createElement("Data");
			rootNode.appendChild(dataNode);
		    
			//Create data children.
			for(var i = 0; i < nameList.length; i++) {
				var nameNode = xmlDoc.createElement(nameList[i]); 
				var valueNode = xmlDoc.createTextNode(valueList[i]);
				nameNode.appendChild(valueNode);
				dataNode.appendChild(nameNode);
			}
		}
		
		xmlDoc.appendChild(rootNode);
		return xmlDoc;
	}
}

//Deprecated in favor of object literal XmlObj.
var XmlData = {
	Serialize: function(nameList, valueList) {
		try {
			var xmlDoc = document.implementation.createDocument("","",null);
		}
		catch(e) {
			try {
				var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			}
			catch(e) {
			}
		}
		
	    var rootNode = xmlDoc.createElement("root");
	    
		for(var i = 0; i < nameList.length; i++) {
			 var dataNode = xmlDoc.createElement("data"); 
			 dataNode.setAttribute(new String(nameList[i]), new String(valueList[i]));
			 rootNode.appendChild(dataNode);
		}
		
		xmlDoc.appendChild(rootNode);
		return xmlDoc;
	},
	// Same as Serialize method but generates the updated XML schema. 
	Create: function(nameList, valueList) {
		
		try
		{
			var xmlDoc = document.implementation.createDocument("","",null);
		}catch(e){
			try
			{
				var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			}catch(e){}
		}
		
	    var rootNode = xmlDoc.createElement("request");
	    var dataNode = xmlDoc.createElement("data");
	    rootNode.appendChild(dataNode);
	    
	    //Create data children.
		for(var i = 0; i < nameList.length; i++) {
			 var nameNode = xmlDoc.createElement(nameList[i]); 
			 //alert(nameList[i] + " : " + valueList[i]);
			 var valueNode = xmlDoc.createTextNode(valueList[i]);
			 nameNode.appendChild(valueNode);
			 dataNode.appendChild(nameNode);
		}
		
		xmlDoc.appendChild(rootNode);
		return xmlDoc;
	}
}
//END OBJECT LITERALS

//BEGIN TOOLS

//Focus on textfield
function FieldFocus(id) {
	document.getElementById(id).focus();
}

//Abbreviates long display names.
function ShortString(str, len) {
	if(str.length > len) {
		return (str.slice(0, len) + "...");
	}
	return str;
}

//Handles enter key onclick event when submitting forms.
function CheckEnter(e) {
	var characterCode;
	if(e && e.which) {
		e = e
		characterCode = e.which;
	}
	else {
		e = event;
		characterCode = e.keyCode;
	}	 
	if(characterCode == 13) {
 		document.forms[0].submit();
 		return false;
	}
	
	return true;
}

//Show or hide HTML components (via layers)
/*
function ShowLayer(id, isShow) {
	if(isShow) {
		document.getElementById(id).style.display = "block";
		document.getElementById(id).style.visibility = "visible";
	}
	else {
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = "hidden";
	}
}
*/

//Show or hide HTML components (via layers)
function ShowLayer(id, isShow) {
	//Show layer.
	if(isShow) {
		if(document.getElementById) {
			document.getElementById(id).style.height = "auto";
			document.getElementById(id).style.visibility = "visible";
			
			if(navigator.appName == "Microsoft Internet Explorer") {
				document.getElementById(id).style.display = "block";
			} else {
				document.getElementById(id).style.display = "table-row";
			}
		}
		else {
			document.layers[id].style.height = "auto";
			document.layers[id].style.visibility  = "visible";
			document.layers[id].style.display = "block";
		}
	}
	//Hide layer.
	else {
		//New browsers?
		if(document.getElementById) {
			document.getElementById(id).style.height = 0;
			document.getElementById(id).style.visibility = "hidden";
			document.getElementById(id).style.display = "none";
		}
		//Old browsers?
		else {
			document.layers[id].style.height = 0;
			document.layers[id].style.visibility  = "hidden";
			document.layers[id].style.display = "none";
		}
	}
}

//Hide status message
function HideStatus() {
	window.status = "";
	return true;
}

function HideStatusMessage() {
	if(document.layers) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
	document.onmouseover = HideStatus;
	document.onmouseout = HideStatus;
}
//END TOOLS


//BEGIN INITIALIZATION
//HideStatusMessage();
//END INITIALIZATION

