﻿/* JVira
 * Copyright 2009 Multivira Inc. , Babak Arjomandi
 * Ver 1
 */

function openclose(DivName,ImageName)
{
if (document.getElementById(DivName).style.display=='none')
   {
     document.getElementById(DivName).style.display='block';
     document.getElementById(ImageName).src="images/mclose.png";
     document.getElementById(ImageName).alt="Close";
   }
   else
   {
    document.getElementById(DivName).style.display='none';
    document.getElementById(ImageName).src="images/mopen.png";
    document.getElementById(ImageName).alt="Open";
   }
}



function printWindow()
{
   bV = parseInt(navigator.appVersion);
   if (bV >= 4) window.print();
}



function PrintContentByID(ObjID)
{
        docPrint=window.open("","Print");
        docPrint.document.open();
        docPrint.document.write('<html><head><title>Print</title>');
        docPrint.document.write('<link href="userstyle.css" type="text/css" rel="STYLESHEET">');
        docPrint.document.write('</head><body style="background:#FFFFFF;direction:rtl;margin:5px;" onLoad="self.print()">');
        docPrint.document.write(document.getElementById(ObjID).innerHTML);  
        docPrint.document.write('</body></html>');
        docPrint.document.close();  
        docPrint.focus();
}




function ConfirmChoice(MyMes,MyPar) 
{ 
   answer = confirm(MyMes)
   if (answer !="0") 
   { 
   location = MyPar 
   } 
}

function WebSearchOpt(SpanID)
{
    if (document.getElementById(SpanID).innerHTML=='سایت')
    {
        document.getElementById(SpanID).innerHTML='نقشه';
    }
    else
    {
        document.getElementById(SpanID).innerHTML='سایت';
    }
    document.getElementById('SiteSearch').focus();
}

function goWebSearch()
{
    if (document.getElementById('SiteSearch').value!='')
    {
        if (document.getElementById('SiteSearchOption').innerHTML=='سایت')
        {
            GotoURL('index.aspx?fnd='+document.getElementById('SiteSearch').value);
        }
        else
        {
            GotoURL('index.aspx?mapfnd='+document.getElementById('SiteSearch').value);
        }
    }
}


function GotoURL(url)
{
   window.location.href=url ;
}
	


function MouseRowIn(RowName)
{
RowName.bgColor = "#dddddd" ;
}


function MouseRowOut(RowName)
{
RowName.bgColor = "" ;
}


function ShowDiv(targetId)
{
   document.getElementById(targetId).style.display = 'block';
}



function HideDiv(targetId)
{
   document.getElementById(targetId).style.display = 'none';
}


function domianExtSel(val)
{
   document.getElementById('domainExtVal').innerHTML = val;
   document.getElementById('domainComboBody').style.display = 'none';
   document.getElementById('TextBox29').focus();
}





function EmailContent(email,rname,subject,divid)
{
      var body = "";
      if(document.getElementById(divid))
      {
      body = "Dear " + rname + ", " + document.getElementById(divid).innerHTML;
      }
      window.open("mailto:"+email+"?subject=" + encodeURIComponent(subject) + "&body=" + escape(body),"SendEmail");
}


var EscKeyPress;


function popWinShow(popupDiv)
{
   if (document.getElementById("popWinBG")==null)
      { 
         var popWinBG = document.createElement('div');
         popWinBG.setAttribute("id","popWinBG");
         document.body.appendChild(popWinBG);         
      }
            
   document.getElementById("popWinBG").style.visibility = 'visible';
   
   if (document.getElementById("popWin")==null)
      { 
         var popWin = document.createElement('div');
         popWin.setAttribute("id","popWin");
         document.body.appendChild(popWin);
      }
   
   document.getElementById("popWin").innerHTML = '<span class="IWinClose" onclick="popWinClose();"></span>' +
                                                 document.getElementById(popupDiv).innerHTML;
   document.getElementById("popWin").style.visibility = 'visible';
   EscKeyPress = true;
   document.onkeydown = EscKeyExit;
}

