
//---report style varialbes

var RepeatTheadStyle="<style type='text/css'>thead{ table-header-group;}</style>";
//--------------------Confirmation message To Saving data

function confirmSave(UIlang)
{
	var strMsg ="";
	if(UIlang=="ar-QA")
		strMsg="هل ترغب في حفظ البيانات";
	else
		strMsg="Do you want to save this data";

	if(!confirm(strMsg))
		return false;
}
function ShowConfimMsg(msgtxt)
{
   // var msgtxt="Do you wat to save";
    var msgReturnValue=0;
    msgReturnValue=window.showModalDialog('../includes/dialogbox100.aspx',msgtxt,'status:no;dialogWidth:370px;dialogHeight:220px;dialogHide:true;help:no;scroll:no');
   //alert(msgReturnValue);
   if (msgReturnValue==1) 
        return true;
   else
         return false;
}
function ShowWarnMsg(msgtxt)
{
   // var msgtxt="Do you wat to save";
    var msgReturnValue=0;
    msgReturnValue=window.showModalDialog('../includes/dialogbox200.aspx',msgtxt,'status:no;dialogWidth:370px;dialogHeight:220px;dialogHide:true;help:no;scroll:no');
   //alert(msgReturnValue);
   if (msgReturnValue==1) 
        return true;
   else
         return false;
}
//---------------------Confirmation message To Delete data
function confirmDelete(UIlang)
{
	var strMsg ="";
	if(UIlang=="ar-QA")
		strMsg="Do you want to Delete this data_ar";
	else
		strMsg="Do you want to Delete this data";

	if(!confirm(strMsg))
		return false;
}
//-----------TRim WhiteSpace Left and Right of the give string-----
function TrimLeftRightWhiteSpace(StrTrim)
{
    StrTrim=StrTrim.replace(/^[ \t\@\$\%\*\!\?]+|[ \t]+$/, "");
    StrTrim=StrTrim.replace(/(\s+$)/, "");
    return StrTrim;
}

function ValidateName(strName)
{
	var message="";
	var reg1 = new RegExp("^[A-Za-z]");
	var reg2 = new RegExp("^[A-Za-z0-9\t]+|[-]$");	
	if(strName.search(reg1))
	{
		//alert("Name must start with letter");		
		return false;
	}
	if(strName.search(reg2))
	{
		//alert("User Name can contain only Alphabets letters, numbers");			
		return false;
	}
	return true	
}
function LoginIDValidation(StrLoginId,ErrorDisplayField,DisplayError)
{	
	var message="";
	var reg1 = new RegExp("^[A-Za-z]");
	var reg2 = new RegExp("^[A-Za-z0-9_-]+$");	
	
	if(StrLoginId.search(reg1))
	{
		message="LoginID must start with letter";
		DisplayMessageOnPage(message,ErrorDisplayField,DisplayError);
		return false;
	}
	if(StrLoginId.length<3)
	{
		message="use minimum 3 letters";
		DisplayMessageOnPage(message,ErrorDisplayField,DisplayError);
		return false;
	}			
	
	if(StrLoginId.search(reg2))
	{
		message="Invalid LoginId<br> It can contain only letters, numbers, hyphens (-), and underscores (_)";	
		DisplayMessageOnPage(message,ErrorDisplayField,DisplayError);
		return false;
	}	
	return true;
}
function IsNumber(strgNum)
{	
	var reg			= "(^[0-9]+$)"; 
	if(strgNum.search(reg))
	{		
		return false;
	}	
	return true;
}
function checkPhoneNumberPattern (strng) 
{
	reg1			= "(^[0-9]+$)"; 				// ##...
	reg2			= "(^[\+][0-9]+$)"; 			// +##... 
	reg3			= "(^[\+][0-9]+[\-][0-9]+$)"; 	// +##...
	reg4			= "(^[0-9]+[\(][0-9]+[\)]$)"; 
	reg5			= "(^[\+][0-9]+[\(][0-9]+[\)]$)"; 	//+##..-##..
	reg6			= "(^[\(][0-9]+[\)][0-9]+$)";
	var reg = reg1+"|"+reg2+"|"+reg3+"|"+reg4+"|"+reg5;
	if (strng == "") 
	{
		//alert("You didn't enter a phone number.\n");
		return false;
	}
	if(strng.search(reg1))
	{
		//alert("Invalid phone number format in phone Number");
		return false;
	}	
	return true;
}
function checkDatePattern(strgDDMMYYYY)
{	
	var regDD			= "((0[1-9]|1[0-9]|2[0-9]|3[01])|([1-9]|1[0-9]|2[0-9]|3[01]))";
	var regSep			= "([/]|[\-])";		
	var regMM			= "((0[1-9]|1[012])|([1-9]|1[012]))";	
	//var regYYYY			= "(^1[9][0-9][0-9]$)|(^2[0][0-9][0-9]$)";
	var regYYYY			= "([1-9][0-9][0-9][0-9])";  
	var reg				= regDD+regSep+regMM+regSep+regYYYY;	
//	if(strgDDMMYYYY.search(reg))
//	{
//		return false;
//	}	
	return true;		
}

