var divSendMessage = null;
var divCreateAlbum = null;
var sendMessageUserId = null;
var sendMessageAjaxObject = null;
var readMessageAjaxObject = null;
var createAlbumAjaxObject = null;
var divVideo = null;
var msgid = null;
var clear = true;

function sendMessage(uid,reply)
{
	//alert(uid);
	divSendMessage = show(430,320);
	
	sendMessageUserId = uid;
	if(reply)
	{
		a = "ajax//sendmessage.php?receiverid="+uid+"&reply="+reply;
	}else
	{
		a = "ajax//sendmessage.php?receiverid="+uid;
	}
	sendMessageAjaxObject = new MyAjax(a,"",sendMessageSuccess,sendMessageFail,sendMessageLoading);
	
}
function createAlbum()
{
	//alert(uid);
	divCreateAlbum = show(430,320);
	a = "ajax//createalbum.php";
	createAlbumAjaxObject = new MyAjax(a,"",createAlbumSuccess,createAlbumFail,createAlbumLoading);
}
function readMessage(mid, mtype, from)
{
	/*
	if(mtype == 1)
	{
		divSendMessage = show(430,220);
	}else
	{
		divSendMessage = show(430,420);
	}
	msgid = mid;
	a = "ajax//readmessage.php?mid="+mid+"&mtype="+mtype;
	readMessageAjaxObject = new MyAjax(a,"",readMessageSuccess,readMessageFail,readMessageLoading);
	*/
	if(from == 0)
	{
		window.location = "message.php?formname=read&mid="+mid+"&from=0";
	}else if(from == 1)
	{
		window.location = "message.php?formname=read&mid="+mid+"&from=1";
	}else
	{
		window.location = "message.php?formname=read&mid="+mid;
	}
}
function sendMessageLoading()
{
	loading(divSendMessage, "sendMessageCancel");
}
function createAlbumLoading()
{
	loading(divCreateAlbum, "createAlbumCancel");
}
function readMessageLoading()
{
	loading(divSendMessage, "readMessageCancel");
}
function sendMessageCancel()
{
	hide();
}
function createAlbumCancel()
{
	hide();
}
function readMessageCancel()
{
	hide();
}
function sendMessageFail()
{
	divSendMessage.innerHTML = '<div id="itemCenter">Connection Error!!</br><a href="#" onclick="sendMessage('+sendMessageUserId+'); return false;">Try again</a></br>If you are having this problem continuously <a href="">click here</a></br><a href="#" onclick="hide(); return false;">Close</a></div>';
}
function createAlbumFail()
{
	divCreateAlbum.innerHTML = '<div id="itemCenter">Connection Error!!</br><a href="#" onclick="sendMessage('+sendMessageUserId+'); return false;">Try again</a></br>If you are having this problem continuously <a href="album.php?formname=newalbum">click here</a></br><a href="#" onclick="hide(); return false;">Close</a></div>';
}
function readMessageFail()
{
	divSendMessage.innerHTML = '<div id="itemCenter">Connection Error!!</br><a href="#" onclick="sendMessage('+sendMessageUserId+'); return false;">Try again</a></br>If you are having this problem continuously <a href="">click here</a></br><a href="#" onclick="hide(); return false;">Close</a></div>';
}
function sendMessageSuccess()
{
	composeUserList = new Array();
	composeUserListName = new Array();
	//alert(sendMessageAjaxObject.getResponseText());
	divSendMessage.innerHTML = sendMessageAjaxObject.getResponseText();
	document.form1.fc.focus();
	
	var b = document.form1.sendto.value;
	var temp = new Array();
	
	temp = b.split(',');
	//alert(temp.toString());
	//alert(temp.length);
	var z = 0;
	for(z = 0; z < temp.length; z++)
	{
		//alert(temp[z]);
		addUserId(temp[z]);
	}
	updateComposeUserList(true);
	//alert(document.getElementById("fc"));
	//setTimeout(document.getElementById("fc").focus(), 2000);
	
	compact("composeMessage");
	
	try
	{
		if(composeUserList.length == 0)
		{
			document.form1.fc.focus();
		}
	}catch(e)
	{
	}
	
}

