﻿// JScript File
function SetFocus(Cntrl)
{
	
	var Control = document.getElementById(Cntrl);
	
	if(Cntrl!=null)
	{
		if (window.event.keyCode == 13)	
		{	Control.focus(Cntrl);}
	}
}

function Popup(Path,Height,Width)
	{	
	if (Path!="")
	    {var result
		//window.open(Path,"","Height="+Height+",width="+Width+",left="+((screen.width/2)-(Width/2))+",top="+((screen.height/2)-(Height/2))+",resizable=no,scrollbars=no,toolbar=no,status=no,directories=no,menubar=no,copyhistory=no,location=no");
	   result = window.showModalDialog(Path,"","dialogHeight:"+Height+"px;dialogWidth:"+Width+"px;center:yes;edge:raised;resizable:no;scroll:no;help:no;status:no");
	  //if (result == null)
		//	result = "";
	  return (result);
	  }
	}
function PopupDialog(Path,Height,Width,Winname)
	{	
	    if (Path!="")
	    {
	        var status = loadXMLDoc(Path);
	        if (status==200)
	        {
		        var result
		        result = window.showModalDialog(Path,Winname,"dialogHeight:"+Height+"px;dialogWidth:"+Width+"px;center:yes;edge:raised;resizable:yes;scroll:yes;help:no;status:no");
		        return (result);
		    }
		    else if (status==404)
		    {
		        alert("File Not Exist. It might be deleted from server.");
		    }
		    else
		    {
		        alert("Error in reading the file."); 
		    }
		}
		else
		{
		alert("file path is empty.");
		}
	}
	
	function PopupDialog1(Path,Height,Width,Winname)
	{
	    var result
		result = window.showModalDialog(Path,Winname,"dialogHeight:"+Height+"px;dialogWidth:"+Width+"px;center:yes;edge:raised;resizable:yes;scroll:yes;help:no;status:no");
	    
	    if(result != null) 
	    {
	        window.location.href= result;
	    }
	    
	}
function PopupWin(Path,Height,Width)
	{
		if (Path!="")
	    {window.open(Path,"new_page","Height="+Height+",width="+Width+",left="+((screen.width/2)-(Width/2))+",top="+((screen.height/2)-(Height/2))+",resizable=no,scrollbars=no,toolbar=no,status=no,directories=no,menubar=no,copyhistory=no,location=no");
	   }//window.showModalDialog(Path,"","dialogHeight:"+Height+"px;dialogWidth:"+Width+"px;center:yes;edge:raised;resizable:no;scroll:no;help:no;status:no");
	}
	function PopupWin1(Path,Height,Width,Title)
	{
		if (Path!="")
	    {window.open(Path,Title,"Height="+Height+",width="+Width+",left="+((screen.width/2)-(Width/2))+",top="+((screen.height/2)-(Height/2))+",resizable=yes,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=no,copyhistory=no,location=no");
	   }//window.showModalDialog(Path,"","dialogHeight:"+Height+"px;dialogWidth:"+Width+"px;center:yes;edge:raised;resizable:no;scroll:no;help:no;status:no");
	}
	
	
	/// the Following function will check the email format email@host.domain. 
function IsValidEmail(Email)
{
	var regex = /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,3}$/
    if (!regex.test(Email)) 
        return (false);
    else
		return (true);   

}

function printPage()
{
  if (window.print != null)
  {
    window.print();
  }
  else
  {
    alert('Your browser does not support this function. Please select Print from the File menu');
  }
}


function isDate(dtStr){
	

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	
	
	strYr=strYear
	
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

function getComparableDateFormat(dtStr)
{
		// Format the date as yyyymmdd for comparing 
		// purposes. 
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		var compareDateFormat= strYear + strMonth + strDay
		return compareDateFormat;
}

function compareDate(date1, date2 ) 
{
	// compares two dates , and return :
	// 1 if the first date is greater than the second
	// 0 if the two dates are eqaul
	var result =-2;
	if ( getComparableDateFormat(date1) >  getComparableDateFormat(date2) ) 
		result = 1
	else if ( getComparableDateFormat(date1) <  getComparableDateFormat(date2)  )
		result = -1
	else 
		result = 0;
	
	return result;
	
} 

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////// Check file existings ////////////////////
////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

var xmlhttp

function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("POST",url,false)
  xmlhttp.send(null)
  return xmlhttp.status;
  //xmlhttp.responseText; To get server side content (ASP )
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
    /*if(xmlhttp.status==200)
        T1.innerText=xmlhttp.status;
    else
        T1.innerText=xmlhttp.status;
    */
  }
}


function GetThumbnilPic(imgLoc)
{

var iframe =  this.document.getElementById("LrgImageIf");

iframe.src = imgLoc;

}
function starttest()
{alert("Your browser does not support XMLHTTP.");}


function ShowPublication(path)
{
	var winPop = window.open("","","menu=0,width=500,height=400;center:yes;edge:raised;resizable:yes;scroll:yes;help:no;status:no");
	winPop.document.write("<html><head><title>SLRB Publication : إصدارات الجهاز</title></head><body style=\"padding:0; margin:0;\"><div align=\"center\"><iframe id='IfrmPage' frameborder=0 src='"+path+"' runat=server width=100% height=100% ></iframe></div></body></html>");
	winPop.document.close();
}



function ShowPopupImage(imgLoc,imgTitle,imgCaption)
{
if(imgLoc!="")
{
	this.imgLoc = imgLoc;

	var getImage = new Image();

	getImage.onload = function()
	{
		try
		{
			winPop.document.getElementById("loadIt").src = getImage.src;
			winPop.window.resizeBy(getImage.width-100, getImage.height-30);
			getImage.src = "";
		}
		catch (err)
		{
		}
	}



	var winPop = window.open("","","menu=0,status=0,scrollbars=0,width=1,height=1;");

	winPop.document.write("<html><head><title>Photo Gallery :: مكتبة الصور</title></head><body onblur=\"window.close();\" onclick=\"window.close();\" style=\"padding:0; margin:0;\"><div align=\"center\"><img src=\"/App_Themes/SlrbWebsite_en/images/loop.gif\" id=\"loadIt\"><br><span style=\"color:maroon; font-size:12px; font-family:arial; padding-top:5px;\">" + imgTitle + "</span><br><span style=\"color:black; font-size:12px; font-family:arial;\">" + imgCaption + "</span><br><br> <span style=\"color:#666666; font-size:10px; font-family:arial;\">click anywhere to close this window</span></div></body></html>");

	winPop.document.close();

	getImage.src = imgLoc;
     }
     else
        alert("No Input File");
     
}