// JavaScript Document

numRowItems = 2;					//number of items displayed horizontally in the media browser window...
maxRecordPerPages = 10;				//maximum records to be retrieved...
totalNumberReviewedMediaItems = 0;	//total number of media content elements which have been reviewed and are to be considered
xmlObj = null;			//xml document object
xmlSearchObj = null     //searched xmlobj
sendToPhoneFuncWindow = null;		//'sendToPhone function window'
nodetest = null;
orinode = null;


function createTableRow(){
	
	// creates a table row
    var row = document.createElement("tr");	
	return row;
}//end function 'createTableRow'

function populatePageSelectBox(currentPage,numPages){	
	var objDropdown = $('pageBox');	
	for(i = 1; i<=numPages; i++){
		var objOption = new Option(i,i);	
		objDropdown.options[objDropdown.length] = objOption;
	}	
}


function getTotalReviewedMediaContentItems(){
	var totalNumberMediaItems = xmlObj.getElementsByTagName('item').length;	
	var mediaItems = xmlObj.getElementsByTagName('item');
	
	var counter = 0;	
	for (i=0; i<totalNumberMediaItems; i++){
		if(mediaItems[i].getElementsByTagName('reviewed')[0].firstChild.nodeValue == 1){
			counter++;
		}
	}	
	return counter;
}

function callMyxerSendToPhoneFunc(evt){

	el = Event.element(evt);
	
	if(el.nodeName == 'SPAN'){
		anchorElement = el.parentNode;
		anchorElementId = anchorElement.id;
	}else{
		anchorElement = el;
		anchorElementId = anchorElement.id;	
	}
	
	//obtain the numeric suffix appended to the anchor tag id in order to determine the index of the input hidden field
	//which contains the media content id...
	anchorPrefixString = 'sendToPhone';
	prefixLength = anchorPrefixString.length;
	indexValue = anchorElementId.substr(prefixLength);
	
	mediaContentElement = $('mediaContentId' + indexValue);
	mediaNameElement = $('mediaName' + indexValue);
	mediaAuthorElement = $('mediaAuthor' + indexValue);
	mediaPriceElement = $('mediaPrice' + indexValue);
	mediaImageElement = $('mediaImage' + indexValue);
	openSendToPhoneFunctionWindow(mediaContentElement,mediaNameElement,mediaAuthorElement,mediaPriceElement,mediaImageElement);

	//obtain index from the name of the anchor tag which can make to the hidden field containing the specific media id...
	//Myxer.SendToPhone($('myxerKey').value,mediaContentElement.value);	
	
}//end function 'callMyxerSendToPhoneFunc'

function sendToPhoneAction(transport){
	
	if(transport.responseText){
		

									
		var jsonObj = transport.responseText.evalJSON();
									
		if(Object.inspect(jsonObj.errorsNum) != null || Object.inspect(jsonObj.errorsNum) != 'undefined'){					
			errorNum = jsonObj.errorsNum;
			
			//clear the 'errors' div
			$('status').innerHTML = "";
			
			if(errorNum > 0){
									
				//inserts the error content
				Element.insert('status','<img border="0" src="../../../images/error.png" height="16" width="16"><span class=errorSendToPhone>&nbsp;' + jsonObj.message  + '</span><br /></img>');	
				
			}else{
				//inserts the error content
				Element.insert('status','<img border="0" src="../../../images/mark.gif" height="16" width="16"><span class=errorSendToPhone>&nbsp;' + jsonObj.message  + '</span><br /></img>');	
			}
			
			with ($('status').style){ 
					borderWidth = '1px';
					borderStyle='solid'; 
					borderColor='#0b5ede';
			}
				
		}
	}
	
	
	
	
}//end function 'sendToPhoneAction'