function createAlbumSuccess()
{
	divCreateAlbum.innerHTML = createAlbumAjaxObject.getResponseText();
	compact("createalbum");
}

function readMessageSuccess()
{
	var a = document.getElementById("tr"+msgid);
	if(a)
	{
		colorArray[msgid] = "";
		a.bgColor = "";
	}
	var b = document.getElementById("img"+msgid);
	if(b)
	{
		if(b.src.search("messagenew.gif") > -1)
		{
			try
			{
				var z = document.getElementById("inboxnumber");
				if(z)
				{
					var n = z.innerHTML;
					n = n.substring(1);
					n = parseInt(n);
					n = n - 1;
					if(n > 0)
					{
						z.innerHTML = "("+n+")";
					}else
					{
						z.innerHTML = "&nbsp;";
					}
				}
			}catch(e)
			{
			
			}
			b.src = "images/messageold.gif";
		}else
		{
			//alert(b.src);
		}
	}
	
	var c = document.getElementById("msglist");
	
	if(c)
	{
		var d = c.getElementsByTagName("input");
		for(var i = 0; i < d.length; i++)
		{
			if(d[i].getAttribute("type") == "checkbox")
			{
				if(d[i].value == msgid)
				{
					d[i].id = "r"+d[i].name;
				}
			}
		}
	}
	divSendMessage.innerHTML = readMessageAjaxObject.getResponseText();
	
	composeUserList = new Array();
	composeUserListName = new Array();
	
	//alert(sendMessageAjaxObject.getResponseText());
	//divSendMessage.innerHTML = sendMessageAjaxObject.getResponseText();
	//compact("composeMessage");
	//var rmdiv = showMyDiv("RM", "Reply",true);
	if(document.form1)
	{
		var b = document.form1.sendto.value;
		var temp = new Array();
	
		temp = b.split(',');
	//alert(temp.toString());
	//alert(temp.length);
		var z = 0;
		for(z = 0; z < temp.length; z++)
		{
		//alert(temp[z]);
			addUserId(temp[z]);
		}
		updateComposeUserList(false);
	}
	//rmdiv.toggle(false);
	compact("messageBox");
	try
	{
	//document.form1.rte1.focus();
	}catch(e)
	{
	}
	
}

function loading(div, cancel)
{
	if(cancel == "")
	{
		calcel = "hide";
	}
	div.innerHTML = '<table width="100%" border="0"><tr><td><div id="itemLeft"><img src="images//indicator.gif"></img></div></td><td valign="top"><div id="itemRight"><a href="#" onclick="'+cancel+'(); return false;">X</a></div></td></tr></table>';
}

function sendMessageSubmit()
{
	if(document.form1.sendto.value == "" || document.form1.sendto.value == 0)
	{
		alert("Please select a receipient");
		return false;
	}
	if((document.form1.rte1.value=="") && (document.form1.subject.value==""))
	{			
		alert("Please write something");
		return false;
	}else
	{
		//alert(document.form1.sendto.value);
		
		var url = "ajax//sendmessage.php?action=submit";
		/*
		alert(encodeURIComponent(document.form1.rte1.value));
		return false;
		*/
		var data = "sendto="+document.form1.sendto.value+"&subject="+encodeURIComponent(document.form1.subject.value)+"&rte1="+encodeURIComponent(document.form1.rte1.value);
		sendMessageAjaxObject = new MyAjax(url, data,sendMessageSubmitSuccess,sendMessageSubmitFail,sendMessageSubmitLoading);
	}
	return true;	
}

function sendMessageSubmitLoading()
{
	document.form1.submit.disabled = true;
	document.form1.cancel.disabled = true;
	document.getElementById("loadingSubmitMessage").innerHTML = '<div id="itemCenter"><img src="images//indicator.gif">Sending please wait</div>';
	//loading(divSendMessage, "sendMessageCancel");
}
function sendMessageSubmitFail()
{
	document.form1.submit.disabled = false;
	document.form1.cancel.disabled = false;
	document.getElementById("loadingSubmitMessage").innerHTML = '<div id="itemCenter">Connection Error please try again...</div>';
}
function sendMessageSubmitSuccess()
{
	divSendMessage = show(400,200);
	divSendMessage.innerHTML = sendMessageAjaxObject.getResponseText();
	compact("sendresult");
}

