﻿// Java Script Writen by Razmic Valijan --- Sep 2007 ---
var task="";
function SwfNo1() 
{	
   var so = new SWFObject("adslaccess.swf", "mymovie", "200", "100", "7", "#336699");
   so.write("flashcontent");
}

function detectBrowser()
{
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer")
&& (version>=4))  {alert("Your browser is good enough!")}
else
  {alert("It's time to upgrade your browser!")}
  }

	
	var IE = document.all?true:false
	var tempX =800;
	var tempY =300;
	var cd = "";
	var xmlHttp;
	var fl ="";
	var fln = "";
	var xmlHttp2;
	var ntest="";
	var checkLoadedPage = "";

	function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } 
  else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  return true
}

	function LotOverTimeOn() {
	if (checkLoadedPage != "lottimer") {loadpage('lottimer'); checkLoadedPage="lottimer";}
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	document.onmousemove = getMouseXY;
	document.getElementById("lottimediv").style.display = "";
	document.getElementById("lottimediv").style.left = tempX + 7;
	document.getElementById("lottimediv").style.top = tempY + 10;	
}


function overStoreOn() {
	if (checkLoadedPage != "onlinestore") {loadpage('onlinestore'); checkLoadedPage="onlinestore";}
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	document.onmousemove = getMouseXY;
	document.getElementById("lottimediv").style.display = "";
	document.getElementById("lottimediv").style.left = tempX + 7;
	document.getElementById("lottimediv").style.top = tempY + 10;
}
function overPopupDivOff()
{
	document.getElementById("lottimediv").style.display = "none";
}

function WinnersPopupOn() {
	if (checkLoadedPage != "winnerspop") {loadpage('winnerspop'); checkLoadedPage="winnerspop";}
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = getMouseXY;
	document.onmousemove = getMouseXY;
	document.getElementById("lottimediv").style.display = "";
	document.getElementById("lottimediv").style.left = tempX + 7;
	document.getElementById("lottimediv").style.top = tempY + 10;
}

