
//remote.js

function TestMove(mycallback, fromoptions, tooptions) {
	var url = "../remote/BuildIdea.asp?function=TestMove" +
					"&FromOptions=" + fromoptions +
					"&ToOptions=" + tooptions;
//prompt('url',url);
//return;					
	remote(url, mycallback);
}

//send notice of new challenge
function EmailChallenge(mycallback, projectid, ideaid, idealevel) {
	var url = "../remote/EmailChallenge.asp?function=EmailChallenge" +
					"&ProjectId=" + projectid +
					"&IdeaId=" + ideaid + 
					"&IdeaLevel=" + idealevel;
	remote(url, mycallback);
}

//add, remove moderators that get notified of challenges
function RemoveEmailChallenge(mycallback, projectid, userid) {
	var url = "../remote/Project.asp?function=RemoveEmailChallenge" +
					"&projectid=" + projectid +
					"&userid=" + userid;
	remote(url, mycallback);
}

function AddEmailChallenge(mycallback, projectid, userid) {
	var url = "../remote/Project.asp?function=AddEmailChallenge" +
					"&projectid=" + projectid +
					"&userid=" + userid;					
	remote(url, mycallback);
}

function ChangeHighlighted(mycallback, ideaid, highlighted) {
	var url = "../remote/ChangeStatusM.asp?function=ChangeHighlighted" +
				"&ideaid=" + ideaid + 
				"&highlighted=" + highlighted;
	remote(url, mycallback);
}

function ChangeReviewed(mycallback, ideaid, reviewed) {
	var url = "remote/ChangeStatus.asp?function=ChangeReviewed" +
				"&ideaid=" + ideaid + 
				"&reviewed=" + reviewed;
	remote(url, mycallback);
}

function ChangeModeratorReviewed(mycallback, ideaid, reviewed) {
	var url = "../remote/ChangeStatusM.asp?function=ChangeModeratorReviewed" +
				"&ideaid=" + ideaid + 
				"&reviewed=" + reviewed;
	remote(url, mycallback);
}

function TestGame(mycallback, email, game) {
	var url = "remote/User.asp?function=TestGame&email=" + email + "&game=" + game;
	remote(url, mycallback);
}

function TestDeleted(mycallback, email) {
	var url = "remote/User.asp?function=TestDeleted&email=" + email;
	remote(url, mycallback);
}

function TestEmail(mycallback, email) {
	var url = "remote/User.asp?function=TestEmail&email=" + email;
	remote(url, mycallback);
}

function TestEmail2(mycallback, email) {
	var url = "../remote/User.asp?function=TestEmail&email=" + email;
	remote(url, mycallback);
}

function AllOrGame(mycallback, setting) {
	var url = "../remote/Project.asp?function=AllOrGame&setting=" + setting;
	remote(url, mycallback);
}

function AddModerator(mycallback, projectid, userid) {
	var url = "../remote/Project.asp?function=AddModerator" +
					"&projectid=" + projectid +
					"&userid=" + userid;
	remote(url, mycallback);
}

function AddRemoveUser(mycallback, projectid, userid, adding, prefix) {
	var url = "../remote/Project.asp?function=AddRemoveUser" +
					"&projectid=" + projectid +
					"&userid=" + userid +
					"&adding=" + adding +
					"&prefix=" + escape(prefix);
	remote(url, mycallback);
}

function BuildIdea(mycallback, IdeaId, IdeaLevel, Build, Challenge, Comment, Hyperlink) {
	var url = "remote/BuildIdea.asp?function=BuildIdea" +
					"&IdeaId=" + IdeaId + 
					"&IdeaLevel=" + IdeaLevel + 
					"&Build=" + Build + 
					"&Challenge=" + Challenge +
					"&Comment=" + Comment +
					"&Hyperlink=" + Hyperlink;
	remote(url, mycallback);
}

function ChangePassword(mycallback, oldpassword, newpassword) {
	var url = "../remote/User.asp?function=ChangePassword" +
					"&oldpassword=" + escape(oldpassword) +
					"&newpassword=" + escape(newpassword);
	remote(url, mycallback);
}

function ChangeStatus(mycallback, IdeaId, Status) {
	var url = "../remote/ChangeStatus.asp?function=ChangeStatus" +
					"&IdeaId=" + IdeaId + 
					"&Status=" + Status;
	remote(url, mycallback);
}