function DisplayMessageOnPage(message,locationId,flag)
{
	if(flag==1)
	{
		document.getElementById("divLoginIdAvailable").innerHTML="<font color=red>"+ message+ "</font>";		
	}
}
	
//--------------------Email Format Validation-------------------
function validEmail(formField,fieldLabel,required)
{
	var result = true;	
	if ( ((formField.value.length > 0) && !isEmailAddr(formField.value)) )
	{
		alert("الرجاء ادخال بريد الكتروني على هذا النسق: yourname@yourdomain.com"); //alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		formField.select();
		result = false;
	}   
  return result;

}
function isEmailAddr(email)
{ 
 var result = false;
  var theStr = email.value;
  var index = theStr.indexOf("@");
  
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
  //var reg ="([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})";
  //if(strgDDMMYYYY.search(reg))
	//{		
	//	return false;
	//}	
	//return true;	
  //^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$  
}

//--------------------Date validation start -------------------->>
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var Errfeild="Years";
function daysInFebruary (year)
	{	// February has 29 days in any year evenly divisible by four,// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	
	function DaysArray(n) 
	{	
			for (var i = 1; i <= n; i++) 
			{
				this[i] = 31
				if (i==4 || i==6 || i==9 || i==11) 
				{
				this[i] = 30
				}
				if (i==2) {this[i] = 29}
			} 
			return this
	}
function validDate(formField,fieldLabel,required,UIlang)
{
	var result		 = true;
	var formField	 = formField;
	var fieldLabel	 = fieldLabel;	
	
	
	if ( (formField.length > 0) )//*new line add on 11/11/04	
	result=ValidateForm(formField);
		//******************************************************* 
	// Declaring valid date character, minimum year and maximum year	
	function isInteger(s)
	{	
			var i;
			for (i = 0; i < s.length; i++)
			{       
				var c = s.charAt(i); // Check that current character is number.
				if (((c < "0") || (c > "9"))) return false;
			}    
			return true;// All characters are numbers.
	}

	function stripCharsInBag(s, bag)
	{	
			var i;
			var returnString = "";// Search through string's characters one by one.// If character is not in bag, append to returnString.
			for (i = 0; i < s.length; i++)
			{   
				var c = s.charAt(i);
				if (bag.indexOf(c) == -1) returnString += c;
			}
			return returnString;
	}

	/*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)
			{
				if(UIlang=="ar-QA")
					alert("التاريخ يجب أن يكون على الشكل: dd/mm/yyyy" +" في حقل "+fieldLabel+""); 
				else
					alert("The date format should be : dd/mm/yyyy" +" in "+fieldLabel+" Field ");
						
				return false
			}
			if (strMonth.length<1 || month<1 || month>12)
			{
				if(UIlang=="ar-QA")
					alert("الرجاء اختيار شهر من حقل "+fieldLabel+""); 
				else
					alert("Please enter a valid month" +" in "+fieldLabel+" Field ");
				
				return false
			}
			if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
			{
				if(UIlang=="ar-QA")
					alert("الرجاء اختيار يوم من حقل "+fieldLabel+""); 
				else
					alert("Please enter a valid day in "+fieldLabel+" Field ")
				
				return false
			}
			if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
			{
				if(UIlang=="ar-QA")
					alert("الرجاء ادخال سنة بين "+minYear+"و "+maxYear +" في حقل"+fieldLabel+""); 
				else
					alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear +" in "+fieldLabel+" Field ")
				
				return false;
			}
			if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
			{
				if(UIlang=="ar-QA")
					alert("الرجاء ادخال تاريخ في حقل"+fieldLabel+""); 
				else
					alert("Please enter a valid date" +" in "+fieldLabel+" Field ");
					
				//Errfeild="Days";
				return false;
			}
			return true;
	}
*/
	function ValidateForm(formField)
	{
		var dt=formField;
		
		if(!required &&( formField=="" || formField=="0/0/0" ))
		{
			return true;	
		}
		else if(formField=="" || formField=="0/0/0")
		{
			if(UIlang=="ar-QA")
				alert("Please enter a  date_Ar"+fieldLabel+""); 
			else
				alert("Please enter a  date" +" in "+fieldLabel+" Field ");
				
			return false;
		}
		else
		{
			if (isDate(formField)==false)
			{						
				return false;
			}
		}
			
		return true;
	}			
	//*******************************************************
	return result;
}
//######### treeview Dispaly
function Toggle(node)
{
	// Unfold the branch if it isn't visible
	if (node.nextSibling.style.display == 'none')
	{
		// Change the image (if there is an image)
		if (node.children.length > 0)
		{
			if (node.children.item(0).tagName == "IMG")
			{
				node.children.item(0).src = "images/minus.gif";
			}
		}

		node.nextSibling.style.display = '';
	}
	// Collapse the branch if it IS visible
	else
	{
		// Change the image (if there is an image)
		if (node.children.length > 0)
		{
			if (node.children.item(0).tagName == "IMG")
			{
				node.children.item(0).src = "images/plus.gif";
			}
		}

		node.nextSibling.style.display = 'none';
	}

}

//######### Popup calender 

function CalPop(sInputName)
{				
			window.open('../includes/Calendar.aspx?textbox='+sInputName,'cal','width=260,height=260,left=270,top=180')
            //window.showModelessDialog('../includes/Calendar.aspx?textbox='+sInputName,'calender','status:no;dialogWidth:255px;dialogHeight:255px;dialogHide:true;help:no;scroll:yes;');
}

function GetDialogFeatures(dialogWidth, dialogHeight, resizable,scroll)

{

	return "dialogWidth: " + dialogWidth + "px;dialogHeight: " + dialogHeight + "px;status: no;unadorned: yes;scroll:" + scroll + ";help: no;" + (resizable ? "resizable: yes;" : "");

}


function Isdate(dtStr)
{
    return true;			
	if(!checkDatePattern(dtStr))
		return false;
		
	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)
	}
	var month=parseInt(strMonth)
	var day=parseInt(strDay)
	var year=parseInt(strYr)
		
	if (strYr.length!=4)
		return false;
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
			{				
				return false
			}
	return true;			
	
}
function doDateCompare(fromDt,toDt) 
{	

//Set the two dates
var dtdiff=0 ;
var firstdt	= fromDt.split("/");
var lastdt	= toDt.split("/");
var stardt	= new Date(firstdt[2],firstdt[1], firstdt[0]);
var enddt	= new Date(lastdt[2],lastdt[1], lastdt[0]); //Month is 0-11 in JavaScript 
var one_day	= 1000*60*60*24;//Set 1 day in milliseconds 
dtdiff		= Math.ceil((enddt.getTime()-stardt.getTime())/(one_day));
 	if( dtdiff<0)  		 
		return false;	
	else	
		return true;	
}