//**************************************************************************************************
	function createXMLHttpRequest() 
	{
		if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
		}
	}
	function loadData(code) 
	{	
		cd = code;
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handleStateChange3;
		var url = "MarketEdit.aspx?act=loadData&value=" + cd;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	
	}
	function handleStateChange3()
	{
		
		if (xmlHttp.readyState == 1) {
			document.getElementById("wait").style.display = "inline";
			}
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) 
			{
		//	document.getElementById("wait").style.display = "";
			var xmlDoc=loadXMLDoc("../resultdata.xml");
			var x = xmlDoc.getElemnetByTagName('desc');
		//	document.getElementById("code").value= xmlDoc.getElementsByTagName("code")[0].childNodes[0].nodeValue;
			document.getElementById("wait").innerText= x[0].childNodes[0].nodeValue;
		//	document.getElementById("txtdesc").innerText= xmlDoc.getElementsByTagName("desc")[0].childNodes[0].nodeValue;
		//	document.getElementById("txtPrice").innerText= xmlDoc.getElementsByTagName("price")[0].childNodes[0].nodeValue;
		//	document.getElementById("txtAmount").innerText= xmlDoc.getElementsByTagName("amount")[0].childNodes[0].nodeValue;
			}
			if (xmlHttp.status == 500) {
			document.getElementById("wait").innerHTML = "<font color=red size=2 face=tahoma>اشکالی در ارتباط با سرور بوجود آمده</font></center>";

			}	
		}
	}
	
	function uploadfile(filepath) 
	{
		fl = filepath;
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handleStateChange;
		var url = "marketAdd.aspx?act=upload&filepath=" + fl;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	function handleStateChange()
	{
		
		if (xmlHttp.readyState == 1) {
			document.getElementById("upload").style.display = "none";
			document.getElementById("resultDiv").style.display = "";
			document.getElementById("resultDiv").innerHTML = "لطفا چند لحظه صبر کنید<img border=0 src='images/ajax_loader.gif'>";
			}
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) 
			{
				ShowResult();
			}
			if (xmlHttp.status == 500) {
			document.getElementById("upload").style.display = "none";
			document.getElementById("resultDiv").innerHTML = "<font color=red size=2 face=tahoma>اشکالی در ارسال فایل بوجود آمده</font></center>";
			}	
		}
	}
	function ShowResult()
	{
		var flt = fl.split("\\");
		var len = flt.length;
	//	document.getElementById("frm").src = "./result.html";;
	var loadResult ="<table style='width: 100%' class='news'> " +
	        "<tr><td style='width: 524px;text-align: center;'>فایل با موفقیت به سرور انتقال یافت<br />	جهت حذف فایل و ارسال فایل جدید <span onclick=\"delback('delpic1');\" style='color:red; cursor: pointer'>اینجا</span> را کلیک کنید</td>"+
			"<td style='text-align: center'>" +
		    "<img alt='' src='./images/market/" + flt[len-1] +"' width='193' height='131' border=1/></td></tr></table>"

		document.getElementById("resultDiv").innerHTML = loadResult;
	}

	function delback(n)
	{
		ntest = n;
		now = new Date();
		var sec = now.getSeconds();
		var url = "marketAdd.aspx?act=delfile&time=" + sec;
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handleStateChange2;
		if (ntest == "delpic2") { 
		url = "./scripts/actions.aspx?act=delpic&time=" + sec;
		}
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	
	function handleStateChange2()
	{
		
		if (xmlHttp.readyState == 1) {
			document.getElementById("upload").style.display = "none";
			document.getElementById("resultDiv").style.display = "inline";
			document.getElementById("resultDiv").innerHTML = "لطفا چند لحظه صبر کنید<img border=0 src='images/ajax_loader.gif'>";
			}
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) 
			{
	
				if (ntest == "delpic2") {
				document.getElementById("upload").style.display = "";
				document.getElementById("picDel").style.display = "none";
				document.getElementById("resultDiv").style.display = "none";
				//document.getElementById("File1").innerText = "";
				}else
				{
				document.getElementById("upload").style.display = "";
				document.getElementById("resultDiv").style.display = "none";
				document.getElementById("File1").innerText = "";				
				}

			}
			if (xmlHttp.status == 500) {
			document.getElementById("upload").style.display = "none";
			document.getElementById("resultDiv").innerHTML = "<font color=red size=2 face=tahoma>اشکالی در حذف فایل بوجود آمده</font></center>";
			}	
		}
	}

	function ShowLog () 
	{
		closeDIV();
		if (!IE) { 
		document.captureEvents(Event.MOUSEMOVE)
		document.onmouseover = getMouseXY;
		}else
		{
		document.onmouseover = getMouseXY;
		}
		tempY -= 300;
		if (tempY < 0) {tempY = 15}
		document.getElementById("ShowLog").style.display = "";
		document.getElementById("frameDIV").style.display = "";
		document.getElementById("ShowLog").style.left = tempX - 700;
		document.getElementById("ShowLog").style.top = tempY;
		var loadResult = "<span style='font-size:10pt; cursor: hand;border: 1px solid #000080; margin-top: 0; background-color: #CCCCFF;width:100%; font-weight:bold;font-family:Arial;'>[Click to Close]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Branch No: " + br + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File Name: " + lfn;
		document.getElementById("frameDIV").innerHTML = xmlHttp.responseText;
		document.getElementById("load").innerHTML = loadResult;
	}
	function closeDIV()
	{
		document.getElementById("ShowLog").style.display = "none";
	}
	function maximizeWin() {
	  if (window.screen) {
	    var aw = screen.availWidth;
		var ah = screen.availHeight;
		window.moveTo(0, 0);
		window.resizeTo(aw, ah);
		}
	}
	

//*********************************************************************

