﻿$.ajaxSetup ({
    cache: false
});

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function ShowWeatherBox(id){
	sLink = './weather.php';
	$.ajax({
	  type: "GET",
	  url: sLink,
	  data: "id=" + id,
	  dataType: "xml",
	  cache: false,
	  success: function(data) {
		  vAdImg = $(data).find('AdImg').text();
		  vAdImg1 = $(data).find('AdImg1').text();
		  vAdImg2 = $(data).find('AdImg2').text();
		  vAdImg3 = $(data).find('AdImg3').text();
		  vAdImg4 = $(data).find('AdImg4').text();
		  vAdImg5 = $(data).find('AdImg5').text();
		  vAdWeather = $(data).find('Weather').text();
		  GetWeatherBox(vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vAdWeather)
	  }
	});
}

function GetWeatherBox(vImg, vImg1, vImg2, vImg3, vImg4, vImg5, vWeather){
	var sImgDo = '';
	var sImgWeather = '';
	sImgWeather += '<img src="' + TEMPLATE_PATH + '/images/weather/'+ vImg + '" alt="" />&nbsp;';
	sImgDo += '<img src="' + TEMPLATE_PATH + '/images/weather/' + vImg1 + '" alt="" />&nbsp;';
	if(vImg2!='') sImgDo += '<img src="' + TEMPLATE_PATH + '/images/weather/' + vImg2 + '" alt="" />&nbsp;';
	if(vImg3!='') sImgDo += '<img src="' + TEMPLATE_PATH + '/images/weather/' + vImg3 + '" alt="" />&nbsp;';
	if(vImg4!='') sImgDo += '<img src="' + TEMPLATE_PATH + '/images/weather/' + vImg4 + '" alt="" />&nbsp;';
	if(vImg5!='') sImgDo += '<img src="' + TEMPLATE_PATH + '/images/weather/' + vImg5 + '" alt="" />&nbsp;';
	sImgDo += '<img src="' + TEMPLATE_PATH + '/images/weather/c.gif" alt="" />&nbsp;';
	
	$(document).ready( function() {
		$('div#tdImgWeather').html(sImgWeather);
		$('div#tdImgDo').html(sImgDo);
		$('div#tdWeather').html(vWeather);
	});
}

function ShowForexRate(returner)
{
    function GetForexRow(Currency, Rate,classes)
    {
        return '<tr class='+classes+'><td>' + Currency + '</td><td>' + Rate + '</td></tr>';
    }
    var sHTML='';    
    if (typeof(vForex1) !='undefined' && typeof(vCost1) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex1, vCost1,'row1'));
     if (typeof(vForex2) !='undefined' && typeof(vCost2) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex2, vCost2,'row2'));
     if (typeof(vForex3) !='undefined' && typeof(vCost3) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex3, vCost3,'row1'));
     if (typeof(vForex4) !='undefined' && typeof(vCost4) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex4, vCost4,'row2'));
     if (typeof(vForex5) !='undefined' && typeof(vCost5) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex5, vCost5,'row1'));
     if (typeof(vForex6) !='undefined' && typeof(vCost6) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex6, vCost6,'row2'));
     if (typeof(vForex7) !='undefined' && typeof(vCost7) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex7, vCost7,'row1'));
     if (typeof(vForex8) !='undefined' && typeof(vCost8) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex8, vCost8,'row2'));
     if (typeof(vForex9) !='undefined' && typeof(vCost9) !='undefined') sHTML=sHTML.concat(GetForexRow(vForex9, vCost9,'row1'));
     if (typeof(vForex10)!='undefined' && typeof(vCost10)!='undefined') sHTML=sHTML.concat(GetForexRow(vForex10, vCost10,'row2'));
     if (typeof(vForex11)!='undefined' && typeof(vCost11)!='undefined') sHTML=sHTML.concat(GetForexRow(vForex11, vCost11,'row1'));
     if (typeof(vForex12)!='undefined' && typeof(vCost12)!='undefined') sHTML=sHTML.concat(GetForexRow(vForex12, vCost12,'row2'));
     if (typeof(vForex13)!='undefined' && typeof(vCost13)!='undefined') sHTML=sHTML.concat(GetForexRow(vForex13, vCost13,'row1'));
     if (typeof(vForex14)!='undefined' && typeof(vCost14)!='undefined') sHTML=sHTML.concat(GetForexRow(vForex14, vCost14,'row2'));     
     sHTML=sHTML.concat('');
     $("#"+returner).html(sHTML);
}