///This is a function collection////
//By Francis David Kullu//
//Define Function
function keyword(keyw, ext)
{
if(document.getElementById("key").value==""){
    alert("Please enter the search string.");
    document.getElementById("key").focus();
    return true;

}
var keyword= ''
if(document.getElementById("box").value==".ppt"){
win=window.open("Presentations/" + keyw+ ".ppt", "newWind", "toolbar=yes,location=yes,directories=no,status=no, menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes")
}
else
{
//location.href= "Articls/" + keyw + ext;
win=window.open("Articls/" + keyw+ ".htm", "newWind", "toolbar=yes,location=yes,directories=no,status=no, menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes")
        
}//end of if else 

//window.open("YOUR PAGE NAME", "newWin", "toolbar=yes,location=yes,directories=no,status=no, menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width=400,height=260")
}//end of keyword funciton
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////Pressing Enter to Focus next form Control//////////       ///////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function enterButton(nxtCtrl){
if(window.event.keyCode==13){
document.getElementById(nxtCtrl).focus();
document.getElementById(nxtCtrl).select();
}

}//end of enterButton

//////////////////////////////////////end of function////////////////////////////////////////////////////////


//////
function isEmpty(arg, msg){
if(document.getElementById(arg).value==""){
    alert("Value required for "+ msg);
    document.getElementById(arg).focus();
    return true;
}//end of if
else{
    return false;
}//end of else part
    
}//isEmpty()
function isNotSelected(arg, msg){
if(document.getElementById(arg).value==0){
	alert("Please select an option for "+msg);
	document.getElementById(arg).focus();
	return true;
	}

}//end of this function
//These functions are to be used to generalise the look of mouse pointing to the rows of tabular data.///
function funSetOut(RowId){
//document.getElementById(RowId).bgColor="#a35876"; 
document.getElementById(RowId).bgColor="#f0f2f0";
}//end of funSetOut


function funSetIn(RowId){
document.getElementById(RowId).bgColor="#bbddbb";
}//end of funSetOut

////date difference between two given dates/////
function DateDiff(date1, date2){
    var d1=new Date(date1);
    var d2=new Date(date2);
    var d3=(d2-d1)/86400000;
    return d3;
}//end of DateDiff()

//A function to check out Non-numeric entry///

function isNumeric(str, msg){
    var list="0123456789.";
    val=document.getElementById(str).value;
    for(var i=0;i<val.length; i++){
        if(list.indexOf(val.charAt(i))==-1){
            if(msg==""){
                alert("Please enter a valid data:");
                document.getElementById(str).focus(); 
				document.getElementById(str).select();                       
                return false;
            }//end of if msg==""
            else{
                alert("Please enter a valid data for "+msg);
                document.getElementById(str).focus();
     			document.getElementById(str).select();
                return false;
            }//end of else part of if msg==""
        }//end of if condition
    }//end of for loop
                return true;
}//end of checkNumeric()
//////////////this is new password  checking same or not///////////
function isSame(arg1, arg2){
if(document.getElementById(arg1).value!=document.getElementById(arg2).value){
    alert("Passwords you typed are not Same!");
    document.getElementById(arg1).select();
    return true;
}//end of if
else{  return false;}//end of else part
}//end of function isSame()
//////////////////////////////////////////////////////////////////

//////////////////////////////date validation/////////////////////


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

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 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 isDate(dtStr){
	var dtCh= "-";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=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){
		alert("The date format should be : mm-dd-yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

//////////////////////////////end of date validation//////////
////////////////This is for date validation//////////////////////////
///////////////////////////////Email Checking Script///////////////////////////////////////////

var invalidaddress=new Array()
invalidaddress[0]="aahotmail"
invalidaddress[1]="aarocketmail"
invalidaddress[2]="aayahoo"
invalidaddress[3]="zdnetmail"
//extend or shorten this list if neccessary

var testresults
function checkemail(arg){
var invalidcheck=0;
var str=document.getElementById(arg).value;
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
var tempstring=str.split("@")
tempstring=tempstring[1].split(".")
for (i=0;i<invalidaddress.length;i++){
if (tempstring[0]==invalidaddress[i])
invalidcheck=1
}
if (invalidcheck!=1)
testresults=true
else{
alert("Please input a more official email address!")
document.getElementById(arg).select();
testresults=false
}
}
else{
alert("Please input a valid email address!")
document.getElementById(arg).select();
testresults=false
}
return (testresults)
}
/////////////////////////////////////////////////////////////
//////////////////////end of checkmail//////////////
////////////////////////////////////////////////////////
///////////////////////checking Phone Number/////////////
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isPhoneValid(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
////////////////end of checking phone number////////////