//---------------- printing job ---------------------------------------->
function AddDataGridHeader(elementId)
{
	var oTRs = document.getElementsByTagName("tr")
	var iTRs = oTRs.length
	for (var iCount=0;iCount<iTRs;iCount++)
	{
		if (oTRs[iCount].className == "ColHeader")
		{
			var oTR = oTRs[iCount];						
			var myTHead = eval("document.all."+elementId+".createTHead()");	
			myTHead.insertAdjacentElement("afterBegin",oTR)
			break;
		}
	}
}

function PrintReport(strPrintAreaId,GridID,pagedir)
{
if(GridID.length>0)
	AddDataGridHeader(GridID);

 var prtContent = document.getElementById(strPrintAreaId); 
 var WinPrint = window.open('','EMS','letf=0,top=0,toolbar=0,scrollbars=0,status=0');
 WinPrint.document.write( "<html dir= '"+pagedir+"' > <LINK href='../css/printRprt.css' type='text/css' rel=stylesheet> " +prtContent.innerHTML);
 WinPrint.document.close();
 WinPrint.focus();
 WinPrint.print();
 WinPrint.close();
 //prtContent.innerHTML=strOldOne;
}
//----------------------------------------------------------------------

var ErrorMsg10A	= "&nbsp;Enter Event Name";
var ErrorMsg10	= " this is test";

var ErrorMsg20	= "&nbsp;Invalid date";
var ErrorMsg20A	= "&nbsp;Invalid date ar";

var ErrorMsg30	= "&nbsp;Invalid phone number Format ";
var ErrorMsg30A	= "&nbsp;Invalid phone number Format ";

