﻿// JavaScript Document
var rVal = 0;

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload=function(){
if (document.getElementById("newsText")){
if (document.getElementById("newsText").offsetHeight > 320){
document.getElementById("extraHeight").style.height = "0px"
}else{
document.getElementById("extraHeight").style.height =  eval(320 - document.getElementById("newsText").offsetHeight) + "px";
}
}
//Nifty("div#mainContent","big bottom");
Nifty("div#newsSectionHeader","normal top");
Nifty("div#newsSectionContent","normal bottom");
Nifty("div#catsSectionHeader","normal top");
Nifty("div#catsSectionContent","normal bottom");
Nifty("div#pictureNewsSectionHeader","normal top");
Nifty("div#pictureNewsSectionContent","normal bottom");
Nifty("div#pageFooter","normal");
Nifty("div#adverSectionContent","normal");
Nifty("div#pollsSectionHeader","normal top");
Nifty("div#pollsSectionContent","normal bottom");
Nifty("div#weatherSectionHeader","normal top");
Nifty("div#weatherSectionContent","normal bottom");
Nifty("div#newsBoxSectionContent","normal");
Nifty("div#redSection","normal");
}

function showCatNews(c,t){
	document.getElementById("selCatImg").src = "/Images/cats/" + c + ".gif";
	document.getElementById("catNewsList").innerHTML = "<img src='/Images/loader.gif'>";
    document.getElementById("curType").value = t;
    document.getElementById("curCat").value = c;
    if (t == 1){
	document.getElementById("catListImg_2").src = "/Images/catListImg_2_off.gif";
	document.getElementById("catListImg_1").src = "/Images/catListImg_1_on.gif";
    }
    if (t == 2){
	document.getElementById("catListImg_1").src = "/Images/catListImg_1_off.gif";
	document.getElementById("catListImg_2").src = "/Images/catListImg_2_on.gif";
    }
	loadXMLDoc("http://www.finalenews.com/listCatNews.aspx?c=" + c + "&t=" + t);
	}

function getPoll(p,a,s){
document.getElementById("pollContent").innerHTML = "<img src='/Images/loader.gif'>";
if (a == "0"){
var myPoll = readCookie("curPoll");
var myVal = readCookie("curVal");
if ((myPoll != null) && (myVal != null)){
loadXmlPoll("http://www.finalenews.com/loadPoll.aspx?pid=" + myPoll + "&s=" + s + "&a=" + myVal);
}else{
loadXmlPoll("http://www.finalenews.com/loadPoll.aspx?pid=0&s=" + s);
}

}else{
	createCookie("curPoll",p,60);
	createCookie("curVal",a,60);
	loadXmlPoll("http://www.finalenews.com/loadPoll.aspx?a=" + a);
	}
}


var xmlhttp,xmlhttp1,xmlhttp2

function loadXMLDoc(url)
{
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=xmlhttpChange
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=xmlhttpChange
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function xmlhttpChange(){
if (xmlhttp.readyState==4)
  {
  if (xmlhttp.status==200)
    {
   	document.getElementById("catNewsList").innerHTML = xmlhttp.responseText;
    }
  }
}

function loadXmlPoll(url)
{
if (window.XMLHttpRequest)
  {
  xmlhttp1=new XMLHttpRequest()
  xmlhttp1.onreadystatechange=xmlPollData
  xmlhttp1.open("GET",url,true)
  xmlhttp1.send(null)
  }
else if (window.ActiveXObject)
  {
  xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp1)
    {
    xmlhttp1.onreadystatechange=xmlPollData
    xmlhttp1.open("GET",url,true)
    xmlhttp1.send()
    }
  }
}


function xmlPollData(){
if (xmlhttp1.readyState==4)
  {
  if (xmlhttp1.status==200)
    {
   	document.getElementById("pollContent").innerHTML = xmlhttp1.responseText;
    }
  }
}

function loadWeather(url)
{
if (document.getElementById("wMesseger")){
document.getElementById("wMesseger").innerHTML = "<img src='/Images/loader.gif'> لطفا منتظر بمانید.";
}
if (window.XMLHttpRequest)
  {
  xmlhttp2=new XMLHttpRequest()
  xmlhttp2.onreadystatechange=xmlWeatherData
  xmlhttp2.open("GET",url,true)
  xmlhttp2.send(null)
  }
else if (window.ActiveXObject)
  {
  xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp2)
    {
    xmlhttp2.onreadystatechange=xmlWeatherData
    xmlhttp2.open("GET",url,true)
    xmlhttp2.send()
    }
  }
}

function xmlWeatherData(){
if (xmlhttp2.readyState==4)
  {
  if (xmlhttp2.status==200)
    {
   	document.getElementById("weatherContent").innerHTML = xmlhttp2.responseText;
    }
  }
}

function getWeather(st){
$('#wLoaderImg').attr("style","visibility:visible;border:none");
 $.ajax({
   type: "GET",
   url: "getWeather.aspx",
   data: "station=" + st,
   dataType: "text",
   success: function(msg){
    var arr = msg.split("|");
     if (arr[0] == "0") {
			alert(arr[1]);
			$('#wLoaderImg').attr("style","visibility:hidden;border:none");
		}
     if (arr[0] == "1") {
			$('#weatherContent').html(arr[1]);
			$('#wLoaderImg').attr("style","visibility:hidden;border:none");
		}
   }
 });
}