﻿function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function ValidateDate(txtDate) {
    var EnteredDate = txtDate.value;
    var IsValid = true;
    if (EnteredDate != '') //Not empty
    {
        var dates_arr = EnteredDate.split("/");
        if (dates_arr.length != 3) {
            IsValid = false;
        }
        else {
            var year = parseInt(dates_arr[0], 10);
            var month = parseInt(dates_arr[1], 10);
            var day = parseInt(dates_arr[2], 10);
            if (isNaN(year) || isNaN(month) || isNaN(day) || year < 1287 || year > 1450 || month > 12 || month < 1 || day > 31 || day < 1 || (month > 6 && day > 30))
                IsValid = false;
            else {
                //سیستم کبیسه خورشیدی : باقیمانده تقسیم سال به 33 یکی از این عدد ها باشد : 1 و 5 و 9 و 13 و 17 و 22 و 26 و 30
                var kabise = year % 33;
                switch (kabise) {
                    case 1:
                    case 5:
                    case 9:
                    case 13:
                    case 17:
                    case 22:
                    case 26:
                    case 30:
                        break;
                    default: //kabise nist
                        if (month == 12 && day > 29) IsValid = false;
                        break;
                }
            }
        }

    }
    if (!IsValid) {
        alert('تاریخ وارد شده صحیح نیست. لطفاً دوباره وارد کنید');
        txtDate.value = '';
    }
    return IsValid;
}
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function FadeIn(ID)
{
    document.getElementById(ID).className = 'ToolbarContainerVis';
    opacity(ID, 0, 100, 500)
}

function FadeOut(ID)
{
    document.getElementById(ID).className = 'ToolbarContainer';
    opacity(ID, 100, 0, 500)
}

function CloseWin(Obj)
{
    FadeOut(Obj.parentNode.id);
    //Obj.parentNode.className = 'HideDiv1';
}

function OpenAlbum(AlbumCode)
{
    Domain = '';
    Domain = 'http://www.parset.com/Music/';
    window.open(Domain + 'PlayMusic.aspx?Code=' + AlbumCode , 'Player', 'width=750,height=550');
}

