function showAjaxDialog(widgetId, nodename, requesturi) {
	var dlg = dijit.byId(widgetId);
	dlg.show();
	ajaxLoad(requesturi, nodename);
}
function ajaxLoad(requesturi, nodename) {
	new Ajax.Request(requesturi, {
		  method:'get',
		  onSuccess: function(response) {
		    document.getElementById(nodename).innerHTML=response.responseText;
		  }
		});
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1000,height=1024');");
}
function showDialog(URL, width, height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + width + ",height=" + height + "');");
}
function submitPopupForm(formSubmit){
	formSubmit.submit();
	window.opener.location.reload();
	self.close();
}

var tipParent="";
var tipId="";
function showTip(me,id) {
  tipParent=me;
  tipId = id;
  tipParent.onmousemove=updatePos;
  document.getElementById(tipId).style.display="block";
  window.onscroll=updatePos;
}
function updatePos() {
  var ev=arguments[0]?arguments[0]:event;
  var x=ev.clientX;
  var y=ev.clientY;
  diffX=24;
  diffY=0;
  document.getElementById(tipId).style.top  = y-2+diffY+document.body.scrollTop+ "px";
  document.getElementById(tipId).style.left = x-2+diffX+document.body.scrollLeft+"px";
  tipParent.onmouseout=hideTip;
}
function hideTip() {
  document.getElementById(tipId).style.display="none";
}