function openSendToPhoneFunctionWindow(mediaContentElement,mediaNameElement,mediaAuthorElement,mediaPriceElement,mediaImageElement){
	
	//content of the dialogue which opens when user selects media content from browser...
	$('mediaBrowserViewWindow').innerHTML = "<div style='background-color:#ffffff;height:15px'></div><div style='padding:10px'><div style='float:left;margin-right:10px'><img height='200px' weight='200px'  src='" + mediaImageElement.value  + "'\/></div><div style='float:left'><div><span class='contentHeader2'>" +  mediaNameElement.value + "</span></div><div><span class='myxerText'>by " +
mediaAuthorElement.value + "</span></div><div style='margin-top:10px'><span class='contentHeader2'>Price:$" + mediaPriceElement.value + "</span></div><div style='padding:5px;margin-top:10px;width:250px;border-width:.2em;border-style:solid;border-color:#fff;'><span class='footerText2'>There are no recurring charges or subscription fees associated with this or any free content download</span></div></div><div style='clear:left'></div><form id='sendToPhoneForm' name='sendToPhoneForm' action=''><div style='margin-top:10px'><span class='contentHeader2'>Enter Your Phone Number: </span><input type='text' name='phoneNumber'/></div><div style='margin-top:5px'><span class='terms'>Standard/other carrier charges may apply. Compatible with most carriers including AT&T, Cellular One, Sprint and TMobile. Text STOP to 69937 to opt out.</span></div><input type='hidden' name='sendToPhoneAction' id='sendToPhoneAction' /><input type='hidden' id='chosenMediaId' name='chosenMediaId' value=''/></form><div style='margin-bottom:5px'><span class='terms2'>Depending on your mobile data plan, your carrier might charge you to receive text messages (or PIX messages) or for internet access. If you don't know what plan you have, you should check with your carrier.</span></div><div id='status' style='text-align:center;margin-bottom:5px;margin-top:10px'></div><div><img src='../../../images/mobilized-sm.jpg'/></div></div>" ;
	
	
	Dialog.confirm($('mediaBrowserViewWindow').innerHTML, {title:"Turf Send To Phone", className:"dialog", width:600, height:440, okLabel: "Send To Phone", cancelLabel:"Cancel", 
		onOk:function(win){ 
		
			//$('login_error_msg').innerHTML='Login or password inccorect'; 	
			//$('login_error_msg').show(); 																																													
			//Windows.focusedWindow.updateHeight(); 
			//new Effect.Shake(Windows.focusedWindow.getId()); 
			//return false;		
			
			$('chosenMediaId').value = mediaContentElement.value;
																																																																																					
			new Ajax.Request('../../../admin/utils/sendToPhone.php',
			{
				method:'post',
				asynchronous:true,
				requestHeaders: {Accept: 'text/xml'},
				parameters:$('sendToPhoneForm').serialize(true),
				onSuccess: 	sendToPhoneAction
			});				
							
		}
	}); 																																						
																																		
}//end function 'openSendToPhoneFunctionWindow'