function LoadBanner() {
    try {
        if (checkVersion()) {
            obhMainContent = document.getElementById("MainContent").childNodes[1];
            BannerTag = "<div class='Marginer2'><a href='http://www.Parset.com/?Ref=Parset' target='_blank'><div class='BisstonBanner1'></div></a></div><div class='Clear'></div><br>"
            obhMainContent.innerHTML = BannerTag + obhMainContent.innerHTML;
        }
    }
    catch (e) {
    }
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
function checkVersion() {
    var msg = "You're not using Internet Explorer.";
    var ver = getInternetExplorerVersion();

    if (ver > -1) {
        return true;
    }
    else
        return false;
    alert(msg);
}

function IsOnlyNumber() {

    var returnValue = false;
    var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;
    if (((keyCode >= 48) && (keyCode <= 57)) ||
(keyCode == 8) ||
(keyCode == 9) ||
(keyCode == 46) ||
(keyCode == 45) ||
(keyCode == 13))
        returnValue = true;

    if (window.event.returnValue)
        window.event.returnValue = returnValue;
    return returnValue;
}
function IsOnlyNumberAndSlash() {
    var returnValue = false;
    var keyCode = (window.event.which) ? window.event.which : window.event.keyCode;
    if (((keyCode >= 47) && (keyCode <= 57)) ||
(keyCode == 8) ||
(keyCode == 9) ||
(keyCode == 13))
        returnValue = true;

    if (window.event.returnValue)
        window.event.returnValue = returnValue;

    return returnValue;
}

var img1 = new Image()
img1.src = "images/newNewsOver.jpg"

var img2 = new Image()
img2.src = "images/newAgentsOver.jpg"

var img3 = new Image()
img3.src = "images/newHooghoghdanOver.jpg"

function ChangeImg(ImgObj, ImgNum) {
    switch (ImgNum) {
        case 1:
            ImgObj.src = img1.src
            break;
        case 2:
            ImgObj.src = img2.src
            break;
        case 3:
            ImgObj.src = img3.src
            break;
    }

}

function RestoreImage(imgObj) {
    imgObj.src = imgObj.origsrc;
}

function ChangeClass(Obj, NewColor) {
    Obj.className = NewColor
}

function ChangeColor(Obj, NewColor) {
    Obj.style.backgroundColor = NewColor
}


function GoToPage(Url) {
    window.location.href = Url
}

function CreateBookmarkLink() {

    if (document.all) window.external.AddFavorite(location.href, document.title);
 }

 GetPersianNumber = function(str) {
     str = str + ''
     var Result = "";
     for (num = 0; num < str.length; num++) {
         Result = Result + String.fromCharCode(str.charCodeAt(num) + 1728);
     }
     return Result;
 }

 function DoMask(MaskFormat, str, textbox, loc, delim) {
     //	try{

     DoNothing = 0

     CurrentPos = textbox.value.length;
     var locs = loc.split(',');

     KeyCode = event.keyCode
     if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey) {
         if ((KeyCode > 47 && KeyCode < 58) || (KeyCode > 95 && KeyCode < 106)) {
             MaxL = MaskFormat.length + locs.length
             if (textbox.value.length >= MaxL) {
                 event.returnValue = false
                 return false;
             }
             if (KeyCode > 95) KeyCode -= (95 - 47);
         } else if (KeyCode != 8 && KeyCode != 46) {
             event.returnValue = false
             return false;
         }
     }

     CurrentChar = String.fromCharCode(KeyCode)

     for (var i = 0; i <= locs.length; i++) {
         for (var k = 0; k <= str.length; k++) {
             if (k == locs[i]) {
                 if (str.substring(k, k + 1) != delim) {
                     str = str.substring(0, k) + delim + str.substring(k, str.length)
                     textbox.value = str
                 }
             }
         }
     }

     if (CurrentPos < MaskFormat.length + locs.length) {
         if (MaskFormat.charAt(CurrentPos) == 'N') {
             if (!isNaN(CurrentChar)) {
                 DoNothing = 0
             }
             else {
                 DoNothing = 1
             }
         }
         else if (MaskFormat.charAt(CurrentPos) == '/') {
             if (CurrentChar == '/') {
                 DoNothing = 0
             }
             else {
                 DoNothing = 1
             }
         }
         else if (MaskFormat.charAt(CurrentPos) == 'L') {
             if (!isNaN(CurrentChar)) {
                 DoNothing = 1
             }
             else {
                 DoNothing = 0
             }
         }

     }
     else
         DoNothing = 1


     if (DoNothing == 1)
         event.keyCode = 0
     return true;
     //	}
     //	catch(e)
     //	{
     //	}
 }

function OpenDate(DivObj)
{

    //InitVal = TDObj.parentNode.parentNode.parentNode.parentNode.rows[0].cells[0].childNodes[0].name;
    InitVal = DivObj.parentNode.parentNode.childNodes[1].childNodes[0].value;
    FFN = DivObj.parentNode.parentNode.childNodes[1].childNodes[0].name;
	InitVal = InitVal.replace("/", "");
	InitVal = InitVal.replace("/", "");
	X =  window.event.clientX 
	Y =  window.event.clientY
	if ( InitVal.length != 8)
		InitVal = '';


    DatePan.style.left = X - 32 + document.body.scrollLeft;
    DatePan.style.top = Y + 2 + document.body.scrollTop + document.documentElement.scrollTop;
//    alert(document.body.offsetHeight)
    DatePan.style.display = "block"
    Init(1)
//    window.resizeTo(X + DatePan.offsetWidth,Y + DatePan.offsetHeight+70)
//    document.body.scrollIntoView(true)
//    
//    alert(document.body.offsetHeight)
}
