// Java script Functions 


//Opening in a new window

function openHelp(type)
{
window.open("../help/Default.asp?type="+type,"help","scrollbars=yes,left=0,top=0,width=300,height=450")

}



//Opening in a new window

function winOpenReports(myURL,winName)
{
window.open(myURL,winName,"scrollbars=yes,status=yes,left=0,top=0,width=700,height=500,menubar,resizable")
}

function winOpen(myURL,winName)
{
window.open(myURL,winName,"scrollbars=yes,status=yes,left=0,top=0,width=600,height=500")
}

function winOpenCourse(myURL,winName)
{
x=screen.width
y=screen.height
window.open(myURL,"mycourse","scrollbars=yes,statusbar=yes,left=0,top=0,width=772,height=600")
//window.open(myURL,winName)
window.open("","Complete","scrollbars=yes,left="+x+",top="+y+",width=200,height=100")
}

function winOpenCoursechk(myURL,winName)
{

x=screen.width
y=screen.height
window.open(myURL,"Chk","scrollbars=yes,left="+x+",top="+y+",width=200,height=200")
}

function winViewCourse(myURL,winName)
{
window.open(myURL,winName,"scrollbars=yes,left=0,top=0,width=772,height=600")

}

function winOpenChat(myURL,winName)
{
window.open(myURL,winName,"scrollbars=yes,left=0,top=0,width=772,height=600")

}

//Navigation bar

var oldelement;
oldelement="";

function PartWrapperToggle(elementName) {
if (oldelement!="" && oldelement!=elementName )
		{
		PartWrapperToggle(oldelement);
		oldelement=elementName;
 } 
 else
  {
   if (oldelement==elementName)
   	oldelement="";
   	else
   	oldelement=elementName;
 	}



	var HeaderElement = null;
	var BodyElement = null; 
	if(document.getElementsByName) {
		HeaderElement = document.getElementsByName(elementName+"Header");
		BodyElement = document.getElementsByName(elementName+"Body");
		UpImage = document.getElementsByName(elementName+"Up");
		DownImage = document.getElementsByName(elementName+"Down");
		if(BodyElement) {	
			if(BodyElement[0].style.display == "none") {
				BodyElement[0].style.display = "block";
				HeaderElement[0].className = "ListNuggetHeader";
				DownImage[0].style.display = "none";
				UpImage[0].style.display = "block";
			} else {
				BodyElement[0].style.display = "none";
				HeaderElement[0].className = "ListNuggetHeaderClosed";
				UpImage[0].style.display = "none";
				DownImage[0].style.display = "block";
			}
		}	
	}
	window.event.cancelBubble = true;
	return false;

}

//validating the Passwords
function cutSpaces(s)
{
	var s1, x;
	x = s1 = "";
	l = s.length;
	for(i = 0; i < l; i++)
		if((x = s.charAt(i)) != " ")
			s1+=x;
	return s1;
}

function validatePassword(t)
{

  newpass = t.newpass.value;
  conpass = t.conpass.value;
  
  
 
if(cutSpaces(newpass) == "")
 {
 alert(" New Password cannot be blank");
 t.newpass.value = "";
 t.newpass.focus();
 return false;
 }
if(cutSpaces(conpass) == "")
 {
 alert(" Confirmation Password cannot be blank");
 t.conpass.value = "";
 t.conpass.focus();
 return false;
 }

  if (t.newpass.value != t.conpass.value)
	{
	 alert("Confirmation Password is not match your new password")
	 t.newpass.value="";
	 t.conpass.value="";
	 t.newpass.focus();
	 t.conpass.focus();
	 return false
	 }

  
 return true
}




function emailCheck (emailStr,myobj) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)");
	myobj.focus();
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.");
    myobj.focus();
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!");
	        myobj.focus();
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.");
	myobj.focus();
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   myobj.focus();
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   myobj.focus();
   return false
}

// If we've gotten this far, everything's valid!
return true;
}



//function search string remove single quatation

 function chksearch(s,myobj)
 {

 	var s1, x;
 	x = s1 = "";
 	l = s.length;
 	for(i = 0; i < l; i++)
 		if((x = s.charAt(i)) != "'")
 			s1+=x;
 	 myobj.value=s1;

 }
 
//function checks for special char for login name 
 function chkSplChr(s,myobj)
 {
	var s1 = "\\(\\)<>@,;:#$%^&*-+=!~`?/{}'|\\\\\\\"\\.\\[\\]";
	l = s1.length;
	//alert(s1);
	if(s == "") {
		alert("Login Name must not be empty");
		return false;
	} else {
	for(i=0; i< l; i++) {
		if(s.indexOf(s1.charAt(i)) != -1) {
			alert("Special Characters are not allowed in the Login Name");
			myobj.value = "";
			myobj.focus();
			//break;
			return false;
		}

	}
	}
	
 	return true;

 }

//function checks for numbers 
 function chkNumbers(s,myobj)
 {
	var s1 = "0123456789.";
	l = s.length;
	
	if(s == "") {
		alert("The field must not be empty");
		return false;
	} else {
		for(i=0; i< l; i++) {
			if(s1.indexOf(s.charAt(i)) == -1) {
				alert("Enter only numbers");
				myobj.value = "";
				myobj.focus();
				//break;
				return false;
			}

		}
	}
	
 	return true;

 }

//function checks for numbers 
 function chkPhoneNumbers(s,myobj)
 {
	var s1 = "0123456789+ -";
	l = s.length;
	
	if(s == "") {
		alert("The field must not be empty");
		return false;
	} else {
		for(i=0; i< l; i++) {
			if(s1.indexOf(s.charAt(i)) == -1) {
				alert("Enter only numbers");
				myobj.value = "";
				myobj.focus();
				//break;
				return false;
			}

		}
	}
	
 	return true;

 }
//-------------------------


function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function




function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function

/*-------------------------------------------------------------
end of date validation function*/