/**
This file is part of GoogleMap PRO.

GoogleMap PRO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

GoogleMap PRO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GoogleMap PRO.  If not, see <http://www.gnu.org/licenses/>.
 **/

/*****Feedback functions*******/

var stop_nu;
function loadUserFeedback(html) {
	document.getElementById("userFeedback").innerHTML = html;
	opacity("userFeedback", 0, 100, 500);
	stop_nu = setTimeout("opacity(\'userFeedback\', 100, 0, 2000)",7000);
}

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",\'" + id + "\')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",\'" + id + "\')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.display = "block";
	object.filter = "alpha(opacity=" + opacity + ")";
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	if (opacity == 0) {
		object.display = "none";
	}
}

function stop_timeout() {	
	clearTimeout(stop_nu);
	document.getElementById("userFeedback").style.display="none";
}

/*****Replace CarriageReturn *******/
function replaceCarriageReturn(emailBody,replaceWith){
	var emailBody = escape(emailBody); //encode all characters in text area to find carriage return character
	
	for(i=0; i < emailBody.length; i++) {
		if(emailBody.indexOf("%0D%0A") > -1) {
			//Windows encodes returns as \r\n hex
			emailBody=emailBody.replace("%0D%0A",replaceWith)
		}else if(emailBody.indexOf("%0A") > -1) {
			//Unix encodes returns as \n hex
			emailBody=emailBody.replace("%0A",replaceWith)
		}else if(emailBody.indexOf("%0D") > -1) {
			//Macintosh encodes returns as \r hex
			emailBody=emailBody.replace("%0D",replaceWith)
		}
	}
	emailBody=unescape(emailBody) //decode all characters in text area back

	return emailBody;
}

/*****Get raio value *******/
function getRadioVal(radioName) {
  var rads = document.getElementsByName(radioName);

  for(var rad in rads) {
	if(rads[rad].checked)
	  return rads[rad].value;
  }

  return null;
}

function checkCatids(){
	var catids = '';
	for(i=0; i<document.gCatForm.elements.length; i++){
		if(document.gCatForm.elements[i].type=="checkbox" && document.gCatForm.elements[i].checked==true ){
			if(catids) {
				catids +=  "," + document.gCatForm.elements[i].value;
			}else{
				catids = document.gCatForm.elements[i].value;
			}
	
		}
	}
	return catids;
	catids = '';
}

function checkAllCategories(){
	for(i=0; i<document.gCatForm.elements.length; i++){
		if(document.gCatForm.elements[i].type=="checkbox"){
			document.gCatForm.elements[i].checked = true ;

		}
	}
}

//Jumpmenu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//write googlemaps overlay
function writetGooglemapsoverlay() {

	var nTop = document.getElementById("googlemap").offsetTop;
	var nLeft = document.getElementById("googlemap").offsetLeft;
	var nWidth = document.getElementById("googlemap").offsetWidth;
	var nHeight = document.getElementById("googlemap").offsetHeight;

	document.write('<style type="text/css">.GoogleMapsOverlay {'
	+ 'position: absolute; left: '+nLeft+'px; top: '+nTop+'px; width: '+nWidth+'px; height: '+nHeight+'px; background-image: url(components/com_googlepro/assets/images/mapOverlay.png);'
	+ 'z-index: 500; visibility: hidden;'
    + '}</style>');

}


//write googlemaps overlay
function writetPrintoverlay() {
	if(document.getElementById("directions")){
		var nTop = document.getElementById("directions").offsetTop+30; //Plus a little more to get in the box
		var nLeft = document.getElementById("directions").offsetLeft;
		var nWidth = document.getElementById("directions").offsetWidth-120;  //width of print_btn+a little more.)
		var nHeight = document.getElementById("directions").offsetHeight;

		document.write('<style type="text/css">.PrintOverlay {'
		+ 'top: '+nTop+'px; left: '+nWidth+'px;'
		+ 'z-index: 500;'
		+ '}</style>');
	}

}

function getRouteplanningBar(find_address,routing) {
	if(find_address) document.getElementById("getSearchBar").style.visibility="hidden";
	if(routing) document.getElementById("getRouteplanningBar").style.visibility="visible";
}
	
function getSearchBar(find_address,routing) {
	if(find_address) document.getElementById("getSearchBar").style.visibility="visible";
	if(routing) document.getElementById("getRouteplanningBar").style.visibility="hidden";
}

//reset map
function resetmap() {
	if(document.getElementById("directions")) document.getElementById("directions").innerHTML = "";
	if(document.getElementById("directionFeedback")) document.getElementById("directionFeedback").style.display = "none";
	if(document.getElementById("directionFeedback1")) document.getElementById("directionFeedback1").style.display = "none";
	if(document.getElementById("searchResults")) document.getElementById("searchResults").style.display = "none";
	if(document.getElementById("comments")) document.getElementById("comments").style.display = 'block'; 
}

//find markers on map
function vispaakort(z,custom){
	if (custom!='standard') {
		gmarkers[z].openExtInfoWindow(map,custom,info[z],{beakOffset: 3}); 
	}else{
		gmarkers[z].openInfoWindowHtml(info[z]);
	}
}	

//Show options
function getOptions(type) {
	var optionArray = Array();
	var i = 0;
	optionArray[i] = "ShowMap"; 
	if(document.getElementById("getFindAddress")){
		i++;
		optionArray[i]="getFindAddress";
	}
	if(document.getElementById("getFindOnMap")){
		i++;
		optionArray[i]="getFindOnMap";
	}
	if(document.getElementById("getRouteplanning")){
		i++;
		optionArray[i]="getRouteplanning";
	}
	if(document.getElementById("getSearchDestinations")){
		i++;
		optionArray[i]="getSearchDestinations";
	}
	
	for( var i =0; i < optionArray.length; i++) {
		var divId = optionArray[i];
		if(i) document.getElementById(divId).style.display = "none";
		document.getElementById(divId+'Options').setAttribute("class", "");
	}

	switch(type) {
		case '1':
			document.getElementById("ShowMapOptions").setAttribute("class", "active");
			break;
		case '2':
			document.getElementById('getFindAddress').style.display = "block";
			document.getElementById("getFindAddressOptions").setAttribute("class", "active");
			document.getElementById("getFindAddress").style.visibility="visible";
			break;
		case '3':
			document.getElementById('getFindOnMap').style.display = "block";
			document.getElementById("getFindOnMapOptions").setAttribute("class", "active");
			document.getElementById("getFindOnMap").style.visibility="visible";
			break;
		case '4':
			document.getElementById('getRouteplanning').style.display = "block";
			document.getElementById("getRouteplanningOptions").setAttribute("class", "active");
			document.getElementById("getRouteplanning").style.visibility="visible";
			break;		  
		case '5':
			document.getElementById('getSearchDestinations').style.display = "block";
			document.getElementById("getSearchDestinationsOptions").setAttribute("class", "active");
			document.getElementById("getSearchDestinations").style.visibility="visible";
			break;
	}
	
	
	
}

function trim(str){
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

