// author: Abdullah M. Al Fararjeh
// date: October 29, 2007
function valideFloatNumericExp(val) {
	
	var flag = true;
	
	var regNumeric1 = /^([0-9]+\.[0-9]+)$/;
	var regNumeric2 = /^(\.[0-9]+)$/;
	var regNumeric3 = /^([0-9]+)$/;
	
	if(val.search(regNumeric1) == -1 && val.search(regNumeric2) == -1 && val.search(regNumeric3) == -1)
	{
		flag = false;
	}
			
	return flag;
}

// author: Abdullah M. Al Fararjeh
// date: November 28, 2007
//functionality: the function receives two parameters. The parameters are date in string data type.
//Then, the function compares between them and return the minimum parameter.
function findMinimumDate(firstDateStr, secondDateStr){
	var day, month, year;
	var firstDate, secondDate;
	
	day = parseFloat(firstDateStr.substring(0, firstDateStr.indexOf("/")));
	month =
		parseFloat(
			firstDateStr.substring(
				firstDateStr.indexOf("/") + 1,
				firstDateStr.lastIndexOf("/")));
	year = parseFloat(firstDateStr.substring(firstDateStr.lastIndexOf("/") + 1));

	firstDate = new Date(month + "/" + day + "/" + year);
	
	day = parseFloat(secondDateStr.substring(0, secondDateStr.indexOf("/")));
	month =
		parseFloat(
			secondDateStr.substring(
				secondDateStr.indexOf("/") + 1,
				secondDateStr.lastIndexOf("/")));
	year = parseFloat(secondDateStr.substring(secondDateStr.lastIndexOf("/") + 1));

	secondDate = new Date(month + "/" + day + "/" + year);
	
	if(firstDate < secondDate)
		return firstDateStr;
	else
		return secondDateStr;
}

// author: Abdullah M. Al Fararjeh
// date: November 28, 2007
//functionality: the function receives two parameters. The parameters are date in string data type.
//Then, the function compares between them and return the maximum parameter.
function findMaximumDate(firstDateStr, secondDateStr){
	var day, month, year;
	var firstDate, secondDate;
	
	day = parseFloat(firstDateStr.substring(0, firstDateStr.indexOf("/")));
	month =
		parseFloat(
			firstDateStr.substring(
				firstDateStr.indexOf("/") + 1,
				firstDateStr.lastIndexOf("/")));
	year = parseFloat(firstDateStr.substring(firstDateStr.lastIndexOf("/") + 1));

	firstDate = new Date(month + "/" + day + "/" + year);
	
	day = parseFloat(secondDateStr.substring(0, secondDateStr.indexOf("/")));
	month =
		parseFloat(
			secondDateStr.substring(
				secondDateStr.indexOf("/") + 1,
				secondDateStr.lastIndexOf("/")));
	year = parseFloat(secondDateStr.substring(secondDateStr.lastIndexOf("/") + 1));

	secondDate = new Date(month + "/" + day + "/" + year);
	
	if(firstDate > secondDate)
		return firstDateStr;
	else
		return secondDateStr;
}

////////////////// Sam Start
function checkDate(frm,dt)
{
		
//		var fromD = eval('frm.'+dt+'.value');
        var fromD =dt; 
		alert(fromD);
		var sDay = fromD.substring(0,fromD.indexOf("/"));//parseFloat(fromD.substring(0,fromD.indexOf("/")));
		var sMonth = fromD.substring(fromD.indexOf("/") + 1,fromD.lastIndexOf("/"));//parseFloat(fromD.substring(fromD.indexOf("/") + 1,fromD.lastIndexOf("/")));
		var sYear =	fromD.substring(fromD.lastIndexOf("/") + 1);//parseFloat(fromD.substring(fromD.lastIndexOf("/") + 1));
		
		if(isNaN(sDay))
			return false;
		else if(isNaN(sMonth))
			return false;
		else if(isNaN(sYear))
			return false;
		
		var day = parseFloat(sDay);
		var month = parseFloat(sMonth);
		var year = parseFloat(sYear);
			
		fromD =new Date(month + "/" + day + "/" + year);
	
	
		
}
function validateEditAppForm(frm){
	if(frm.AppDate.value == null || frm.AppDate.value == ""){
		alert("?????? ????? ???????");
		//frm.FromDate.focus();
		return;
	}else if(frm.AppTime.value == null || frm.AppTime.value == ""){
		alert("?????? ????? ??????");
		frm.AppTime.focus();
		return;
	}else if(frm.AppPlace.value == null || frm.AppPlace.value == ""){
		alert("?????? ????? ??????");
		frm.AppPlace.focus();
		return;
	}else if(frm.AppSubject.value == null || frm.AppSubject.value == ""){
		alert(" ?????? ?????");
		frm.AppSubject.focus();
		return;
	}else
		window.location = "AppointmentUpdated.html";
}

//////// END Sam

