﻿//
function showData() {
    alert("ID_Control=" + ID_Control);
    alert("LanguageID=" + LanguageID);
}

//Bottom Control
function SetCenter() {
    var obj = document.getElementById("BottomMenu")
    var obj2 = document.getElementById("BottomM")
    obj2.setAttribute("style", "margin-right:" + (960 - (86 + obj.clientWidth + 86)) / 2 + "px");
}

function SetSize(type) {
    if (document.location.toString().indexOf('ViewPages.html', 0) > 0)
        return;

    document.getElementById('MainPage').style.height = '';
    document.getElementById('Footer').style.top = '';

    if (type == false) {
        document.getElementById('MainPage').style.height = '';
        document.getElementById('Footer').style.top = '';
        return;
    }
    if (document.getElementById('MainPage') == null)
        return;
    var clientH;
    if (window.innerHeight)
        clientH = window.innerHeight;
    else
    //DOCTYPE?
        clientH = Math.max(document.documentElement.clientHeight, document.body.offsetHeight) - 5;
    var documentH = document.getElementById('MainPage').offsetHeight;
    if (documentH < clientH) {
        if(PageID != 55)
            document.getElementById('MainPage').style.height = clientH + 'px';
        else
            document.getElementById('MainPage').style.height = '100%';
                    
        var top = parseInt(document.getElementById('Footer').style.top);
                
        if(PageID != 55)
            document.getElementById('Footer').style.top = ((isNaN(top) ? 0 : top) + (clientH - documentH)) + 'px';
        else
            document.getElementById('Footer').style.top = '0px';
    }
}