function populateMyxerMediaBrowserContent(xmlObj,currentPage){
	var totalNumberMediaItems = xmlObj.getElementsByTagName('item').length;	
	var mediaItems = xmlObj.getElementsByTagName('item');
	//console.log('totalNumberMediaItems: ',totalNumberMediaItems);
	//holds the number of table rows containing media content
	numTableRows = 0;
	//counter which holds running count of media items which have been reviewed
	counter = -1;
	
	startIndex = (currentPage * maxRecordPerPages) - maxRecordPerPages ;
	endIndex = currentPage * maxRecordPerPages;	
	if(endIndex > totalNumberMediaItems){
		endIndex = 	totalNumberMediaItems;
	}
	var   oTABLE   =   document.createElement('table')   
	var   oTBody   =   document.createElement("TBODY"); 
	oTABLE.appendChild(oTBody); 
	for (i=startIndex; i<endIndex; i++){
		
		/*This if only considers content if the media has already been reviewed.*/
		if(mediaItems[i].getElementsByTagName('reviewed')[0].firstChild.nodeValue == 1){		
			counter++;
			if(i == 0){
				row = createTableRow();
				numTableRows ++;	
				
			}else if(counter%numRowItems == 0 ){
				row = createTableRow();				
				numTableRows ++;
			}			
			var cell = document.createElement("td");
			var cellContent = document.createElement("div");
			
			//div is created to hold the thumbnail image and given class 'imageMediaContent'
			var imageCellContent = document.createElement("div");
			imageCellContent.className = "imageMediaContent";			
			var mediaImage = new Image();			
			with (mediaImage.style){ 
				borderWidth = '5px';
				borderStyle='solid'; 
				borderColor='#cacaca';
			}
			
			//sets the source of the media content...
			mediaImage.src = mediaItems[i].getElementsByTagName('thumbnail')[0].firstChild.nodeValue;			
			//media Description content div is created and given className 'mediaDescriptionContent'	
			var mediaDescriptionContent = document.createElement("div");
			mediaDescriptionContent.className = 'mediaDescriptionContent';
			
			//div for mediaName content....
			var mediaNameDivElement = document.createElement("div");			
			
			var mediaNameAnchor = document.createElement("a");
			mediaNameAnchor.href="#";
			
			var type = mediaItems[i].getElementsByTagName('type')[0].firstChild.nodeValue; 			
			var itemid = mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue;				
			var artist = mediaItems[i].getElementsByTagName('artist')[0].firstChild.nodeValue;			
			var itemname = mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue;
			var price = mediaItems[i].getElementsByTagName('price')[0].firstChild.nodeValue;
			
			var selected = document.getElementById("browseFilter").options[document.getElementById("browseFilter").selectedIndex].text;
			var popular = "0";
			if(selected == "Premium Picks of the Day")
			{
				popular = "1";
			}
			var url = "http://www.turfbilling.com/displaymixerdata/displaysingle.php/?popular="+popular+"&price="+price+"&type="+type+"&itemid="+itemid+"&artist="+artist+"&itemname="+itemname+"";
			mediaNameAnchor.setAttribute("href",url );
			mediaNameAnchor.id ="mediaName" + i;
			var mediaNameDivValue = document.createTextNode(mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue);
			mediaNameDivElement.className = "mediaName";
			
			//div for price of the media content
			var mediaPriceDivElement = document.createElement("div");
			if(mediaItems[i].getElementsByTagName('price')[0].firstChild.nodeValue == '0.00'){
				mediaPriceDivValue = document.createTextNode('price: FREE');
			}else{
				mediaPriceDivValue = document.createTextNode('price: $' + mediaItems[i].getElementsByTagName('price')[0].firstChild.nodeValue);
			}
			mediaPriceDivElement.className = "mediaPrice";
			
			//div for author information
			var mediaAuthorDivElement = document.createElement("div");
			var mediaAuthorDivValue = document.createTextNode('artist: '+ mediaItems[i].getElementsByTagName('artist')[0].firstChild.nodeValue);
			mediaAuthorDivElement.className = "mediaAuthor";
			
			
			//div for MyxerCode information
			var mediaMyxerCodeDivElement = document.createElement("div");
			var mediaMyxerCodeDivValue = document.createTextNode('Turfcodes: '+mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue);
			mediaMyxerCodeDivElement.className = "mediaPrice";
			
			//div for MyxerCode information
			var mediaMyxerCodeDivElement1 = document.createElement("div");
			var mediaMyxerCodeDivValue1 = document.createTextNode('Text '+mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue+ ' to 69937');
			mediaMyxerCodeDivElement1.className = "mediaPrice";
			
			
			var mediaOperationsContent = document.createElement("div");
			mediaOperationsContent.className = 'mediaOperationsContent';
			
			//content = mediaItems[i].getElementsByTagName('artist')[0].firstChild.nodeValue;
			
			var sendToPhoneAnchor = document.createElement("a");
			sendToPhoneAnchor.href="#";
			var itemid = mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue;
			var str = "alert('a');Myxer.SendToPhone('UJPPAVGF55','"+itemid+"');alert('d');";
			//var str = Myxer.SendToPhoneLoader({ step:'1', targetId:'"+itemid+"', targetType:'content', refreshParent:true });
			sendToPhoneAnchor.setAttribute("onclick", str); 
			//sendToPhoneAnchor.setAttribute("onclick", "Myxer.SendToPhone('UJPPAVGF55', '532545'); return false;"); 
			sendToPhoneAnchor.id ="sendToPhone" + i;
			
			//content id...
			var mediaContentIDField = document.createElement("input");
			mediaContentIDField.id = "mediaContentId" + i;
			mediaContentIDField.type = 'hidden';
			mediaContentIDField.value = mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue;
			
			//media name...
			var mediaNameField = document.createElement("input");
			mediaNameField.id = "mediaName" + i;
			mediaNameField.type = 'hidden';
			mediaNameField.value = mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue;
			
			//media author...
			var mediaAuthorField = document.createElement("input");
			mediaAuthorField.id = "mediaAuthor" + i;
			mediaAuthorField.type = 'hidden';
			mediaAuthorField.value = mediaItems[i].getElementsByTagName('artist')[0].firstChild.nodeValue;
			
			//media price...
			var mediaPriceField = document.createElement("input");
			mediaPriceField.id = "mediaPrice" + i;
			mediaPriceField.type = 'hidden';
			mediaPriceField.value = mediaItems[i].getElementsByTagName('price')[0].firstChild.nodeValue;
			
			//media image(large)...
			var mediaImageField = document.createElement("input");
			mediaImageField.id = "mediaImage" + i;
			mediaImageField.type = 'hidden';
			mediaImageField.value = mediaItems[i].getElementsByTagName('bigthumbnail')[0].firstChild.nodeValue;
			
			//sendToPhoneAnchor.onclick = callMyxerSendToPhoneFunc(mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue);
			
			var sendToPhoneSpan = document.createElement("span");
			sendToPhoneSpan.className = "mediaHeaderStyle3";
			var sendToPhoneSpanValue = document.createTextNode('listen/send to phone');
			
			
			var mediaNameSpan = document.createElement("span");
			mediaNameSpan.className = "mediaName";
			var mediaNameSpanValue = document.createTextNode(mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue);
			mediaNameSpan.appendChild(mediaNameSpanValue);
			mediaNameAnchor.appendChild(mediaNameSpan);
			
			//structures DOM object which will output media content based on user selection (DOM append calls..)
			mediaNameDivElement.appendChild(mediaContentIDField);
			mediaNameDivElement.appendChild(mediaNameField);
			mediaNameDivElement.appendChild(mediaAuthorField);
			mediaNameDivElement.appendChild(mediaPriceField);
			mediaNameDivElement.appendChild(mediaImageField);
			mediaNameDivElement.appendChild(mediaNameAnchor);			
			
			mediaDescriptionContent.appendChild(mediaNameDivElement);			
			mediaPriceDivElement.appendChild(mediaPriceDivValue);
			mediaDescriptionContent.appendChild(mediaPriceDivElement);			
			mediaAuthorDivElement.appendChild(mediaAuthorDivValue);
			mediaDescriptionContent.appendChild(mediaAuthorDivElement);	
			
			//sendToPhoneSpan.appendChild(sendToPhoneSpanValue);
			//sendToPhoneAnchor.appendChild(sendToPhoneSpan);
			
			mediaOperationsContent.appendChild(mediaContentIDField);
			mediaOperationsContent.appendChild(mediaNameField);
			mediaOperationsContent.appendChild(mediaAuthorField);
			mediaOperationsContent.appendChild(mediaPriceField);
			mediaOperationsContent.appendChild(mediaImageField);
			//mediaOperationsContent.appendChild(sendToPhoneAnchor);
			
			mediaDescriptionContent.appendChild(mediaOperationsContent);
			//MyxerCode
			mediaMyxerCodeDivElement.appendChild(mediaMyxerCodeDivValue);
			mediaDescriptionContent.appendChild(mediaMyxerCodeDivElement);
			
			mediaMyxerCodeDivElement1.appendChild(mediaMyxerCodeDivValue1);
			mediaDescriptionContent.appendChild(mediaMyxerCodeDivElement1);
			
			cellContent.appendChild(mediaDescriptionContent);
		
			imageCellContent.appendChild(mediaImage);
			//my uploads, not our uploads
			if(document.getElementById("profileselect")==null)
			{
				var selected = document.getElementById("browseFilter").options[document.getElementById("browseFilter").selectedIndex].text;
				if(selected == "My Uploads")
				{
					//div for mediaName content....
					var editUploadDivElement = document.createElement("div");
					var editUploadAnchor = document.createElement("a");
					editUploadAnchor.href="#";	
					var type = mediaItems[i].getElementsByTagName('type')[0].firstChild.nodeValue; 			
					var itemid = mediaItems[i].getElementsByTagName('id')[0].firstChild.nodeValue;		
					var artist = mediaItems[i].getElementsByTagName('artist')[0].firstChild.nodeValue;			
					var itemname = mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue;
					var price =    mediaItems[i].getElementsByTagName('price')[0].firstChild.nodeValue;					
					//var category = mediaItems[i].getElementsByTagName('category')[0].firstChild.nodeValue;
                   
					editUploadAnchor.setAttribute("href", "http://www.turfbilling.com/displaymixerdata/editcontent.php/?type="+type+"&itemid="+itemid+"&artist="+artist+"&price="+price+"&itemname="+itemname+"");	
					//editUploadAnchor.setAttribute("href", "http://www.turfbilling.com/displaymixerdata/dedicated.php/?type="+type+"&itemid="+id+"&artist="+artist+"&itemname="+name+"");			
					editUploadAnchor.id ="editUpload" + i;
					var editUploadDivValue = document.createTextNode(mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue);
					editUploadDivElement.className = "editUpload";
					
					//edit uploaded content				
					var editUploadSpan = document.createElement("span");
					editUploadSpan.className = "editUpload";
					var editUploadSpanValue = document.createTextNode('Edit Details');
					editUploadSpan.appendChild(editUploadSpanValue);
					editUploadAnchor.appendChild(editUploadSpan);	
					
					
					editUploadDivElement.appendChild(editUploadAnchor);			
					imageCellContent.appendChild(editUploadDivElement);
				}
			}
			cellContent.appendChild(imageCellContent);
			cell.appendChild(cellContent);
			row.appendChild(cell);
			oTBody.appendChild(row) 
			
			////$('browseContent').appendChild(row);Event.observe("sendToPhone" + i,'click', callMyxerSendToPhoneFunc);
			
		}else{
			continue;	
		}
	}//end 'for'
	document.getElementById("browseContent").appendChild(oTABLE);		
	var numPages = Math.ceil(totalNumberReviewedMediaItems/maxRecordPerPages);
	
	if(numPages < 1){
		numPages = 1;	
	}

	if($('numPagesSpan').hasChildNodes()){
		$('numPagesSpan').removeChild($('numPagesSpan').childNodes[0]);
	}
		
	//populates the total number of pages of content...
	$('numPagesSpan').appendChild(document.createTextNode(numPages));
	
	//populates the page number options within the select box which allows the user to select a specific page of content
	$('pageBox').innerHTML = "";
	 populatePageSelectBox(currentPage,numPages);
	 
	 $('pageBox').selectedIndex  = $('currentPage').value - 1;
	
	 //closes the loading window
	 closeDialog();
	
	 
}//end 'populateMyxerMediaBrowserContent'
function clearAllNode(parentNode){
    while (parentNode.firstChild) {
      var oldNode = parentNode.removeChild(parentNode.firstChild);
       oldNode = null;
     }
   } 