var ErrorMsg31	= "&nbsp;Invalid Fax number Format ";
var ErrorMsg31A	= "&nbsp;Invalid Fax number Format ";

var ErrorMsg32	= "&nbsp;Invalid Email number Format ";
var ErrorMsg32A	= "&nbsp;Invalid Email Format ";

var ErrorMsg40	= "&nbsp;Invalid Number ";
var ErrorMsg40A	= "&nbsp;Invalid Number ";

var ErrorMsg100	= "&nbsp;Name Should Start with letter ";
var ErrorMsg100A	= "&nbsp;Name Should Start with letter ";

var WarnMsg100	= "Do you want to save this data";
var WarnMsg100A	= "هل ترغب في حفظ البيانات";

var WarnMsg110	= "Do you want to Delete this data";
var WarnMsg110A	= "هل ترغب حقا في حذف هذه البيانات";


function DropDownItemRequired(oSrc, args)    
{     
    args.IsValid = (args.Value > 0 || args.Value < -1);
}

function If_Emp_ItemRequired(oSrc, args)
{
    if(document.getElementById("ddl_edit_Occupation").value=="2")//selected employed from the list
        args.IsValid = args.Value!="";
        //args.IsValid = args.Value.Length > 2; 
}


function Isdate_old(oSrc, args)
        {		        
	        var dtStr = args.Value;
	        var dtCh= "/";
            var minYear=1900;
            var maxYear=2100;
            var Errfeild="Years";
//	        if(!checkDatePattern(dtStr))
//	        {
//		        return args.IsValid= false;
//		        
//		    }
	          	
	        var daysInMonth = DaysArray(12);
	        var pos1=dtStr.indexOf(dtCh);
	        var pos2=dtStr.indexOf(dtCh,pos1+1);
	        var strYear=dtStr.substring(0,pos1);
	        var strMonth=dtStr.substring(pos1+1,pos2);
	        var strDay=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)
	        }
	        var month=parseInt(strMonth)
	        var day=parseInt(strDay)
	        var year=parseInt(strYr)
        		
	        if (strYr.length!=4)
		        return args.IsValid= false;//return false;
	        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
			        {				
				       return args.IsValid= false;// return false
			        }
	        return args.IsValid=  true;//return true;	        		
        	
        }

//	
//var doOKFunction = 0;
//var doCancelFunction = 0;
//var doButton2Function = 0;
//var doButton3Function = 0;

//// call this from dialog onload() to allow ok and cancel to call your code
//// functions should return true if they want the dialog to close
//function doSetOKCancel(okFunc, cancelFunc, button2Func, button3Func )
//{
//	//dump("top.window.navigator.platform: " + top.window.navigator.platform + "\n");

//	doOKFunction = okFunc;
//	doCancelFunction = cancelFunc;
//	doButton2Function = button2Func;
//	doButton3Function = button3Func;
//}

//function doOKButton()
//{
//	var close = true;

//	if ( doOKFunction )
//		close = doOKFunction();

//	if (close && top)
//		top.window.close();
//}

//function doCancelButton()
//{
//	var close = true;

//	if ( doCancelFunction )
//		close = doCancelFunction();

//	if (close && top)
//		top.window.close();
//}

//function doButton2()
//{
//	var close = true;

//	if ( doButton2Function )
//		close = doButton2Function();

//	if (close && top)
//		top.window.close();
//}

//function doButton3()
//{
//	var close = true;

//	if ( doButton3Function )
//		close = doButton3Function();

//	if (close && top)
//		top.window.close();
//}

//function moveToAlertPosition()
//{
//    // hack. we need this so the window has something like its final size
//    if (window.outerWidth == 1) {
//        dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n");
//        sizeToContent();
//    }

//	var xOffset = (opener.outerWidth - window.outerWidth) / 2;
//	var yOffset = opener.outerHeight / 5;

//	var newX = opener.screenX + xOffset;
//	var newY = opener.screenY + yOffset;

//	// ensure the window is fully onscreen (if smaller than the screen)
//	if (newX < screen.availLeft)
//		newX = screen.availLeft + 20;
//	if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
//		newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;

//	if (newY < screen.availTop)
//		newY = screen.availTop + 20;
//	if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
//		newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60;

//	window.moveTo( newX, newY );
//}

//function centerWindowOnScreen()
//{
//	var xOffset = screen.availWidth/2 - window.outerWidth/2;
//	var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10;

//	xOffset = ( xOffset > 0 ) ? xOffset : 0;
//  yOffset = ( yOffset > 0 ) ? yOffset : 0;
//	window.moveTo( xOffset, yOffset);
//}

 	