function validDate(toD)
	{
		var day = parseFloat(toD.substring(0, toD.indexOf("/")));
		var month =
			parseFloat(
				toD.substring(
					toD.indexOf("/") + 1,
					toD.lastIndexOf("/")));
		var year = parseFloat(toD.substring(toD.lastIndexOf("/") + 1));

		toD = new Date(month + "/" + day + "/" + year);
		dd = toD.getDate();
		mm = toD.getMonth()+1;
		yy = toD.getFullYear();
		if(dd==day && mm==month && yy==year)
			return true;
		else
			return false;
}
function isDDMMMYYYY(date){
		pos1=date.indexOf("/");
		if (pos1==-1)
			return false;
		pos2=date.indexOf("/",pos1+1);			
		if (pos2==-1)
			return false;		
		if (date.indexOf("/",pos2+1)!=-1)
			return false;
		days = date.substring(0,pos1)
		if (isNaN(days))
			return false;
		if (!((days>=1)&&(days<=31)))
			return false;
		years= date.substring(pos2+1)
		if (isNaN(years))
			return false;
		months = date.substring(pos1+1,pos2)				
		if (isNaN(months))
			return false;
		if (!((months>=1)&&(months<=12)))
			return false;
		return true;
}
function validDatePeriod(fromD,toD)
{
		var day = parseFloat(toD.substring(0, toD.indexOf("/")));
		var month =
			parseFloat(
				toD.substring(
					toD.indexOf("/") + 1,
					toD.lastIndexOf("/")));
		var year = parseFloat(toD.substring(toD.lastIndexOf("/") + 1));

		toD = new Date(month + "/" + day + "/" + year);


		day = parseFloat(fromD.substring(0, fromD.indexOf("/")));
		month =
			parseFloat(
				fromD.substring(
					fromD.indexOf("/") + 1,
					fromD.lastIndexOf("/")));
		year =
			parseFloat(fromD.substring(fromD.lastIndexOf("/") + 1));

		fromD =new Date(month + "/" + day + "/" + year);


   if (fromD  <= toD) 
		return true;
   else
		return false;		
}

function isStartWithCharacter(str){
		if (str=="")
			return true;
		if (!
			(((str.charAt(0)>='a')&&(str.charAt(0)<='z'))
		  ||((str.charAt(0)>='A')&&(str.charAt(0)<='Z'))
		  
		   ))
			return false;
			else
			return true;	
}
function isCharactersAndNumber(str){
		if (str=="")
			return true;
	for (var i =0;i <str.length;i++){
		if (!
			(((str.charAt(i)>='a')&&(str.charAt(i)<='z'))
		  ||((str.charAt(i)>='A')&&(str.charAt(i)<='Z'))
		  ||((str.charAt(i)>='0')&&(str.charAt(i)<='9'))
		  ||((str.charAt(i)=='_'))
		   ))
			return false;
	}
	return true;	
}

function isNameok(frm)
	{        
    
	if (frm.LoginName.value.length == 0)
		{
		alert('You have to enter a login name, please');
		frm.LoginName.focus();
		return false;
		}
	if (checkName(frm.LoginName.value) == false)
		{
		alert('Login name must not contain special character');
		frm.LoginName.focus();
		frm.LoginName.select();
		return false;
		}
	if (frm.Password.value.length == 0)
		{
		alert('You have to enter a login password, please');
		frm.Password.focus();
		return false;
		}
	if (checkName(frm.Password.value) == false)
		{
		alert('Password must not contain special character');
		frm.Password.focus();
		frm.Password.select();
		return false;
		}
        
	return true;
	}



function isCharOrDigit(c)
{
    var test = c;
    if (test == "_" || test == "a" || test == "b" || test == "c" || test == "d" || test == "e"
    || test == "f" || test == "g" || test == "h" || test == "i" || test == "j"
    || test == "k" || test == "l" || test == "m" || test == "n" || test == "o"
    || test == "p" || test == "q" || test == "r" || test == "s" || test == "t"
    || test == "u" || test == "v" || test == "w" || test == "x" || test == "y"
    || test == "z" || test == "'" || test == "A" || test == "B" || test == "C"
    || test == "D" || test == "E" || test == "F" || test == "G" || test == "H"
     || test == "I" || test == "J" || test == "K" || test == "L" || test == "M"
     || test == "N" || test == "O" || test == "P" || test == "Q" || test == "R"
    || test == "S" || test == "T" || test == "U" || test == "V" || test == "W"
    || test == "X" || test == "Y" || test == "Z" ||test == "0" || test == "1"
    || test == "2" || test == "3" || test == "4"
    || test == "5" || test == "6" || test == "7" || test == "8" || test == "9")
        {
        return true;
        }
    return false;
    }

function checkName(s)
{
    var test = s;
    if ( (test.length == 1) && (test == "'") )
	{
	return false;
	}
    for (var k=0 ; k<test.length ; k++)
        {
        var c = test.substring(k,k+1);
        if (isCharOrDigit(c) == false)
            {
            return false;
            }
         }
	return true;
}

function checkSpecialCharText(s)
{

    var test = s;
    //alert('test1='+test);
    if ( (test.length == 1) && (test == "'") )
	{
	return false;
	}
	// alert('test1.1='+test+' len'+test.length);
    for (var k=0 ; k<test.length ; k++)
        {
        var c = test.substring(k,k+1);
      //  alert('c='+c+' k='+k);
      //   alert('sub='+test.substring(k,k+1));
        if (isSpecialChar(c) == true)
            {
            return true;
            }
         }
	return false;
}




function isSpecialChar(c)
{
    var test = c;
   // alert('test2='+test);
    if (test == ";" || test == "'" || test == "-" || test == "&" || test == "%" || test == "~" || test == "/")
        {
        // alert('retrun T');
        return true;
        }
      //alert('retrun F');
    return false;
    }