function popWinClose()
{
   if (document.getElementById("popWinBG")!=null)
      { 
         document.getElementById("popWinBG").style.visibility = 'hidden';
      }
         
   if (document.getElementById("popWin")!=null)
      { 
         document.getElementById("popWin").style.visibility = 'hidden';
      }      
}


function EscKeyExit(e) {
	var x;
	if (document.all) {
		var evnt = window.event;
		x = evnt.keyCode;
        }
        else {
            x = e.keyCode;
        }

	if (x == 27 && EscKeyPress == true) {
		popWinClose();
		EscKeyPress = false;
        }
}



// Ads AND Banners ///////////////////////////////////////////////////////////////////////////////////////
var BannerList = new Array();
var imageIDcurrent = 0 ;

function createBanner(BannerDivID,imageList,TimerLength) {
    BannerList = imageList.split(',');

    if (document.getElementById("bannerImg")==null)
       { 
          var bannerImg = document.createElement('img');
          bannerImg.setAttribute("id","bannerImg");
          document.getElementById(BannerDivID).appendChild(bannerImg);
       }   
       
    if (document.getElementById("BannerCtlKeys")==null)
       { 
          var BannerCtlKeys = document.createElement('div');
          BannerCtlKeys.setAttribute("id","BannerCtlKeys");
          document.getElementById(BannerDivID).appendChild(BannerCtlKeys);         
       }       
       
    var BKeys = ""; 
    var i = 0;    
    for (i = 0 ; i < BannerList.length ; i++)
    {
        var ii = i + 1 ;
        BKeys += '<a href="#" id="BannerKey_'+i+'" class="BannerKey" onclick="AdsShow('+i+');">'+ii+'</a>' ;
    }    
    document.getElementById('BannerCtlKeys').innerHTML = BKeys ;

   AdsShow(imageIDcurrent);
   setInterval("changeAds()", TimerLength);
}


function AdsShow(imageID) {
    imageIDcurrent = imageID;
    document.getElementById("bannerImg").src = BannerList[imageIDcurrent];  
    var i = 0;    
    for (i = 0 ; i < BannerList.length ; i++)
    {
        document.getElementById('BannerKey_'+i).className = 'BannerKey';
    }
    document.getElementById('BannerKey_'+imageID).className = 'BannerKeyActive';
}


function changeAds() {
    imageIDcurrent += 1 ;
    if (imageIDcurrent >= BannerList.length)
       { imageIDcurrent = 0 ; }  
    AdsShow(imageIDcurrent);
}


// Validations ///////////////////////////////////////////////////////////////////////////////////////


function checkImageFile(inputFile)
{
	var uFilePath = inputFile.value.toLowerCase();
	if (!(uFilePath.indexOf('.png')>0 || uFilePath.indexOf('.jpg')>0 || uFilePath.indexOf('.jpeg')>0))
	{
		inputFile.value = null;
		alert('You can chose only JPG or PNG image formats');
	}
}

function ImageFileNote()
{
	alert('حداکثر اندازه تصویر ارسالی شما می بایست کمتر از 1 مگابایت باشد');
}


function checkSelectRanking()
{
  var radio = document.forms[0].elements['RadioButtonList1'];

  if (radio[0].checked || radio[1].checked || radio[2].checked)
  {
    return true;
  }
  else
  {
    alert('لطفا جهت ارسال نظر رتبه خود به این مطلب  را مشخص کنید');
    return false;
  }
}


// Gallery ///////////////////////////////////////////////////////////////////////////////////////

function showBigImageGallery(ipath,title,url)
{
    document.getElementById('GalleryBigPic').src = ipath;
    document.getElementById('GalleryBigPic').title = title;
    document.getElementById('GalleryTitle').innerHTML = title;
    document.getElementById('GalleryTitle').href = url;
}