var node = null;
var oldValue = null;
var ajObject = null;
function changeComposeMessage(n)
{
	//alert(node);
	node = n;
	oldValue = node.innerHTML;
	id = document.forms[1].fl.value;
	if(id == -1)
	{
		return;
	}
	index = document.form1.fl.selectedIndex;
	name = document.form1.fl.options[index].innerHTML;
	node.innerHTML = '<a href="viewprofile.php?id='+id+'">'+name+'</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="javascript:showFriendList(); return false;">(change)</a>';
	//alert(node.innerHTML);
	document.form1.sendto.value = id;
	a = "ajax//common.php?action=getuserdisplaypicturesmall&userid="+id;
	ajObject = new MyAjax(a,"",changeDP);
	//document.getElementById("userimage").innerHTML = 'asif';
}
var composeUserList = null;
var composeUserListName = null;

function addUserId(id)
{
	
	clear = false;
	if(id != -0)
	{
		if(composeUserList == null)
		{
			composeUserList = new Array();
			composeUserListName = new Array();
		}
		if(arrayContain(composeUserList, id))
		{
			return;
		}
		ind = -1;
		for(i = 0; i < document.form1.fl.options.length; i++)
		{
			if(document.form1.fl.options[i].value == id)
			{
				ind = i;
				break;
			}
		}
		//alert(ind);
		if(ind != -1)
		{
			
			//alert(document.forms[1].fl.options[index].value);
			composeUserListName[composeUserList.length] = document.form1.fl.options[ind].innerHTML;
			composeUserList[composeUserList.length] = id;
		}
		//return;
	}
	clear = true;
	
}
function addUser()
{
	if(composeUserList == null)
	{
		composeUserList = new Array();
		composeUserListName = new Array();
	}
	
	
	id = document.form1.fl.value;
	index = document.form1.fl.selectedIndex;
	document.form1.fl.selectedIndex = 0;
	document.form1.subject.focus();
	if(id == -1)
	{
		return;
	}
	
	if(arrayContain(composeUserList, id))
	{
		return;
	}
	
	
	name = document.form1.fl.options[index].innerHTML;
	//alert(document.forms[1].fl.options[index].value);
	composeUserListName[composeUserList.length] = name;	
	composeUserList[composeUserList.length] = id;
	updateComposeUserList(true);
}
function limitString(string, limit)
{
	if(string.length > limit)
	{
		return string.substring(0,limit-1)+"..";	
	}else
	{
		return string;
	}	
}

function removeUser(id)
{
	if(composeUserListName != null && composeUserList != null)
	{
		try
		{
			//composeUserList = Array.concat(composeUserList.slice(0,id-1),composeUserList.slice(id+1,composeUserList.length-1));
			a = composeUserListName.slice(0,id);
			c = composeUserList.slice(0,id);
			//alert(a.toString());
			b = composeUserListName.slice(id+1,composeUserListName.length);
			d = composeUserList.slice(id+1,composeUserList.length);
			//alert(b.toString());
			composeUserListName = new Array();
			composeUserListName = composeUserListName.concat(a);
			composeUserListName = composeUserListName.concat(b);
			composeUserList = new Array();
			composeUserList = composeUserList.concat(c);
			composeUserList = composeUserList.concat(d);
			//alert(composeUserListName.toString());
			updateComposeUserList(true);
			document.form1.subject.focus();
			
		}catch(e)
		{
			//alert(e);
		}
	}
}
function updateComposeUserList(f)