function gotoPageContent(selectedPage){
	currentPage = $('currentPage').value;
	populateMyxerMediaBrowserContent(xmlObj,currentPage);
	
}//end function 'gotoPageContent'

function processXMLResponse(transport) {	
	xmlObj = transport.responseXML;		
	var currentPage = $('currentPage').value;	
	totalNumberReviewedMediaItems = getTotalReviewedMediaContentItems();	
	populateMyxerMediaBrowserContent(xmlObj,currentPage);	
}

function deleteUnSearchedItem(itemid)
{	
	var items = xmlSearchObj.getElementsByTagName('item');	
	var len = items.length;	
	var itemParentNodeList = xmlSearchObj.getElementsByTagName("items");	//NodeList		
	var itemParentNode = itemParentNodeList.item(0);	
	var itemNodes = itemParentNode.childNodes;	
	for(i=0;i<len;i++) {		
		var id = items[i].getElementsByTagName('id')[0].firstChild.nodeValue;
		
		  if(id == itemid)
		  {
			 
			  xmlSearchObj.getElementsByTagName("items").item(0).removeChild(itemNodes[i]);	
		      break;
		  }
	}
}
function getTotalSearchedMediaContentItems(keyword){
	xmlSearchObj = xmlObj;		
	orinode = xmlObj.getElementsByTagName("items").item(0).cloneNode(true);	
	var totalNumberMediaItems = xmlObj.getElementsByTagName('item').length;		
	var mediaItems = xmlObj.getElementsByTagName('item');
	var counter = 0;	
	var results = new Array();
	var j =0;	
	for(i=0; i<totalNumberMediaItems; i++)
	{
		if(mediaItems[i].getElementsByTagName('reviewed')[0].firstChild.nodeValue == 1){			
			var itemname = mediaItems[i].getElementsByTagName('name')[0].firstChild.nodeValue;
			if((itemname.toUpperCase()).indexOf(keyword.toUpperCase())!=-1)
			{
				results[j] = mediaItems[i];
			    counter++;
			    j++;	
			}
			
		}
	}	
	clearAllNode(xmlSearchObj.getElementsByTagName("items").item(0));
	var len = xmlSearchObj.getElementsByTagName("item").length;
	for(i=0;i<results.length;i++)
	{
		xmlSearchObj.getElementsByTagName("items").item(0).appendChild(results[i]);
	}	
	var len = xmlSearchObj.getElementsByTagName("item").length;
	return counter;
}


