// JavaScript Document
// ajaxUrl is the web service url
// toCurrency is the currency converted to
// returnFunc
// price is the selected price that is multiplied by the rate
function xmlhttpPost(ajaxUrl,toCurrency,locator,price) {
	var xmlHttpReq = false;
	var parsedRate  ;
	var Rate;
	var self = this;
	if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('GET',ajaxUrl,true);
	self.xmlHttpReq.setRequestHeader('Content-Type','text/xml; charset=utf-8');
	self.xmlHttpReq.onreadystatechange = handleReturn;
    self.xmlHttpReq.send();
	function handleReturn() {
		if (self.xmlHttpReq.readyState == 4) {
			if (self.xmlHttpReq.status == 200) {
				parsedRate = parseXmlOutPut(self.xmlHttpReq.responseText);// parses xml out put to returned rate
					
				//If sri lankan rupees add percentage 20%
						
				Rate = (toCurrency=='LKR')?(price*parsedRate)*1.2:(price*parsedRate);
				contentAreaLoader(toCurrency +" " + Rate.toFixed(2), locator);
				
			} else {
				alert("There was a problem in request. Please try again later"); 
			}
		} else {
			document.getElementById("rate-container-" + locator).innerHTML = 'Wait..';
		}
	}
}
function contentAreaLoader(responseText, locator)
{
	document.getElementById("rate-container-" + locator).innerHTML =responseText; 
}

function parseXmlOutPut(responseXmlValue)
{
	
  if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(responseXmlValue,"text/xml");
  }
else // Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async="false";
  xmlDoc.loadXML(responseXmlValue);
  } 
  return xmlDoc.getElementsByTagName("double")[0].childNodes[0].nodeValue;
}
function displayMessage(message) {
	var fTop = (screen.height)/4;
	var fLeft = ((screen.width)-200)/2;
	var browser = navigator.appName;
	if(browser == "Netscape") {
		document.getElementById("dvMessage").style.top = window.pageYOffset+fTop+'px';
		document.getElementById("dvMessage").style.left = window.pageXOffset+fLeft+'px';
		document.getElementById("dvMessage").innerHTML = "<table width='200' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'><tr><td width='200' height='100' align='Center' class='allBox'>"+message+"</td></tr></table>";
	} else {
		document.getElementById("dvMessage").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvMessage").style.left = document.body.scrollLeft+fLeft;
		window.frames['frmMessage'].document.getElementById('divMessage').innerHTML = "<table width='200' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'><tr><td width='200' height='100' align='Center' class='allBox'>"+message+"</td></tr></table>";
	}
	document.getElementById("dvMessage").style.visibility = 'visible';
}

function citySignup(cid) {
	xmlhttpPost('http://www.bizymoms.com/cityTemplates/ajax/processAjax.php','action=CitySignup&cId='+cid,displayMessage,'Loading Signup Form.<br>Please wait...');
}

function getConversion(fromCurrency, toCurrency, productId) 
{
	var price;
	price = document.getElementById('hidden-price-container-' + productId).value;
	
	xmlhttpPost('http://www.gobigit.com/convertor/convertor.asp?from=' + fromCurrency + '&to='+toCurrency,toCurrency,productId,price);
}


function showPagin(cityId,pageStart)
{
var xmlHttpReq = false;
var self= this;
 if (window.ActiveXObject)
 {
  self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
 }
 else
 {
 
  self.xmlHttpReq = new XMLHttpRequest();
 } 
   self.xmlHttpReq.open("POST","../city-admin/cityLinkFeatured.php",true);
   self.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
   self.xmlHttpReq.onreadystatechange=handleReturn;
   self.xmlHttpReq.send("cityId="+cityId+'&jeg_ft=ft3&jg_page_start='+pageStart);
  	function handleReturn()
	 {
		if (self.xmlHttpReq.readyState == 4) 
		{
				if (self.xmlHttpReq.status == 200)
				{
				 document.getElementById("cityLink").innerHTML=self.xmlHttpReq.responseText;
				}   
				else 
				{
						document.getElementById("cityLink").innerHTML="The city page is unable to access the featured links due to some internal problem. Please try again!!"; 
				}
		}
		else
		{
				document.getElementById("cityLink").innerHTML="<img src=\"../blog-network/images/zoho-busy.gif\"> fetching Featured Interviews and Businesses..";
		}
	}
}

function changeTrans(opacity, id,opacStart,opacEnd) {
	var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}