{
	try
	{
	div = document.getElementById("userList");
	//alert(div);
	if(div)
	{
		
		if(composeUserList.length < 1)
		{
			
			div.innerHTML = '<div id="separator">&nbsp;</div>';
			
		}else
		{
			
			var msg = '<table border="0" width="100%" align="left">';
			//msg = "";
			var count = 0;
			
			for(i = 0; i < composeUserList.length; i++)
			{
				
				if(i%3 == 0)
				{
					msg += '<tr>';
				}
				
				msg += '<td width="33%"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><div id="itemCenter">'+limitString(composeUserListName[i], 14)+'</div></td><td><div id="itemRight"><a href="#" onclick="javascript:removeUser('+i+'); return false;" onfocus="fcfocuslost()"><b>x</b></a></div></td></tr></table></td>';
				
				if(i%3 == 2)
				{
					msg += '</tr>';
				}
				/*
				msg += '<span id="itemLeft">'+composeUserListName[i]+'&nbsp;<a href="#" onclick="javascript:removeUser('+i+'); return false;"><b>x</b></a></span>';
				*/
				count++;
			}
			
			if(count % 3 == 0)
			{
				msg += '</table>';
			}else if(count % 3 == 1)
			{
				msg += '<td colspan="2"><div id="itemLeft">&nbsp;</div></td></tr></table>';
			}else
			{
				msg += '<td><div id="itemLeft">&nbsp;</div></td></tr></table>';
			}
			
			//msg +=  '<span id="itemLeft"><input type="text" name="select" class="fieldDiv"></span>';
			//alert(msg);
			div.innerHTML = msg;
			if(f)
			{
				if(document.form1.subject.value == "")
				{
					document.form1.subject.focus();
				}else
				{
					document.form1.rte1.focus();
				}
			}
			var row = (count / 3) + 1;
			
			
			
		}
		
		if(composeUserList && document.form1.sendto)
		{
			document.form1.sendto.value = composeUserList.toString();
		}
		
		//alert(document.form1.sendto.value);
	}
	}catch(e)
	{
		alert(e.toString());
	}
	compact("composeMessage");
}

function arrayContain(array, value)
{
	for(i=0; i< array.length; i++)
	{
		if(array[i] == value)
		{
			return true;
		}
	}
	return false;
}

function changeDP()
{
	res = ajObject.getResponseText();
	document.getElementById("userimage").innerHTML = res;
}
function showFriendList()
{
	if(node == null)
	{
		return;
	}
	node.innerHTML = oldValue;
	document.forms[1].sendto.value = -1;
	a = "ajax//common.php?action=getuserdisplaypicturesmall&userid="+-1;
	ajObject = new MyAjax(a,"",changeDP);
	//document.getElementById("change").innerHTML = '&nbsp;';
}
function showVideo(vid)
{
	divVideo = show(450,390);
	videoId = vid;
	a = "ajax//showvideo.php?v="+vid;
	sendMessageAjaxObject = new MyAjax(a,"",videoMessageSuccess,videoMessageFail,videoMessageLoading);
}
function videoMessageLoading()
{
	loading(divVideo, "videoMessageCancel");
}
function videoMessageCancel()
{
	hide();
}
function videoMessageFail()
{
	divVideo.innerHTML = '<div id="itemCenter">Connection Error!!</br><a href="#" onclick="showVideo('+videoId+'); return false;">Try again</a></br>If you are having this problem continuously <a href="javascript:popUp(\'videopopup.php?v='+videoId+'\')">click here</a></br><a href="#" onclick="hide(); return false;">Close</a></div>';
}
function videoMessageSuccess()
{
	divVideo.innerHTML = sendMessageAjaxObject.getResponseText();
}
function fcfocus()
{
	var list = document.getElementById("fclist");
	var fc = document.getElementById("fc");
	if(list && fc)
	{
		list.style.visibility = "visible";
		list.style.zIndex = 2;
		fc.value = "";
		list.innerHTML = '<div id="itemLeft">Start typing a friend\'s name</div>';
		//list.style.width="100px";
		//document.form1.fl.options.length);
	}
}