function procesSearchResponse()
{	
	var currentPage = $('currentPage').value;	
    var keyword = document.getElementById("kw").value;     
    clearAllNode(document.getElementById("browseContent"));   
	totalNumberReviewedMediaItems = getTotalSearchedMediaContentItems(keyword);	
	populateMyxerMediaBrowserContent(xmlSearchObj,currentPage);
	clearAllNode(xmlObj.getElementsByTagName("items").item(0));
	xmlObj.getElementsByTagName("items").item(0).appendChild(orinode);
}
function appenditemsnode(results)
{
	var items = document.getElementById("items");	
	
	for(i=0;i<results.length;i++)
	{		
		items.appendChild(results[i]);	
	}
}
function loadMyxerBrowser(){	

	new Ajax.Request('manageMyxerSpecialFeeds.php',
	{
		method:'post',
		asynchronous:true,
		requestHeaders: {Accept: 'text/xml'},
		parameters:$('myxerBrowserForm').serialize(true),
		onLoaded:openDialog('loadingWindow'),
		onSuccess: 	processXMLResponse
	});		
	
}
//loads Myxer Media Browser with media content
function loadMyxerBrowser(user,myxid){	
	
	new Ajax.Request('manageMyxerSpecialFeeds.php?user='+user+'&myxid='+myxid,
	{
		method:'post',
		asynchronous:true,
		requestHeaders: {Accept: 'text/xml'},
		parameters:$('myxerBrowserForm').serialize(true),
		onLoaded:openDialog('loadingWindow'),
		onSuccess: 	processXMLResponse
	});	
	
}