function ChangeStatusM(mycallback, IdeaId, Status) {
	var url = "../remote/ChangeStatusM.asp?function=ChangeStatus" +
					"&IdeaId=" + IdeaId + 
					"&Status=" + Status;
	remote(url, mycallback);
}

function CreateBLS(mycallback, projectid, startdatetime, enddatetime, points) {
	var url = "../remote/BLS.asp?function=CreateBLS" +
					"&projectid=" + projectid +
					"&startdatetime=" + escape(startdatetime) +
					"&enddatetime=" + escape(enddatetime) +
					"&points=" + points;	
	remote(url, mycallback);
}

function DeleteBLS(mycallback, blsid) {
	var url = "../remote/BLS.asp?function=DeleteBLS" +
					"&blsid=" + blsid;
	remote(url, mycallback);
}

function DeleteIdea(mycallback, IdeaId) {
	var url = "../remote/ChangeStatus.asp?function=DeleteIdea" +
					"&IdeaId=" + IdeaId;
	remote(url, mycallback);
}

function DeleteUser(mycallback, userid) {
	var url = "../remote/User.asp?function=DeleteUser" +
					"&userid=" + userid;
	remote(url, mycallback);
}

function NewIdea(mycallback, comment) {
	var url = "../remote/NewIdea.asp?function=NewIdea" +
					"&Comment=" + comment;
	remote(url, mycallback);
}

function NewIdeaM(mycallback, comment) {
	var url = "../remote/NewIdea.asp?function=NewIdeaM" +
					"&Comment=" + comment;
	remote(url, mycallback);
}

function RemoveModerator(mycallback, projectid, userid) {
	var url = "../remote/Project.asp?function=RemoveModerator" +
					"&projectid=" + projectid +
					"&userid=" + userid;
	remote(url, mycallback);
}

function Rule(mycallback, IdeaId, Ruling, Penalize) {
	var url = "../remote/Rule.asp?function=Rule" +
					"&IdeaId=" + IdeaId +
					"&Ruling=" + Ruling +
					"&Penalize=" + Penalize;
	remote(url, mycallback);
}

function SetAvatar(mycallback, avatar) {
	var url = "../remote/User.asp?function=SetAvatar" +
					"&avatar=" + escape(avatar);
	remote(url, mycallback);
}

function UpdateBLS(mycallback, blsid, projectid, startdatetime, enddatetime, points) {
	var url = "../remote/BLS.asp?function=UpdateBLS" +
					"&blsid=" + blsid +
					"&projectid=" + projectid +
					"&startdatetime=" + escape(startdatetime) +
					"&enddatetime=" + escape(enddatetime) +
					"&points=" + points;	
//prompt('url',url);
//return;					
	remote(url, mycallback);
}

function UpdateIdea(mycallback, IdeaId, idea, comment, status, challenge, challengestatus, hyperlink) {
	var url = "../remote/ChangeStatus.asp?function=UpdateIdea" +
					"&IdeaId=" + IdeaId +
					"&idea=" + escape(idea) +
					"&comment=" + comment +
					"&status=" + status +
					"&challenge=" + challenge +
					"&challengestatus=" + challengestatus +
					"&hyperlink=" + hyperlink;
//prompt('url',url);
//return;					
	remote(url, mycallback);
}

function DeleteProject(mycallback, projectid) {
	var url = "../remote/Project.asp?function=DeleteProject" +
					"&projectid=" + projectid;			
	remote(url, mycallback);
}

///////////////////////////////////////////////////////////////////////////////////////////////

//save off where the user wants to go
var tempcall;
var req;

function remote(url, mycallback) {
	tempcall = mycallback;	
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
		}
    // branch for IE/Windows ActiveX version
    } 
	else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	
	if(req) {
		if (mycallback!=null) {
			req.onreadystatechange = callback;
			req.open("GET", url, true);
			req.send(null);
		}
		//syncrhonous call
		else {
			req.open("GET", url, false);
			req.send(null);		
		}
	}
	else {
		alert("System error: did not find XMLHTTP object");
	}
}

function callback() {
    if (req.readyState == 4) { //complete
        if (req.status == 200) { //OK
            // update the HTML DOM based on whether or not message is valid
            var message = req.responseXML.getElementsByTagName("message")[0];
            var result = message.childNodes[0].nodeValue;
			//alert("result = " + result);
            tempcall(result);
        }
		else {
			alert("System error: there was a problem retrieving data from the function call: (" + req.status + ") " + req.statusText);
		}
    }
}