function fcfocuslost()
{
	//setTimeout(clearfclist,1000);
	
	var list = document.getElementById("fclist");
	var fc = document.getElementById("fc");
	if(list && fc)
	{
		fc.value = "";	
		fcchange();
		list.style.visibility = "hidden";		//
		list.style.zIndex = -1;
	}
	
}
/*
function clearfclist()
{
	alert(clear);
	while(!clear);
	alert(clear);
	var list = document.getElementById("fclist");
	var fc = document.getElementById("fc");
	if(list && fc)
	{
		list.style.visibility = "hidden";
		fc.value = "";	
		//fcchange();
	}
}
*/
var si = -1;
function fcchange(e)
{
	
	var list = document.getElementById("fclist");
	var fc = document.getElementById("fc");
	if(list && fc)
	{
		try
		{
			var characterCode;
			if(e && e.which)
			{ 
				e = e;
				characterCode = e.which;
			}
			else
			{
				e = event;
				characterCode = e.keyCode; //character code is contained in IE's keyCode property
			}
			//alert(characterCode);
			if(characterCode == 13 || characterCode == 44 || characterCode == 59 || characterCode == 188 || characterCode == 186)
			{ //if generated character code is equal to ascii 13 (if enter key)
				//loginform.submit(); //submit the form
				try
				{
					if(si != -1)
					{
						//alert(si);
						var l = list.getElementsByTagName("div");
						l[si].onclick();
						if(characterCode != 13)
						{
							document.form1.fc.focus();
						}
						//alert(func);
					}
				}catch(e)
				{
					alert(e);
				}
				return;
			}
			if(characterCode == 38)
			{ //if generated character code is equal to ascii 13 (if enter key)
				//loginform.submit(); //submit the form
				try
				{
					if(si != -1)
					{
						//alert(si);
						var l = list.getElementsByTagName("div");
						var nsi = si-1;
						if(nsi < 0)
						{
							nsi = l.length-1;
						}
						fcselect(l[nsi]);
						//alert(func);
					}
				}catch(e)
				{
					alert(e);
				}
				return;
			}
			if(characterCode == 40)
			{ //if generated character code is equal to ascii 13 (if enter key)
				//loginform.submit(); //submit the form
				try
				{
					if(si != -1)
					{
						//alert(si);
						var l = list.getElementsByTagName("div");
						var nnsi = parseInt(si)+1;
						if(nnsi >= l.length)
						{
							//alert(nnsi);
							//alert(l.length);
							nnsi = 0;
						}
						fcselect(l[nnsi]);
						//alert(func);
					}
				}catch(e)
				{
					alert(e);
				}
				return;
			}
		}catch(e)
		{
		}
		if(fc.value == "")
		{
			list.innerHTML = '<div id="itemLeft">Start typing a friend\'s name</div>';
			si = -1;
		}else
		{
			var result = "";
			var str = fc.value;
			var count = 0;
			for(i = 1; i < document.form1.fl.options.length; i++)
			{
				var s = document.form1.fl.options[i].innerHTML;
				if(s)
				{	
					//alert(s);
					/*
					if(str.length <= s.length)
					{
						//alert(s);
						if(str == s.substring(0,str.length))
						{
							result = s;
						}
					}
					*/
					var a = s.toLowerCase();
					var b = str.toLowerCase();
					var z = a.search(b);
					if(z != -1)
					{	
					
						var value = document.form1.fl.options[i].value;
						
						if(value > 0)
						{
							s = s.substring(0,z)+"<b>"+s.substring(z,z+b.length)+"</b>"+s.substring(z+b.length, s.length);
						result += '<div id="itemLeft" style="cursor:pointer;border-bottom:1px solid" onclick="javascript:addUserId('+value+'); updateComposeUserList(true); return false;" onmouseover="fcselect(this)" value="'+count+'">'+s+'</div>';
						}else if(value < 0)
						{
							s = s.substring(0,z)+"<b>"+s.substring(z,z+b.length)+"</b>"+s.substring(z+b.length, s.length);
						result += '<div id="itemLeft" style="cursor:pointer;border-bottom:1px solid; " onclick="javascript:addUserId('+value+'); updateComposeUserList(true); return false;" onmouseover="fcselect(this)" value="'+count+'"><img src="images/icons/go_education.gif" border="0" align="texttop"/>&nbsp;&nbsp;'+s+'</div>';
						}
					
					
						count++;
					}
					/*
					var d = s.split(" ");
					for(var k = 0; k < d.length; k++)
					{
											
					}
					*/
				}
			}
			//alert(result);
			if(count > 0)
			{
				list.innerHTML = result;
				var l = list.getElementsByTagName("div");
				fcselect(l[0]);
				si = 0;
			}else
			{
				si = -1;
				list.innerHTML = '<div id="itemLeft">No match found</div>';
			}
		}
	}
}
var oldColor = "#F7F7F7";
var newColor = "#FDFBE7";
newColor = "#000000";

