﻿<!--
/*Credit JavaScript Kit www.javascriptkit.com*/
var dragapproved=false
var z,x,y
function move()
{
    if (event.button==1&&dragapproved)
    {
        z.style.pixelLeft=temp1+event.clientX-x
        z.style.pixelTop=temp2+event.clientY-y
        return false
    }
}
function drags()
{
    if (!document.all)
        return
    if (event.srcElement.className=="drag")
    {
        dragapproved=true
        z=event.srcElement
        temp1=z.style.pixelLeft
        temp2=z.style.pixelTop
        x=event.clientX
        y=event.clientY
        document.onmousemove=move
    }
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")
//-->


var a =['·','¸','¹','º','»','¼','½','¾','¿','À','Á','Â'];
var WaitCounter=0;
var WaitCycle=0;
function NumberKeyPress()
{
    if (window.event.keyCode<48 || window.event.keyCode>57)
        window.event.keyCode="";
   window.event.returnValue = true;
}
function setFocus(theObject)
{
    if (window.event.keyCode == 13)
    {
        document.all[theObject].focus();  
        window.event.keyCode = 13;
    }
}
function CheckFrame()
{
    if(top.frames.length==0)
    {
	    top.location.href = 'Login.aspx?key=security'
    }
}
function getposOffset(overlay, offsettype)
{
    var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
    var parentEl=overlay.offsetParent;
    while (parentEl!=null)
    {
        totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}
function overlay(curobj, subobjstr, opt_position)
{
    if (document.getElementById)
    {
        var subobj=document.getElementById(subobjstr)
        subobj.style.display=(subobj.style.display!="block")? "block" : "none"
        //var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
        //var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
        subobj.style.left="350"
        subobj.style.top=getposOffset(curobj, "top")+29;
        return false
    }
    else
        return true
}
function overlayclose(subobj)
{
    document.getElementById(subobj).style.display="none"
}
function datemask(key,textbox)
{
	if (key==9 || key==13 || key==39 || key==37 || key==16)
		return true;
	var oRange = document.selection.createRange();
	var SelectedLength=oRange.text.length;
	oRange.moveStart('Textedit',-1);
	var iEnd=oRange.text.length;
	var iStart=iEnd-SelectedLength;
	var EmptyDate='13__/__/__';
	var strDate='';
	var strText=textbox.value;
	if (key==8 || key==46)
	{
		if (iStart==iEnd)
		{
			if (iStart<2 || (iStart==2 && key==8))
			{
				iStart=2;
			}
			else
			{
				if (key==8)
				{
					iStart=(iStart==5||iStart==8?iStart-1:iStart);
					textbox.value=strText.substring(0,iStart-1) + EmptyDate.charAt(iStart-1) + strText.substring(iStart,10);
					iStart=iStart-1;
				}
				else
				{
					if (iStart==10)
						return false;
					iStart=(iStart==4||iStart==7?iStart+1:iStart);
					var strTemp = strText.substring(iStart,10);
					strTemp = replace(strTemp,'/','');
					strTemp = strTemp.substring(1,strTemp.length) + '_';
					strTemp = replace(strText.substring(0,iStart),'/','') + strTemp;
					textbox.value=strTemp.substring(0,4) + '/' + strTemp.substring(4,6)+'/'+strTemp.substring(6,8);
				}
			}
		}
		else
		{
			if (iEnd<=2)
			{
				iStart=2;
			}
			else
			{
				textbox.value=strText.substring(0,iStart) + EmptyDate.substring(iStart,iEnd) + strText.substring(iEnd,10);
				iStart=(iStart<2?2:iStart);
			}
		}
	}
	else if ((key>=48 && key<=57) || (key>=96 && key<=105))
	{
		if (iStart==10)
			return false;
		if (iStart==iEnd)
		{
			if (iStart<2)
			{
				iStart=2;
			}
			else
			{
				
				iStart=(iStart==4||iStart==7?iStart+1:iStart);
				textbox.value=strText.substring(0,iStart) + (key>57?String.fromCharCode(key-48):String.fromCharCode(key)) + strText.substring(iStart+1,10);
				iStart=(++iStart==4||iStart==7?iStart+1:iStart);
			}
		}
		else
		{
			if (iEnd<=2)
			{
				iStart=2;
			}
			else
			{
				strText=strText.substring(0,iStart) + EmptyDate.substring(iStart,iEnd) + strText.substring(iEnd,10);
				iStart=(iStart==4||iStart==7?iStart+1:(iStart<2?2:iStart));
				textbox.value=strText.substring(0,iStart) + (key>57?String.fromCharCode(key-48):String.fromCharCode(key)) + strText.substring(iStart+1,10);
				iStart=(++iStart==4||iStart==7?iStart+1:iStart);
			}
		}
		
	}
	else
		return false;
		
	textboxSelect(textbox,iStart,iStart);
	return false;
}

function dateboxenter(textbox)
{
	if (textbox.value=='')
	{
		textbox.value='13__/__/__';
		textboxSelect(textbox,2,2);
	}
}
function replace(fullString,text,by)
{
	var strLength = fullString.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return fullString;

	var i = fullString.indexOf(text);
	if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
	if (i == -1) return fullString;

	var newstr = fullString.substring(0,i) + by;

	if (i+txtLength < strLength)
		newstr += replace(fullString.substring(i+txtLength,strLength),text,by);

	return newstr;
}
function LeaveDateBox(textbox)
{
	if (textbox.value=='13__/__/__')
	{
		textbox.value='';
		return;
	}
	var strDate=textbox.value;
	if (strDate.length==10)
	{
		var Year=parseInt(strDate.substring(0,4));
		var Month=strDate.substring(5,6)=="0"?parseInt(strDate.substring(6,7)):parseInt(strDate.substring(5,7));
		var Day=strDate.substring(8,9)=="0"?parseInt(strDate.substring(9,10)):parseInt(strDate.substring(8,10));
		if (strDate.indexOf("_")!==-1 || Year<1300 || Year>1450 || Month<1 || Month>12 || Day<1 || Day>31 || (Month>6 && Day>30) || (Month==12 && Year%4!=3 && Day==30))
		{
			alert("تاريخ نامعتبر است");
			textbox.value='13__/__/__';
			textboxSelect(textbox,2,2);
			textbox.focus();
		}
	}
}

function textboxSelect(oTextbox, iStart, iEnd)
{
	var oRange = oTextbox.createTextRange(); 
    oRange.moveStart("character", iStart); 
    oRange.moveEnd("character", -oTextbox.value.length + iEnd);      
    oRange.select();  
}
/* Dragable Media */
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
//this.targetobj.style.width=400;
return false
}
}
}
dragobject.initialize()
function makeWait()
{
    if(WaitCycle>100)
    {
        tdMessage.innerHTML="عمليات بيش از حد طول كشيد";
        tdMessage.className="ErrorField";
        WaitCycle=0;
        document.all.spnWait.innerHTML="";
        setTimeout("document.location=document.location;",10000);
        return false;
    }
	if(WaitCounter>10)WaitCounter=0;
	else WaitCounter++;
	document.all.spnWait.innerHTML=a[WaitCounter];
	setTimeout("makeWait();WaitCycle++;",150);
}
//Tooltip Scripts
var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip
var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
document.write('<div id="tooltip"></div>') //write out tooltip DIV
document.write('<img id="pointer" style="display:none;" src="Images/arrow2.gif">') //write out pointer image
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["tooltip"] : document.getElementById? document.getElementById("tooltip") : ""
function ietruebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function ddrivetip(thetext, thewidth, thecolor, theFlesh)
{
    if (ns6||ie)
    {
        if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
        if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
        tipobj.innerHTML=thetext
        enabletip=true
        return false
    }
}
function positiontip(e)
{
    if (enabletip)
    {
        var nondefaultpos=false
        var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
        var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
        var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
        var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
        var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
        var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge<tipobj.offsetWidth)
        {
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left=curX-tipobj.offsetWidth+"px"
            nondefaultpos=true
        }
        else if (curX<leftedge)
            tipobj.style.left="5px"
        else
        {
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
        }
        //same concept with the vertical position
        if (bottomedge<tipobj.offsetHeight)
        {
            tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
            nondefaultpos=true
        }
        else
        {
            tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
        }
        tipobj.style.visibility="visible"
    }
}
function hideddrivetip()
{
    if (ns6||ie)
    {
        enabletip=false
        tipobj.style.visibility="hidden"
        tipobj.style.backgroundColor=''
        tipobj.style.width=''
    }
}
document.onmousemove=positiontip
//End of Tooltip Scripts
function ShowMyText(strValue)
{
    var vars = strValue.split(",");
    if(vars[1]!="")
        return vars[1];
    else
        return "";
}
function ShowMyValue(strValue)
{
    var vars = strValue.split(",");
    if(vars[0]!="")
        return vars[0];
    else
        return "";
}
function ShowManual(objdv)
{
    if(objdv.style.display=="none")
    {
        objdv.style.display="block";
    }
    else
    {
        objdv.style.display="none";
    }
}
function ShowMessages()
{
    service.GlobalServices.callService(FillMessage,"GetMessage");
    setTimeout("ShowMessages();",60000);
}
function FillMessage(objValue)
{
    if(objValue.error)
    {    
        var xfaultcode = objValue.errorDetail.code;
        var xfaultstring = objValue.errorDetail.string;    
        var xfaultsoap = objValue.errorDetail.raw;
        alert(xfaultstring+xfaultcode+xfaultsoap);
    }
    else
    {
        tdMessenger.innerHTML=objValue.value;
    }
}
function ShowPopup(strMessage)
{
    var oPopup = window.createPopup();
	var tempX = 0
	var tempY = 0
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
    var oPopBody = oPopup.document.body;
    oPopBody.style.backgroundColor = "lightyellow";
    oPopBody.style.border = "solid black 1px";
    oPopBody.innerHTML ="<div style='font-family: Tahoma;font-size: 9pt;color: #38638D;padding-left: 3;padding-right: 3;direction:rtl;font-face:tahoma;font-size:10pt;' class='TDLable'>&nbsp;" + strMessage + "</div>";
    oPopup.show(tempX , tempY , 180, 250, document.body);
}