var map = null;
var geocoder = null;

function load(jtype,mtype)
{
	if (GBrowserIsCompatible())
	{
		// ,{mapTypes:[G_SATELLITE_TYPE]}
		map = new GMap2(document.getElementById("map"));		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());			
		map.addControl(new GScaleControl());				 
		map.addControl(new GOverviewMapControl());	
		map.enableDoubleClickZoom();		
		if(mtype == 'bw')
		{
			map.setCenter(new GLatLng(12.983, 77.583), 3, G_SATELLITE_TYPE);
		}
		else
		{
			map.setCenter(new GLatLng(12.983, 77.583), 3, G_NORMAL_MAP);			
		}
		
		geocoder = new GClientGeocoder();
		var url = "http://www.1clickhire.com/cntjobs.php?jtype="+ jtype;
		GDownloadUrl(url, function(data, responseCode) {
		  var xml = GXml.parse(data);		  
		  var markers = xml.documentElement.getElementsByTagName("city");
		  if(markers == null){ return; }
		  for (var i = 0; i < markers.length; i++)
		  {
			showAddress(markers[i].getAttribute("name"),
				markers[i].getAttribute("state"), markers[i].getAttribute("country"), markers[i].getAttribute("cnt"));
		  }
		});	
		
	}
	return;
}

function showAddress(jcity,jstate,jcountry,jobCount)
{

	var address = jcity + "," + jstate + "," + jcountry;
	var WIN_HTML = '<h6>' + jobCount + ' job(s) in ' + jcity + '</h6><br/>'
					+ '<a href="http://en.wikipedia.org/wiki/' + jcity + '" target="_blank" title="know more @wikipedia">' + jcity + '</a>-'
					+ '<a href="http://en.wikipedia.org/wiki/' + jstate + '" target="_blank" title="know more @wikipedia">' + jstate + '</a>-'
					+ '<a href="http://en.wikipedia.org/wiki/' + jcountry + '" target="_blank" title="know more @wikipedia">' + jcountry + '</a>';
	
	  if (geocoder) {
	  // Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = "http://www.1clickhire.com/images/mm_20_red.png";
		icon.shadow = "http://www.1clickhire.com/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		
		geocoder.getLatLng(
		  address,
		  function(point) {
			if (!point) {
			  //alert(address + " not found");
			} else {
			  map.setCenter(point, 4);
			  var marker = new GMarker(point,icon);
			  GEvent.addListener(marker, "click", function()
			  {
				marker.openInfoWindowHtml(WIN_HTML);
			  });
			  map.addOverlay(marker);
			}
		  }
		);
	  }
	  return;
}	

function quickload(jcity,jstate,jcountry,mtype,mid)
{
	if (GBrowserIsCompatible())
	{
		displayToggle(mid);		
		var el = document.getElementById(mid).style; 
		if(el.display == "block")
		{
			// ,{mapTypes:[G_SATELLITE_TYPE]}
			map = new GMap2(document.getElementById(mid));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());			
			map.addControl(new GScaleControl());	
			map.enableDoubleClickZoom();	
			geocoder = new GClientGeocoder();
			showAddress(jcity,jstate,jcountry,1);
		}
	}
	return;
}


/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML=""+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop)
{
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
//******************************************** Progress Bar ends *******************

function displayToggle(id) {
  var el = document.getElementById(id).style; 
  if(el.display == "none") {
  el.display = "block";  
  }
  else if(el.display == "block") {
  el.display = "none";
}
}

function visibilityToggle(id) {
  var el = document.getElementById(id).style; 
  if(el.visibility == "hidden") {
  el.visibility = "visible";  
  }
  else if(el.visibility == "visible") {
  el.visibility = "hidden";
}
}

function showHide(id,vis) {
 document.getElementById(id).style.visibility=vis;
}

function showDisplay(id,display) {
 document.getElementById(id).style.display=display;
}

function setMessage(message,elemId) {
    var mdiv = document.getElementById(elemId);
    mdiv.innerHTML = message;
}

function setStyle(id)
{
	var rootElem = document.getElementById(id);	
	
	myfilter=function(node){
		if (node.tagName=="A") //filter out A elements
			return NodeFilter.FILTER_ACCEPT;
		else
			return NodeFilter.FILTER_SKIP;
		}		
		var walker=document.createTreeWalker(rootElem, NodeFilter.SHOW_ELEMENT, myfilter, false);
		
		while (walker.nextNode())
		walker.currentNode.style.fontSize = "medium"; //hide all DIV and IMG elements on the page
}

function ouimaGETAJAX(url,boxid)
{
		var http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

		if (!http_request) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
        http_request.onreadystatechange = function() { alertContents(http_request,boxid); };
        http_request.open('GET', url, true);
        http_request.send(null);   
	
}

function alertContents(http_request,boxid)
{
	var elem = document.getElementById(boxid);
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			var xmldoc = http_request.responseXML;
			var root_node = xmldoc.getElementsByTagName('root').item(0);			
			elem.innerHTML = root_node.firstChild.data;	
		}
		else
		{
			alert('There was a problem with the request.');
			
		}
	}
}

function setScreenImg(imgloc,boxid)
{
	var elem = document.getElementById(boxid);
	elem.innerHTML = imgloc;	
}

function ouimaGETAJAXTxt(url,boxid)
{
		var http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

		if (!http_request) {
			return false;
		}
        http_request.onreadystatechange = function() { alertText(http_request,boxid); };
        http_request.open('GET', url, true);
        http_request.send(null);   
	
}
function alertText(http_request,boxid)
{
	var elem = document.getElementById(boxid);
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			var txtdata = http_request.responseText;
			elem.innerHTML = txtdata;	
			alert(txtdata);
		}
		else
		{
			return;
		}
	}
}


