var webRoot = 'http://www.poidb.com';            
var request = create_Object();
var temppoiid;	 

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};
	

	
function create_Object()
{
var xmlhttp;
	// This if condition for  Firefox and  Opera  Browsers	
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  {
		try 
		{
		  xmlhttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			alert("Your browser is not supporting XMLHTTPRequest");
			xmlhttp = false;
		}
	}
	// else condition for  ie
	else
	{
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
  return xmlhttp;
}

function addpoi_interaction()
	{
	if(request.readyState == 1)
		{
		document.getElementById('poi-' + temppoiid).innerHTML='';
		document.getElementById('poi-' + temppoiid).innerHTML = '<img src="/images/spinner.gif">&nbsp;Updating...';
		}
	if(request.readyState == 4)
		{
		var answer = request.responseText;
		document.getElementById('poi-' + temppoiid).innerHTML='';
		document.getElementById('poi-' + temppoiid).innerHTML = answer;
		}
	}
	
function addpoi(poiid)   
	{
		temppoiid = poiid;
		request.open("GET", "/poi/aja_addtolist.asp?poiid=" + poiid + "&r=" + rand(1000)); 
		request.onreadystatechange = addpoi_interaction;
		request.send('');
	}  
	
/************* NEW FUNCTIONS ***************/
// Add new string functions
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.toTitleCase = function() { 
	var ls = this.toLowerCase();
	var la = ls.split(' ');
	for (var i=0; i<la.length; i++) la[i] = la[i].charAt(0).toUpperCase()+la[i].slice(1);
	return la.join(' ');
}

function resize16x9 (element) {
	if (typeof element == 'undefined') return;
	if (typeof element == 'string') {
		if (element = document.getElementById(element));
		else return;
	}
	width = element.clientWidth;
	height = Math.round((width/16)*9);
	element.style.height = height+'px';
}

/************* MAPPING ***************/

function showMap (insertafter, width, latitude, longitude, caption) {
	if (!insertafter) return true;
	if (!width) var width = '100%';
	if (!latitude) return true;
	if (!longitude) return true;
	if (!caption) var caption = '';
	if (insertafter.nextSibling != null && classExists(insertafter.nextSibling, 'map')) { // collapse video player if already open
		if (insertafter != null) classRemove(insertafter, 'active');
		insertafter.nextSibling.parentNode.removeChild(insertafter.nextSibling);
	}
	else {
		classAdd(insertafter, 'active');
		var div = document.createElement('DIV');
		div.className = 'map';
		div.style.width = width;
		div.style.height = '1px';
		insertafter.parentNode.insertBefore(div, insertafter.nextSibling);
		resize16x9(div);
		div.innerHTML = ('<iframe src="http://www.poidb.com/smallmap.htm?latitude='+encodeURIComponent(latitude)+'&amp;longitude='+encodeURIComponent(longitude)+'&amp;caption='+encodeURIComponent(caption)+'" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>');
	}
	if (insertafter.blur) insertafter.blur(); // removes dotted outline from link in Mozilla browsers
	return false;
}

// Add a CSS class to the specified element (will not add the class if it already exists)
function classAdd (element, theclass) {
	if (!element) return;
	if (!element.className) element.className = '';
	var reg = new RegExp('(^| )'+theclass+'( |$)', 'g');
	if (element.className.search(reg) == -1) element.className = (element.className + ' ' + theclass).trim();
}

// Remove a CSS class from the specified element
function classRemove (element, theclass) {
	if (!element) return;
	if (!element.className) return;
	var reg = new RegExp('(^| )'+theclass+'( |$)', 'g');
	element.className = element.className.replace(reg, ' ').trim();
}

// Return true if a class name exists in the specified element
function classExists (element, theclass) {
	if (!element) return false;
	if (!element.className) return false;
	var reg = new RegExp('(^| )'+theclass+'( |$)', 'g');
	return reg.test(element.className);
}


function swap(id1,id2){
on(id1);
off(id2);
return true;
};
 
function on(_8a){
if(document.getElementById(_8a)!=null){
document.getElementById(_8a).style.display="block";
}
return true;
};

function off(_8b){
if(document.getElementById(_8b)!=null){
document.getElementById(_8b).style.display="none";
}
return true;
};


function URLencode(sStr) {
    return escape(sStr)
       .replace(/\+/g, '%2B')
          .replace(/\"/g,'%22')
             .replace(/\'/g, '%27');
  }

function submitonce(form) 
{
   form.submit.disabled=true;
   return true;
}
function creat_Object()
{
var xmlhttp;
	// This if condition for  Firefox and  Opera  Browsers	
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  {
		try 
		{
		  xmlhttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			alert("Your browser is not supporting XMLHTTPRequest");
			xmlhttp = false;
		}
	}
	// else condition for  ie
	else
	{
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
  return xmlhttp;
}
	
var request = creat_Object();

 function toggleDisplay(divName){
	var tempDiv = document.getElementById(divName);
	if (!tempDiv) {
		return;
	}
	if ((tempDiv.style.display=="block")||(tempDiv.style.display=="" && tempDiv.className.indexOf("hid") == 0)){
		tempDiv.style.display="none";
	} else if ((tempDiv.style.display=="none")||(tempDiv.className.indexOf("hid") != 0)){
		tempDiv.style.display="block";
	}
}


	/* functions of rating*/
	function turnOnStarsOnMouseOver(rating,imggrp) 
	{
		turnOnOffStars(rating,imggrp);
		//turnOffStars('10',imggrp);
		//turnOnStars(rating,imggrp);
	}
	function turnOffStarsOnMouseOut(currentRatingId,imggrp) 
	{
		turnOnOffStars(document.getElementById(currentRatingId).value,imggrp);
		//turnOffStars('10',imggrp);
		//turnOnStars(document.getElementById(currentRatingId).value,imggrp);
	}
	function turnOnOffStars(rating,imggrp) 
	{
		if(!imggrp)imggrp=='D';
		var imgGrpArr = new Array();
		imgGrpArr['D'] = new Array('img_star_object-half.gif','img_star_object-half2.gif','img_star_object_grey-half.gif','img_star_object_grey-half2.gif');
 		imgGrpArr['H'] =new Array('img_star_half1.gif','img_star_half2.gif','img_star_greyhalf1.gif','img_star_greyhalf2.gif');
 		var cimg=0;
 		if(parseInt(rating)<=0)rating=0;
		for(i=10; i>0; i--) 
		{
			cimg =(i%2==0)?(1):(0); 
			cimg = (i>rating)?(cimg+2):cimg;
			document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][cimg];
		}
	}
	function turnOffStars(rating,imggrp) 
	{//'FH'=>'img_star_half1.gif','LH'=>'img_star_half2.gif','FHG'=>'img_star_greyhalf1.gif','LHG'=>'img_star_greyhalf2.gif'
		if(!imggrp)imggrp=='D';
		var imgGrpArr = {};
 		imgGrpArr['D'] = new Array('img_star_object_grey-half.gif','img_star_object_grey-half2.gif');
 		imgGrpArr['H'] =new Array('img_star_greyhalf1.gif','img_star_greyhalf2.gif');
		for(i=rating; i>0; i--) 
		{
			
			if(i%2==0) 
			{
				document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][1];
			}
			else 
			{
				document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][0];
			}
		}
	}

	function turnOnStars(rating,imggrp) 
	{
		if(!imggrp)imggrp=='D';
		var imgGrpArr = {};
		imgGrpArr['D'] = new Array('img_star_object-half.gif','img_star_object-half2.gif');
 		imgGrpArr['H'] =new Array('img_star_half1.gif','img_star_half2.gif');
		for(i=rating; i>0; i--) 
		{
		
			if(i%2==0) 
			{
				document.getElementById('star' + i).src = webRoot+"/images/"+imgGrpArr[imggrp][1];
			}
			else 
			{
				document.getElementById('star' + i).src =  webRoot+"/images/"+imgGrpArr[imggrp][0];
			}
		}
	}
	function giveRating(rating, destId,imggrp) 
	{
		if(!imggrp || typeof(imggrp)=='undefined' || imggrp==null)imggrp='D';
		document.getElementById(destId).value = rating;
		//alert(document.getElementById(destId).value)
		turnOnOffStars(rating,imggrp);
		//turnOffStars('10',imggrp);
		//turnOnStars(rating,imggrp);
	}
	/* end functions of rating*/