function fcselect(n)
{
	var value = n.getAttribute("value");
	//alert(value);
	if(si != -1)
	{
		try
		{
			var list = document.getElementById("fclist");
			var l = list.getElementsByTagName("div");
			fcdeselect(l[si]);
		}catch(e)
		{
		
		}
	}
	try
	{
		si = value;
		n.style.backgroundColor = newColor;
		n.style.color = "#FFFFFF";
	}catch(e)
	{
	}
	
}

function fcdeselect(de)
{
	de.style.backgroundColor = oldColor;
	de.style.color = "#000000";
}

function changePage(obj)
{
	//alert(obj.value);
	window.location = obj.value;
}

function validateCreateAlbum()
{
	if(document.newalbum.albumname.value == "")
	{
		alert("Please enter album name");
		return false;
	}else
	{
		document.newalbum.submit();
	}
}

var majax;

function sendAdvisorRequest(fromId, toId)
{
	var url = "ajax/advisorresponse.php?fromid=" + fromId + '&toid=' + toId;
	majax = new MyAjax(url, '', advisorResponse, '', '');
	
}

function advisorResponse() 
{ 
	div = show(400, 280);	
	div.innerHTML = majax.getResponseText(); 
}

function createReport()
{
	alert("This function is under development.");
	return false;
}

function changeConcentration(value)
{
	var id = value;
	id = id.substring(0, id.length-2);
	var div = document.getElementById(id+"div");
	//if(div)
	//{
	//	div.innerHTML = "<label id='itemLeftAlt'>Loading...</label>";
	//}
	
	var category = document.getElementById(value);
	var combo = document.getElementById(id+"c");
	
	combo.options.length = 0;
	combo.options[combo.options.length] = new Option("Loading", "-1");
	combo.disabled = true;
	
	var categoryId = category[category.selectedIndex].value;
	
	var size = category.getAttribute("size");
	
	var url  = "ajax//uniprogramresponse.php?id="+id+"&cid="+categoryId+"&size="+size;
	
	var ajaxObject = new MyAjax(url,"",function()
												{
													//div.innerHTML = ajaxObject.getResponseText();
													changeComboOption(combo, ajaxObject.getResponseText());
													combo.disabled = false;
												});
	
	
	//alert(id);
}

function RemoveStudyConcentration(id)
{
	var conSelect = document.getElementById(id+"sc");
	var conSelectHidden = document.getElementById(id+"sch");
	//alert(conSelectHidden.value);
	if(conSelect)
	{
		var selectedIndex = conSelect.selectedIndex;
		if(selectedIndex < 0)
		{
			alert("Select a concentration from your selected concentration list.");
			return;
		}
		//try
		//{
			var value = conSelect.options[selectedIndex].value;
			var hvalue = conSelectHidden.value;
			//alert(value);
			var newvalue = hvalue.replace(","+value, "");
			newvalue = newvalue.replace(value+",", "");
			//newvalue = newvalue.replace(","+value, "");
			newvalue = newvalue.replace(value, "");
			/*
			//alert(hvalue.indexOf(value));
			var index = hvalue.indexOf(value);
			var newvalue = hvalue.substring(0, index)+hvalue.substring(index+value.length);
			if(newvalue.substring(newvalue.length) == ",")
			{
				newvalue = newvalue.substring(0, newvalue.length-1);
			}else
			{
				alert(";");
			}
			*/
			//alert(newvalue);
			conSelect.options[selectedIndex] = null;
			conSelectHidden.value = newvalue;
			//alert(conSelectHidden.value);
			
			//alert(conSelect.options.length);
		//}catch(e)
		//{
		//	alert(e);
		//}
	}
}