//Top Control
function trimAll(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

function GoToSearchPage() {
    var strSearch = trimAll(document.getElementById("TTSearch").value);
    var scope = document.getElementById("DropScope").options[document.getElementById("DropScope").selectedIndex].value;
    		
    if(strSearch != 'جستجو')
    {
        var url = Url_Search + "?AssetID=" + scope;
        url = url + "&SearchText=" + escape(strSearch);
        window.location.href = url;
    }
    else
        alert('لطفا کلمه مورد نظر خود را وارد کنید.');
    return false;
}

function fnTopControlSearchKeyPress(e) {
	var strSearch = trimAll(document.getElementById("TTSearch").value);
	
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (KeyID == 13) {
		if (strSearch == '') {
			alert('لطفا کلمه مورد نظر خود را وارد کنید.');
			return false;
		}
		else{
        	GoToSearchPage();
	        return false;
		}
    }
}

function ShowMenu(IDName) {
    obj = document.getElementById(IDName)
    obj.className = IDName
}

function HideMenu(IDName) {
    obj = document.getElementById(IDName)
    obj.className = "Hide"
}
        
function fnSendError(languageId) {
    var url = window.location.href;
    url = url.replace(/[/]/g,"|");
    url = url.replace("?","*");
            
    var langStr = "";
    if(languageId == 1 && url.match(/FA/) == null)
        langStr = "FA/";
            
    window.open(langStr + "BugForm.html?" + "PageAddress=" + url, null, "height=300,width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no")
}

function fnSendFriend(languageId) {
    var url = window.location.href;
    url = url.replace(/[/]/g,"|");
    url = url.replace("?","*");
            
    var langStr = "";
    if(languageId == 1 && url.match(/FA/) == null)
        langStr = "FA/";
                
    window.open(langStr + "SendToFriend.html?" + "PageAddress=" + url, null, "height=300,width=1000,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no")
}

function fnAddFavorite() {
    var url = window.location.href
    var title = "Hawzah Site"
    if (document.all)
        window.external.addfavorite(url, title)
    else if (window.sidebar) {
        window.sidebar.addPanel(title, url, "")
    }
}

function fnHighLight(obj, param) {
    if (param == 1)
        obj.className = "MenuItem2"
    else
        obj.className = "MenuItem1"
}
function fnPrint() {
    var obj = document.getElementById(CtrlID + "_LblContent")//document.getElementById("MainPage")
    var defaultPage = document.getElementById("CtrlHomeTazeha1_LblTazehaTitle")
    var searchPage = document.getElementById("LblResults")
    var objTitle = document.getElementById("PageTitle")
    var strContent = ""
    if (obj != null && defaultPage == null && searchPage == null) {
        strContent += "<html><head>"
                
        strContent += "<link type='text/css' rel='stylesheet' href='http://www.hawzah.net/CMS-Files/FA/Default/Common11.css' >"
        strContent += "<link type='text/css' rel='stylesheet' href='http://www.hawzah.net/CMS-Files/FA/Default/CMS_Common.CSS' >"
        strContent += "<link type='text/css' rel='stylesheet' href='http://www.hawzah.net/CMS-Files/FA/Default/CMS-Menu.CSS' >"
                
        strContent += "<script>document.title='" + document.title + "'; function printIt(){window.print()}<"
        strContent += "/script></head><body rightmargin=10>"
        strContent += "<div align=left style='font-family:times new roman;'><address>URL : " + window.document.URL + "</address></div><hr/>"
        strContent += "<div align=left><input type='button' value='&#1670;&#1575;&#1662;' onclick='javascript:printIt()'></div>"
        strContent += "<blockquote style='margin-right:10px;direction:rtl;font-family:tahoma;'><p>" + obj.innerHTML + "</p></blockquote>"
        strContent += "</body></html>"
        winPreview = window.open("about:blank", "winPrint", "width=1000,height=500, menu=0, toolbar=0, status=0,scrollBars=1")
        winPreview.document.write(strContent)

        winPreview.document.close();
        winPreview.focus();
        winPreview.print();
    }
    else {
        alert("Page does not contain print page!")
        window.print()
    }
}

//*************************************** Ajax *************************
var Ajax =
{
    http2: null,
    data: null,
    loading: null,
    fn_CallBack: "",
    f_FailCallBack: ""
}

Ajax.CreateXMLHttpRequest = function() {
    if (Ajax.http2 == null) {
        if (navigator.appName == "Microsoft Internet Explorer") {
            try {
                Ajax.http2 = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                try {
                    Ajax.http2 = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
        { }
            }
        }
        else {
            Ajax.http2 = new XMLHttpRequest();
            if (Ajax.http2.overrideMimeType) {
                Ajax.http2.overrideMimeType('text/html');
            }
        }
    }
}
Ajax.fnCallBackAjax = function() {
    if (Ajax.http2.readyState == 4) {
        Ajax.ShowLoading("hide");
        if (Ajax.http2.status == 200) {
            //Ajax.ShowLoading("hide");
            if (Ajax.http2.responseText != null) {
                eval(Ajax.fn_CallBack + '(Ajax.http2.responseText)');
            }
            else {

                eval(Ajax.f_FailCallBack + '()');
            }
        }
    }
}
Ajax.fnSendAjax = function(HttpHandlerURL, Data, f_CallBack, f_FailCallBack) {
    var data = Data + '&' + Ajax.data;
    Ajax.fn_CallBack = f_CallBack;
    Ajax.f_FailCallBack = f_FailCallBack;
    Ajax.CreateXMLHttpRequest();
    Ajax.ShowLoading("show");
    var t = Ajax.http2.readyState; //alert('s' + Ajax.http2);
    Ajax.http2.open("POST", HttpHandlerURL, true);
    Ajax.http2.onreadystatechange = Ajax.fnCallBackAjax;
    Ajax.http2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    Ajax.http2.setRequestHeader("Content-length", data.length);
    Ajax.http2.send(data);
    return false;
}
Ajax.ShowLoading = function(action) {
    if (this.loading == null) {
        this.loading = document.createElement('div');
        this.loading.style.backgroundColor = 'red';
        this.loading.style.padding = '3px';
        this.loading.style.fontSize = '11px';
        this.loading.style.position = 'absolute';
        this.loading.style.top = '0px';
        this.loading.style.right = '0px';
        this.loading.innerHTML = 'در حال ارتباط با سرور ...';
        document.body.appendChild(this.loading);
    }
    if (action == "show")
        this.loading.style.display = "block";
    else if (action == "hide")
        this.loading.style.display = "none";
    return false;
}
//*************************************** End Ajax *************************


//*************************************** Captcha *************************
function GetCaptchaCode(Id) {
    var tb = document.getElementById(Id).getElementsByTagName('input')[0];
    return tb.value;
}
function RefreshCaptchaCode(Id) {
    var img = document.getElementById(Id).getElementsByTagName('img')[0];
    img.src += '1';
}
//*************************************** End Captcha *************************


//************************** Header Search ***************************

/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only things you may need to change in this file are the following
variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

The numbers you set for checkboxHeight and radioHeight should be one quarter
of the total height of the image want to use for checkboxes and radio
buttons. Both images should contain the four stages of both inputs stacked
on top of each other in this order: unchecked, unchecked-clicked,
checked, checked-clicked.

You may need to adjust your images a bit if there is a slight vertical
movement during the different stages of the button activation.

The value of selectWidth should be the width of your select list image.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "100";


/* No need to change anything after this */


document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;

//************************** End Header Search ***************************
