﻿function SetSize(Type) {

   if (document.getElementById('Page2') == null)
        return;
        
        if(Type==false)
        {
         document.getElementById('Page2').style.height ='';
         document.getElementById('DivFooter').style.top='';
         return;  
        }   
    var clientH;
    if (window.innerHeight)
        clientH = window.innerHeight;
    else
        clientH = Math.max(document.documentElement.clientHeight, document.body.offsetHeight)-5;
    var documentH = document.getElementById('Page2').offsetHeight;
    if (documentH < clientH) {
          
        document.getElementById('Page2').style.height = clientH + 'px';
        // document.getElementById('Page1').style.height = clientH + 'px';
        var top = parseInt(document.getElementById('DivFooter').style.top);
        document.getElementById('DivFooter').style.top = ((isNaN(top) ? 0 : top) + (clientH - documentH))+'px';
     return;   
    }
}


//*********************************************************dialog SendProblem ******************************************************
var popupDialogProblem = {
    name: 'popupDialogProblem',
    objpopupDialogProblem: null,
    httpSendProblem:null
}
popupDialogProblem.fnShowDialog = function(owner, width, height, fnUICreator, time, data, offsetLeft, offsetTop) {
   
    var pos = this.findPos(owner);
    if (this.objpopupDialogProblem == null) {
        this.objpopupDialogProblem = document.createElement('div');
        this.objpopupDialogProblem.setAttribute('id', this.name);
      //  this.objpopupDialogProblem.style.fontSize = '13px';
        this.objpopupDialogProblem.style.position = 'absolute';
        document.body.appendChild(this.objpopupDialogProblem);
    }
    this.objpopupDialogProblem.style.overflow = 'hidden';
  //  this.objpopupDialogProblem.style.border = 'solid 1px Blue';
  //  this.objpopupDialogProblem.style.width = width + 'px';

 //   this.objpopupDialogProblem.style.height = height + 'px';

    if (window.innerHeight)
        this.objpopupDialogProblem.style.left = pos[0]-width/2+ "px";
    else
        this.objpopupDialogProblem.style.left = pos[0]-width + offsetLeft + "px";
    this.objpopupDialogProblem.style.top = pos[1] + offsetTop + "px";

    //this.objpopupDialogProblem.style.display = 'none';
    popupDialogProblem.changeOpac(0);
    this.objpopupDialogProblem.innerHTML = eval(fnUICreator + '()');
    this.opacity(0, 100, time);

    return false;
}
popupDialogProblem.opacity = function(opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout("popupDialogProblem.changeOpac(" + i + ")", (timer * speed));
            timer++;
        }
    } else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++) {
            setTimeout("popupDialogProblem.changeOpac(" + i + ")", (timer * speed));
            timer++;
        }
    }
}

popupDialogProblem.changeOpac = function(opacity) {
    this.objpopupDialogProblem.style.display = 'block';
    this.objpopupDialogProblem.style.opacity = (opacity / 100);
    this.objpopupDialogProblem.style.MozOpacity = (opacity / 100);
    this.objpopupDialogProblem.style.KhtmlOpacity = (opacity / 100);
    this.objpopupDialogProblem.style.filter = "alpha(opacity=" + opacity + ")";
    if(opacity==0)
        this.objpopupDialogProblem.style.display = 'none';
}

popupDialogProblem.findPos = function(objpopupDialogProblem) {
    var curleft = curtop = 0;
    if (objpopupDialogProblem.offsetParent) {
        if (window.innerHeight)
            curleft = objpopupDialogProblem.offsetLeft;
        else
            curleft = objpopupDialogProblem.offsetParent.offsetWidth - Math.abs(objpopupDialogProblem.offsetLeft) - objpopupDialogProblem.offsetWidth

        curtop = objpopupDialogProblem.offsetTop;
        while (objpopupDialogProblem = objpopupDialogProblem.offsetParent) {
            curleft += objpopupDialogProblem.offsetLeft
            curtop += objpopupDialogProblem.offsetTop
        }
    }
    return [curleft, curtop];
}