function SelectStudyConcentration(id, maximum)
{
	var con = document.getElementById(id+"c");
	if(!con)
	
	{
		return;
	}
	var selectedIndex = con.selectedIndex;
	if(selectedIndex > -1)
	{
		var value = con.options[selectedIndex].value;
		//alert(value);
		if(value > 0)
		{
			 var conSelect = document.getElementById(id+"sc");
			 var conSelectHidden = document.getElementById(id+"sch");
		 	if(conSelect.options.length < maximum)
		 	{
				//if(!valueExistInCombo(conSelect, con.options[selectedIndex].value))
				if(conSelectHidden.value.indexOf(""+con.options[selectedIndex].value) == -1)
				{
		 			conSelect.options[conSelect.options.length] = new Option(con.options[selectedIndex].text, con.options[selectedIndex].value);
					if(conSelectHidden.value == "")
					{
						conSelectHidden.value = con.options[selectedIndex].value;
					}else
					{
						conSelectHidden.value = conSelectHidden.value+","+con.options[selectedIndex].value;
					}
					
				}else
				{
					alert("You already have this concentration in your selected list.");
				}
			}else
			{
				alert("You can not select more than "+maximum);
			}
		}else
		{
			alert("Please select a concentration.");
		}
	}else
	{
		alert("Please select a concentration.");
	}
	
}

function selectLocationCountry(id)
{
	var country = document.getElementById(id+"country");
	var state = document.getElementById(id+"state");
	var stateDiv = document.getElementById(id+"div");
	var city = document.getElementById(id+"city");
	
	var value = country.options[country.selectedIndex].value;
	//alert(value);
	if(value == -1)
	{
		stateDiv.style.display = "none";
		state.options.length = 0;
		state.options[0] = new Option("Select a country", -1);
		city.options.length = 0;
		city.options[0] = new Option("Select a country", -1);
	}else
	{
		url = "ajax//locationpackageresponse.php?action=c&cid="+value;
		stateDiv.style.display = "none";
		state.options.length = 0;
		state.options[0] = new Option("Loading", -1);
		city.options.length = 0;
		city.options[0] = new Option("Loading", -1);
		city.disabled = true;
		state.disabled = true;
		var a = new MyAjax(url,"", function()
										   {
											   var data = a.getResponseText();
											   if (window.ActiveXObject)
												 {
													var doc=new ActiveXObject("Microsoft.XMLDOM");
													doc.async="false";
													doc.loadXML(data);
												}
												// code for Mozilla, Firefox, Opera, etc.
												else
												{
													var parser=new DOMParser();
													var doc=parser.parseFromString(data,"text/xml");
												}// documentElement always represents the root node
												
												var x=doc.documentElement;
											   	var type = x.getAttribute("type");
												if(type == "city")
												{
											   		changeComboOption(city, data);
													city.disabled = false;
												}else
												{
													//alert(data);
													stateDiv.style.display = "block";
													changeComboOption(state, data);
													city.options.length = 0;
													city.options[0] = new Option("Select a state", -1);
													state.disabled = false;
													city.disabled = false;
												}
										   },null,null );
	}
}

function selectLocationState(id)
{
	var country = document.getElementById(id+"country");
	var state = document.getElementById(id+"state");
	var stateDiv = document.getElementById(id+"div");
	var city = document.getElementById(id+"city");
	
	var cvalue = country.options[country.selectedIndex].value;
	var value = state.options[state.selectedIndex].value;
	//alert(value);
	if(value == -1)
	{
		//stateDiv.style.display = "none";
		//state.options.length = 0;
		//state.options[0] = new Option("Select a country", -1);
		city.options.length = 0;
		city.options[0] = new Option("Select a state", -1);
	}else
	{
		url = "ajax//locationpackageresponse.php?action=s&cid="+cvalue+"&sid="+value;
		//stateDiv.style.display = "none"s
		//state.options.length = 0;
		//state.options[0] = new Option("Loading", -1);
		city.options.length = 0;
		city.options[0] = new Option("Loading", -1);
		city.disabled = true;
		
		//alert(url);
		//state.disabled = true;
		var a = new MyAjax(url,"", function()
										   {
											   var data = a.getResponseText();
											   //alert(data);
											   if(changeComboOption(city, data))
											   {
													city.disabled = false;
											   }
											},null,null );
	}
}