function submitPolls(requesturi,votingID) {
	toggleWidget(votingID + "loading", "show");
	 adEntryID=dojo.byId("adEntryID").value;
	 guid=dojo.byId("guid").value;
	 var userOption;
	 for(var i=1;i<=3;i++)
	 {
	 	if(dojo.byId('userVote_'+i).checked)
	 		userOption=dojo.byId('userVote_'+i).value;
	 }
	 dojo.xhrPost({url:requesturi, content:{campEntryID:adEntryID,campguid:guid,userVote:userOption}, load:function (data, ioargs) {
		console.debug(data);
		document.getElementById("votingPane").innerHTML = data;
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
	toggleWidget(votingID + "loading", "hide");
}
var map = null;
var selectedLat;
var selectedLong;
var pointMarkers = new HashLookUp();
var mash = null;
function ContentMarker(content, marker) {
	this.marker = marker;
	this.inOverlay = false;
	this.geoCodedContent = content;
	this.setMarker = function (marker) {
		this.marker = marker;
	};
	this.getMarker = function () {
		return marker;
	};
	this.setGeoCodedContent = function (content) {
		this.geoCodedContent = content;
	};
	this.getGeoCodedContent = function () {
		return this.geoCodedContent;
	};
	this.isInOverlay = function () {
		return this.inOverlay;
	};
	this.setInOverlay = function (inoverlay) {
		 this.inOverlay=inoverlay;
	};
	
	this.openInfoWindows = function () {
		var infoTabs = new HashLookUp();
		var count = 0;
		for (url in this.geoCodedContent.items) {
			infoTabs.addLookUp(infoTabs.length, this.geoCodedContent.items[url]);
		}
		this.marker.openInfoWindowTabsHtml(infoTabs.items);
	};
}
function HashLookUp() {
	this.length = 0;
	this.items = new Array();
	this.removeLookUp = function (key) {
		var value;
		if (typeof (this.items[key]) != "undefined") {
			this.length--;
			var value = this.items[key];
			delete this.items[key];
		}
		return value;
	};
	this.getLookUp = function (key) {
		return this.items[key];
	};
	this.getAtIndex = function (index) {
		return this.items[index];
	};
	this.addLookUp = function (key, value) {
		if (typeof (value) != "undefined") {
			this.length++;
			this.items[key] = value;
		}
		return value;
	};
	this.hasLookUp = function (key) {
		return typeof (this.items[key]) != "undefined";
	};
}
function loadGeoMap(nodename,zoom,lat,long) {
	eval(mash);
	if (map) {
		return;
	}
	
	var mapNode = document.getElementById(nodename);
	if (!mapNode) {
		return;
	}
	if (GBrowserIsCompatible()) {
		var defaultIcon = new GIcon();
		defaultIcon.iconSize = new GSize(16, 16);
		defaultIcon.shadowSize = new GSize(24, 16);
		defaultIcon.iconAnchor = new GPoint(8, 16);
		defaultIcon.infoWindowAnchor = new GPoint(8, 0);
		map = new GMap2(document.getElementById(nodename));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl()); // map, sattelite, hybrid
		map.setCenter(new GLatLng(lat, long), zoom);
	}
}
function centerMap(lat,long,zoom){
	if(!map){
	 return;
	}
	map.setCenter(new GLatLng(lat, long), zoom);
	
}

function addGeoCodedContent(url, title, author, lat, long) {
	var point = new GLatLng(lat, long);
	if (!pointMarkers.hasLookUp(point.toString())) {
		var marker = new GMarker(point);
		var contents = new HashLookUp();
		pointMarkers.addLookUp(point.toString(), new ContentMarker(contents, marker));
	}
	var contentMark = pointMarkers.getLookUp(point.toString());
	var geoCodedContents = contentMark.getGeoCodedContent();
	var message = " <a href='" + url + "'> <b>" + title + "</b></a><br/>" + author ;
	if (geoCodedContents.hasLookUp(url.toString())) {
		geoCodedContents.removeLookUp(url);
	}
	geoCodedContents.addLookUp(url, new GInfoWindowTab(title.split(" ")[0] + " ...", message));
	addContentMarkOnMap(contentMark);
}
function addPointMarkers(geomash) {
	for (var i = 0; i < geomash.length; i++) {
		if (!geomash[i]) {
			continue;
		}
		addGeoCodedContent(geomash[i].url, geomash[i].title, geomash[i].author, geomash[i].text, geomash[i].lat, geomash[i].long);
	}
}
function addContentMarkOnMap(contentMarker) {
	if (!map) {
		return;
	}
	if(contentMarker.isInOverlay())
		return ;
	if (GBrowserIsCompatible()) {
		contentMarker.setInOverlay(true);		
		GEvent.bind(contentMarker.getMarker(), "click", contentMarker, contentMarker.openInfoWindows);
		map.addOverlay(contentMarker.getMarker());
	}
}
function addMarkers() {
	if (GBrowserIsCompatible()) {
		for (contentMarker in pointMarkers.items) {
			addContentMarkOnMap(pointMarkers.items[contentMarker]);
		}
	}
}

function locationChange() {
	this.document.locationForm.submit();
}
function showLocateDialog(widgetId,articleId,nodename,requesturi){
	document.getElementById('currentArticleId').innerHTML = articleId;
	var dlg = dijit.byId(widgetId);
	dlg.show();	
	ajaxLoad(requesturi,nodename);
}
function showCommentDialog(requesturi,widgetId,articleId,divName){
	document.getElementById('currentArticleId').innerHTML = articleId;
	var dlg = dijit.byId(widgetId);
	dojo.xhrPost({url:requesturi,content:{articleguid:articleId},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(divName).innerHTML = data;
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
	dlg.show();		
}

function loadArticle(requesturi,articleId){
	toggleWidget(articleId+'loading','show');
	dojo.xhrPost({url:requesturi,content:{articleguid:articleId},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
	toggleWidget(articleId+'loading','hide');
}


function rateArticle(requesturi,articleId,ratepoint){
	toggleWidget(articleId+'loading','show');
	dojo.xhrPost({url:requesturi,content:{articleguid:articleId,pointvalue:ratepoint},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;			
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
	toggleWidget(articleId+'loading','hide');
}



function loadCategorizedPane(requesturi,categorycode,widgetstate){

	dojo.xhrPost({url:requesturi,content:{articlecategorycode:categorycode,widgetstate:widgetstate},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(categorycode).innerHTML = data;		
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
}



function saveFlag(requesturi,articleId){
toggleWidget(articleId+'loading','show');
	dojo.xhrPost({url:requesturi,content:{articleguid:articleId},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;		
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
	toggleWidget(articleId+'loading','hide');
}
function locateArticle(requesturi){
	
	var articleId = document.getElementById('currentArticleId').innerHTML;
	toggleWidget(articleId+'loading','show');
	dojo.xhrPost({url:requesturi,content:{articleguid:articleId},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;		
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
	toggleWidget(articleId+'loading','hide');
}
function tagArticle(requesturi){
	var articleId = document.getElementById('currentArticleId').innerHTML;
	var tagtext = dijit.byId('tagtext').getValue();
	dojo.xhrPost({url:requesturi,content:{articleguid:articleId,tagtext:tagtext},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;		
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});	
}
function saveComment(requesturi){
var articleId = document.getElementById('currentArticleId').innerHTML;
var commenttext = dijit.byId('commenttext').getValue();
toggleWidget(articleId+'loading','show');
dojo.xhrPost({url:requesturi,content:{articleguid:articleId,commenttext:commenttext},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;		
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
toggleWidget(articleId+'loading','hide');	
}
function toggleWidget(widgetId,state){
	
}
function showDialog(widgetId,articleId){
	document.getElementById('currentArticleId').innerHTML = articleId;
	var dlg = dijit.byId(widgetId);
	dlg.show();	
}
function showThisDialog(widgetTemplate,blogGuid){
	var dlg = dijit.byId(widgetTemplate);
	if(widgetTemplate=='tagDialog')
		dojo.byId('blogGuid').value=blogGuid;
	else
		if(widgetTemplate=='commentDialog')
			dojo.byId('blogGuid').value=blogGuid;
			
	//	dojo.connect(dlg,"onExecute",{blogGuid:blogGuid},"saveTag");
	dlg.show();	
}



function changeWidgetState(requesturi,articleId,widgetState,widgetId){
	if(widgetState == 'MINIMIZED'){
		toggleWidget(articleId,'hide')
		toggleWidget(articleId+'minimized','show')
	}else{
		toggleWidget(articleId,'show')
		toggleWidget(articleId+'minimized','hide')
	}
	
}


function saveCategory(requesturi){
var articleId = document.getElementById('currentArticleId').innerHTML;
var categoryCode = dojo.byId('categorycode').value;
var mediaType = dojo.byId('mediatype').value;
var languageCode = dojo.byId('languagecode').value;
console.debug("Saving category for articleId "+articleId);
console.debug("mediaType :"+mediaType+"CategoryCode :"+categoryCode);
dojo.xhrPost({url:requesturi,content:{articleguid:articleId,catcode:categoryCode,mtype:mediaType,langcode:languageCode},load:function (data, ioargs) {
			//console.debug(data);
		document.getElementById(articleId).innerHTML = data;
		return data;
	}, error:function (data, ioargs) {
		console.debug("Mobchannel error!" + data + ioargs.xhr.status);
	}, timeout:360000});
}

function saveArticle(articleId){
	
}
function shareArticle(articleId){
	
}
function loadPage(){ 

}
function unLoadPage(){ 

}
function locationChange() 
{	this.document.locationForm.submit(); 
}