//Resets the options in the media browser...
function clearMediaBrowserContent(){
	$('browseContent').innerHTML = "";
}

function refreshResults(evt){	
	el = Event.element(evt);
	var filterValue = el.value; 
	
	
	//clear the contents of the media browser
	clearMediaBrowserContent();
	
	if(el.id == 'pageBox'){
		$('currentPage').value = el.value;
		gotoPageContent($('currentPage').value);
	}else{
		$('currentPage').value = 1;
		
		if(filterValue == 'our_uploads'){
			
			//query all user's data
			var sURL = "http://www.turfbilling.com/displaymixerdata/queryuser.php";
			new Ajax.Request(sURL,
					{
						method:'post',
						asynchronous:false,		
						requestHeaders: {Accept: 'application/json'},
						onComplete: 	processUserResponse
					});
			
			var sel = document.getElementById("profileselect");
			var user;
			var myxid;
			user = sel.options[0].text;
		    myxid = sel.options[0].value;
			$('function').value = 'profile/'+myxid;	
			loadMyxerBrowser(user,myxid);
			
		}else if(filterValue == 'edit_my_uploads'){
			
			$('function').value = 'profile';
			loadMyxerBrowser();	
		}else if(filterValue == 'potd'){
			$('function').value = 'potd';			
			loadMyxerBrowser();				
		}else{
			//$('function').value = 'profile/'+;	
			// when select a user
			
			var sel = document.getElementById("profileselect");
			var user;
			var myxid;
			for(var i =0;i<sel.options.length;i++)
			{
				if(sel.options[i].selected)
				{
					user = sel.options[i].text;
					myxid = sel.options[i].value;
					break;
				}
			}
			$('function').value = 'profile/'+myxid;	
			loadMyxerBrowser(user,myxid);	
		}		
			
	}
}



function processUserResponse(transport) {	
	//callback obtains the XML response object
	var userprofiles = transport.responseText;
	var arr = userprofiles.split("%%");	
	var users = arr[0].split("#");	
	var profiles = arr[1].split("@");
	var sel=document.getElementById('profileselect');
	sel.length=0;
	  for(var i=0;i<users.length;++i){		  
		  addOption(sel, users[i],profiles[i]);
	  }
						
}//end function 'cleanseJSONResponse'	

function addOption(oListbox, sName, sValue) {
	var oOption = document.createElement("option");
	oOption.appendChild(document.createTextNode(sName));
	if (arguments.length == 3) {	
			oOption.setAttribute("value", sValue);
	}
	oListbox.appendChild(oOption);
}
function selectfile()
{
	
	document.getElementById("fileToUpload").click();
}
function visit(obj) { 
	
    var props = "";
    for(var p in obj){        
           // alert(p); 
    }
}