popupDialogProblem.Exit = function() {
    this.opacity(100, 0, 1000);
}
//********************************
popupDialogProblem.SendAjaxProblem = function() {

   document.getElementById("TextBug").innerHTML="";
              
   
   var TxtName=document.getElementById("bugFormUserName").value;
     var TxtEmail=document.getElementById("bugFormEmail").value;
       var TxtSubject=document.getElementById("bugFormTitle").value;
         var TxtNote=document.getElementById("bugFormContent").value;
            var TxtUrl=document.getElementById("CtrlTop1_TextUrl").value;
    
    
    var data ="&TxtNote="+TxtNote+"&TxtSubject="+TxtSubject+"&TxtEmail="+TxtEmail+"&TxtName="+TxtName+"&TxtUrl="+TxtUrl;
    HttpHandlerURL="/DLView/Public/SendProblemAjax.ashx";
    popupDialogProblem.CreateXMLHttpRequest();
    popupDialogProblem.httpSendProblem.open("POST", HttpHandlerURL, true);
    popupDialogProblem.httpSendProblem.onreadystatechange = popupDialogProblem.fnCallBackAjax;
    popupDialogProblem.httpSendProblem.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    popupDialogProblem.httpSendProblem.setRequestHeader("Content-length", data.length);
    popupDialogProblem.httpSendProblem.send(data);
    return false;
}
//**********************************
popupDialogProblem.CreateXMLHttpRequest = function() {
    if (popupDialogProblem.httpSendProblem == null) {
        if (navigator.appName == "Microsoft Internet Explorer") {
            try {
                popupDialogProblem.httpSendProblem = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                try {
                    popupDialogProblem.httpSendProblem = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
        { }
            }
        }
        else {
            popupDialogProblem.httpSendProblem = new XMLHttpRequest();
            if (popupDialogProblem.httpSendProblem.overrideMimeType) {
                popupDialogProblem.httpSendProblem.overrideMimeType('text/html');
            }
        }
    }
}
//**************************************************
popupDialogProblem.fnCallBackAjax = function() {
    if (popupDialogProblem.httpSendProblem.readyState == 4) {
        if (popupDialogProblem.httpSendProblem.status == 200) {
            //popupDialogProblem.ShowLoading("hide");
            //debugger;
            if (popupDialogProblem.httpSendProblem.responseText != null)
             {
                if(popupDialogProblem.httpSendProblem.responseText=="ok")
                {
                
            
                    document.getElementById("TextBug").innerHTML="ارسال با موفقیت انجام شد";
              
                
                }
                else
                {
                 
                  document.getElementById("TextBug").innerHTML="خطا در ارسال لطفا مجدد سعی کنید";
                }
             }
            else
             {
                  document.getElementById("TextBug").innerHTML="خطا در ارسال لطفا مجدد سعی کنید";
             
             }
        }
    }
}
//function fnCriticismFormSend() {
//    var criticismTitle = document.getElementById('CriticismTitle').value;
//    var criticismText = document.getElementById('CriticismText').value;
//    var DisplayName = document.getElementById('DispalyName').checked;
//    if (criticismTitle == "" || criticismText == "") {
//        alert("عنوان و یا محتوای نقد را کامل کنید");
//        return;
//    }
//    Ajax.fnSendAjax('/view/ashx/bugForm.ashx', 'type=4&cTitle=' + criticismTitle + '&cText=' + criticismText + '&DName=' + DisplayName, 'CB_fnCriticismFormSend', 'CBF_fnCriticismFormSend');
//}
//function CB_fnCriticismFormSend(result) {
//    popupDialogProblem.obj.innerHTML = result;
//    setTimeout('popupDialogProblem.fnClose()', 2000);
//}
//function CBF_fnCriticismFormSend() {
//    popupDialogProblem.obj.innerHTML = ".خطا در درج نظر";
//}

function fnCreateProblemForm() {
var str = '<div class="ClssBodyNotedialog" ><div class="ClssTitleNotedialog">فرم ارسال اشکال یا پیشنهاد</div>'
str += '<Br/>'
str += '<div class="bbody">'
str += '<div class="bugrow">'
str += '<div class="rcol">نام و نام خانوادگی</div>'
str += '<input type="text" class="tb" id="bugFormUserName" value="" style="width: 190px;" />'
str += '</div>'
str += '<Br/>'
str += '<div class="bugrow">'
str += '<div class="rcol">پست الکترونیکی</div>'
str += '<input type="text"  id="bugFormEmail" value="" style="direction: ltr; width: 190px;" />'
str += '</div>'
str += '<Br/>'
str += '<div>'
str += '<div class="rcol">عنوان اشکال</div>'
str += '<input type="text"  id="bugFormTitle" style="width: 190px;" />'
str += '</div>'
str += '<Br/>'
str += '<div class="bugrow">'
str += '<div class="rcol">محتوای اشکال</div>'
str += '<textarea style="position: relative;width: 190px; height: 100px" id="bugFormContent" rows="8" cols="6"></textarea>'
str += '</div>'
str += '<Br/>'
str += '<div style="text-align: center; padding-top: 5px; clear: both;">'
str += '<input type="button"  onclick="popupDialogProblem.SendAjaxProblem()"  value="ارسال" > '
str += '<input type="button"  onclick="popupDialogProblem.Exit()" value="خروج" />'
str += '<div id="TextBug" ></div>'

str += '</div>'
str += '</div>'
str += '</div>'
return str
}


//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>

function LoginDoIt(e) {
 

    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (KeyID == 13)
	{
	
	   LoginAjax();
	}
}
function SearchTopDoIt(e) {
 

    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (KeyID == 13)
	{
	
	   SearchTop();
	}
}


function   SearchTop()
{
// var CheckFehrest='false';
//var CheckTitle='false';
//var CheckText='false';
//var SearchScope;
// var Index=document.getElementById("CtrlTop1_TextKindSearch").selectedIndex;
//        switch(Index)
//        {
//        case 0:
//        CheckText='true';
//        SearchScope='001';
//        break;
//        case 1:
//        CheckTitle='true';
//         SearchScope='010';
//        break;
//        case 2:
//        CheckFehrest='true';
//         SearchScope='100';
//        break;
//        }
      
var LanguageID=document.getElementById("CtrlTop1_TextLanguageId").value;
var SearchText=document.getElementById("CtrlTop1_TextSearch").value;
 
	if( SearchText == ""  )
	{
	
		alert("لطفا عبارت جستجو را وارد کنید")	
		return false;
	}
	if(SearchText.length == 1)
	{
		//alert("طول کلمه باید بیشتر از یک باشد")
		return false;
	}
window.location="/DLView/Book/Search.aspx?LanguageID"+LanguageID+"&searchtext="+SearchText+ "&searchScope=" +'111'+"&TopSearch=1";
}


var http=null;
function CreateXMLHttpRequest2()
{
    if(http==null)
    {
        if(navigator.appName == "Microsoft Internet Explorer") 
               {
                try 
                { 
                http = new ActiveXObject("Microsoft.XMLHTTP"); 
                  } 
                catch (e) 
                { 
                try 
                { 
                    http = new ActiveXObject("Msxml2.XMLHTTP"); 
                }
                catch (e) 
                {} 
            } 
        } 
        else 
        {
                http = new XMLHttpRequest(); 
                if (http.overrideMimeType) 
                { 
                    http.overrideMimeType('text/html'); 
                } 
        }
    }  
}
function LoginAjax()
{

CreateXMLHttpRequest2();
var  d=new Date();
var url='/DLView/Users/LoginAjax.ashx?Rand='+ d.getMilliseconds().toString();
var username=document.getElementById("CtrlTop1_TextUserName").value;
var password=document.getElementById("CtrlTop1_TextPassword").value;
var data="Username="+username +"&PassWord="+password+"&LanguageID="+ document.getElementById('CtrlTop1_TextLanguageId').value;
ShowLoading2("show");

http.open("POST", url, true);
http.onreadystatechange = Login_CallBack;

http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
http.setRequestHeader("Content-length", data.length);
http.send(data);
return false; 
} 
function Login_CallBack()
{

    if (http.readyState == 4)
    {
        if (http.status == 200)
        {
            ShowLoading2("hide");
            var result = http.responseText;
            if (result!=null)
            {
           
            	document.getElementById("CtrlTop1_DivUserInfo").innerHTML=result;
            	var  Obj=document.getElementById("CtrlTop1_DivUserInfo");
                Obj.style.display="block";
                Obj=document.getElementById("CtrlTop1_DivLogin");
                Obj.style.display="none";
                
                document.getElementById("CtrlTop1_linkhomepage").href="/DLView/Users/Homepage.aspx?LanguageID=1";
                if(document.getElementById("Bks_BookPageView1_DivMeesage")!=null)
                 {
              //document.getElementById("Bks_BookPageView1_DivDontAccess").style.display="none";
                document.getElementById("Bks_BookPageView1_DivMeesage").style.display="none";
                document.getElementById("ImgClose").style.display="block";
            
                window.location=window.location;
                 }
               
                 if(document.getElementById("ISHomePage")!=null)
                 {
                 
                            if(document.getElementById("LoginIsFalse")==null)
                                 window.location= "/DLView/Users/Homepage.aspx?LanguageID=1"
                 }
                 
                
              }   
            	else
            	{
            	document.getElementById("CtrlTop1_DivUserInfo").innerHTML="عدم موفقیت در ورود";
              	}
            	
           
        }
    }
}
function ShowLoading2(action)
{
 var divObj = document.getElementById("CtrlTop1_ImageAjaxLoading");
    if (action == "show")
        divObj.style.display = "block";
    else if (action == "hide")
        divObj.style.display = "none"; 
        return false; 
}

function ClickTabTop(selectedTab)
{       
    
          
            var  strLang=document.getElementById('CtrlTop1_TextLanguageId').value;
             if (selectedTab==6)
                   window.location= "/DLView/Book/PublisherList.aspx?LanguageID=" + strLang;
             if (selectedTab==5)
                   window.location= "/DLView/Book/CreatorList.aspx?LanguageID=" + strLang;
            //if (selectedTab ==4)
            //     this.linkcreator.HRef ="/DlView/Quran/Quran.aspx?LanguageID=" + strLang;
             if (selectedTab==3)
                     window.location = "/DlView/Book/Search.aspx?LanguageID=" + strLang+"&show=1";
            if (selectedTab ==2)
                     window.location = "/DlView/Book/BookAlphabet.aspx?LanguageID=" + strLang;
            if (selectedTab==1)
            {
                
                    if(document.getElementById("CtrlTop1_HomePage").value=="1")
                       window.location="/DLView/Users/Homepage.aspx?LanguageID="+ strLang;
                    else
                       window.location= "/DLView/Default.aspx?LanguageID=" + strLang;
            }
                     
            return false;
}
  
function Search()
{

}
function Register()
{
  
 var strLang=document.getElementById('CtrlTop1_TextLanguageId').value;
 document.location="/DLView/Users/UserRegister.aspx?LanguageID=" + strLang;
 return false;
}
function GetPass()
{
  
  var strLang=document.getElementById('CtrlTop1_TextLanguageId').value;
  document.location="/DLView/Users/GetPass.aspx?LanguageID=" + strLang;
return false;
  
  
}
function ChangePass()
{
  
    var strLang=document.getElementById('CtrlTop1_TextLanguageId').value;
    document.location="/DLView/Users/ChangePassword.aspx?LanguageID=" + strLang;
    return false;
  
  
}
function MyAccount()
{
  
    var strLang=document.getElementById('CtrlTop1_TextLanguageId').value;
    document.location="/DLView/Users/MyAccount.aspx?LanguageID=" + strLang;
    return false;
  
  
}

function ExitSystem()
{
document.getElementById("CtrlTop1_HomePage").value="0";
var  strLang=document.getElementById('CtrlTop1_TextLanguageId').value;
document.location="/DLView/Default.aspx?LanguageID=" + strLang+"&ExitSystem=1";
return false;
}


function TryLogin()
{
              
            	var  Obj=document.getElementById("CtrlTop1_DivUserInfo");
                Obj.style.display="none";
                Obj=document.getElementById("CtrlTop1_DivLogin");
                Obj.style.display="block";
return false;
}

function ExpandToc(Img,Ul)
{

                if(document.getElementById(Ul).style.display=="block")
                {
                  document.getElementById(Ul).style.display="none";
                  Img.src="/DLView/Images/Ball/plus.gif";
                }
                else if(document.getElementById(Ul).style.display=="none")
                {

                        document.getElementById(Ul).style.display="block";
                        Img.src="/DLView/Images/Ball/minus.gif"; 

                }
                else
                {
                
                     document.getElementById(Ul).style.display="none";
                  Img.src="/DLView/Images/Ball/plus.gif";
                
                
                }
                return false;
}