function lottime() {
		createXMLHttpRequest();
		now = new Date();
		var sec = now.getSeconds();
		xmlHttp.onreadystatechange = handleStateChange3;
		var url = "scripts/actions.aspx?act=lot&dt="+ sec;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
}

	function handleStateChange3()
	{
		if (xmlHttp.readyState == 1) {
			document.getElementById("wait").innerHTML = "<center><img border=0 src='./images/ajax_loader.gif'></center>";
			}
		if(xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) 
			{
				ShowlotTime();
			}
			if (xmlHttp.status == 500) {
			}	
		}
	}
function ShowlotTime() {
	document.getElementById("wait").style.display = "none";
	document.getElementById("lotfrm").src = "counter/temp.html";  
}


//********************************************************************
function resize(ifName) { 
var the_height= document.getElementById(ifName).contentWindow.document.body.scrollHeight;
  //change the height of the iframe
  if (the_height <286) {
     the_height = 286
     }
  document.getElementById(ifName).height= the_height;
}
//********************************************************************
function loadWinnersBak(P) {
		task = P;
		var url;
		createXMLHttpRequest();
		now = new Date();
		var sec = now.getMilliseconds()+now.getSeconds();
		url ="../scripts/actions.aspx?act=winBack&filepath=" + document.getElementById('Dwin').value + "&t=" + sec;
		xmlHttp.onreadystatechange = StateChangeWin;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
}//end function

function StateChangeWin()	{
		if (xmlHttp.readyState == 1) {		
				document.getElementById("winresult").innerHTML = "<center><img border=0 src='../images/ajax_loader_arrow.gif'></center>";
				}
		if (xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) 
			{
				ShowWinnersBack();
			}
			if (xmlHttp.status == 500) {
			document.getElementById("winresult").innerHTML = "تاریخ قرعه کشی را انتخاب نمایید";
			}	
		}
}
function ShowWinnersBack()
{
	document.getElementById("winresult").innerHTML = xmlHttp.responseText;
}
//********************************************************************

function loadpage(Pname) {
		task = Pname;
		var url;
		createXMLHttpRequest();
		now = new Date();
		var sec = now.getMilliseconds()+now.getSeconds();
		if (task == "ads") {
			url = "advertisment.htm";
		}
		else {
			if (task == "lottimer") {
				url = "counter/temp.html";
			} 
		    else {
		         if (task == "onlinestore") {
		        url = "popup/parsianet.html"; 
		       	}else {
		       	  if (task == "winnerspop") {
		       	  url = "popup/winners.html";
		       	  }
		       	  }
		       }
		}//end else
		xmlHttp.onreadystatechange = StateChange;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
}

	function StateChange()
	{
		if (xmlHttp.readyState == 1) {
			if (task == "ads") {
				document.getElementById("adsdiv").innerHTML = "<center><img border=0 src='./images/ajax_loader.gif'></center>";
				}
				else {
				document.getElementById("divloader").innerHTML = "<center><img border=0 src='./images/ajax_loader.gif'></center>";
				}	
			}
		if (xmlHttp.readyState == 4) {
			if(xmlHttp.status == 200) 
			{
				if(task == "ads") {ShowAds();}
				if(task == "lottimer") {ShowlotTimer();}
				if(task == "onlinestore") {ShowOnlineStore();}
				if(task == "winnerspop") {ShowWinnersPop();}
			}
			if (xmlHttp.status == 500) {
			document.getElementById("divloader").innerHTML = "اطلاعات قابل بارگزاری نمی باشد";
			}	
		}
	}
	
function ShowAds() {
	document.getElementById("adsdiv").innerHTML = xmlHttp.responseText;
	lottime();
}
function ShowlotTimer() {
	var txthtml = "<iframe id='lotfrm' name='lotfrm' border='0' frameborder='0' marginwidth='1' marginheight='1' width='180px' style='HEIGHT: 50px' scrolling='no' src='counter/temp.html'></iframe>";
	document.getElementById("divloader").innerHTML = txthtml;

}
function ShowOnlineStore() {
	document.getElementById("divloader").innerHTML = xmlHttp.responseText;
}
function ShowWinnersPop() {
	document.getElementById("divloader").innerHTML = xmlHttp.responseText;
}