
function IsMixedCased(Str)
{
	var i, c, PrevCase = "", res;
	var asciiV ; //hamed -- This var is to check the ASCII decimal value of the Character
		     //This function was not working for cases like 'Côté' but by adding this checking
		     //var the problem is solved and french characters can be added in that format
	
	res = false;
	// Checking Upper and lower
	for(i=0; i<Str.length; i++)
	{
		c = Str.charAt(i);
		asciiV = Str.charCodeAt(i) //hamed

		if((c >= "a" && c <= "z") || (asciiV >= 224 && asciiV <= 246)) // hamed
		{
			if(PrevCase == "U") res = true;
			PrevCase = "L";

		}
		else
		if((c >= "A" && c <= "Z") || (asciiV >= 192 && asciiV <= 220)) // hamed
		{
			if(PrevCase == "L") 
				res = true;
			else if(PrevCase == "U") 
				return false; // This prevents two Upper letter beside eachother
			PrevCase = "U";
		}
		else	
			PrevCase = "";
		
	}
	
	return res;
}

function IsDigit(Ch)
{
	return (Ch >= "0" && Ch <= "9");
}

function GetNumber(str)
{
	if(Trim(str) == '')
		return 0;
		
	var c, i, s;
	s = "";
	for(i = 0; i < str.length; i++)
	{
		c = str.substr(i, 1);
		if(c == "." || IsDigit(c))
			s += c;
	}	
	
	if(Trim(s) == '')
		return 0;
		
	return parseFloat(s);
}

function IsNumber(str)
{
	if(Trim(str) == '')
		return false;
	var c, i
	for(i = 0; i < str.length; i++)
	{
		c = str.substr(i, 1);
		if(!(c == "." || IsDigit(c)))
			return false;
	}	
	
	return true;
}

function IsLetter(Ch)	
{
	return (Ch >= "a" && Ch <= "z") || (Ch >= "A" && Ch <= "Z");
}

function Trim(str)
{
	if(str.length == 0) return '';
	var first = 0, last = str.length - 1;
	while(first < str.length && str.substr(first, 1) == ' ') first++;
	while(last > 0 && str.substr(last, 1) == ' ') last--;
		
	return str.substr(first, last - first + 1);
}

function Replace(Str, FindStr, ReplaceStr)
{
	var d = Str;
	while(d.indexOf(FindStr) > -1) d = d.replace(FindStr, ReplaceStr);
	return d;
}
 
function NumberBoxKeypress()
{
	var kc;
	kc = window.event.keyCode;
	if((kc < 48 || kc > 57) && kc != 13)
		window.event.keyCode = 0;
		
}
	
function TextNoSpaceKeyPress()
{
	var kc;
	kc = window.event.keyCode;
	if(!((kc >= 97 && kc <= 122) || (kc >= 65 && kc <= 90 ) || (kc >= 48 && kc <= 57 ) || kc!=32 || kc==13 || kc==45 || kc==46))
		window.event.keyCode = 0;
}

function UppercaseKeyPress()
{
	var kc;
	kc = window.event.keyCode;
	if(!((kc >= 97 && kc <= 122) || (kc >= 65 && kc <= 90 ) || (kc >= 48 && kc <= 57 ) || kc!=32 || kc==13 || kc==45 || kc==46))
		window.event.keyCode = 0;
		
	if(kc >= 97 && kc <= 122)
		window.event.keyCode = kc - 97 + 65;
}

function TextOneSpaceKeyPress()
{
	var kc;
	kc = window.event.keyCode;
	//alert(kc);
	if(!((kc >= 35 && kc <= 126) || kc==33 || kc==32 || kc==13 || kc==45 || kc==46 || kc==47 || kc>191))
		window.event.keyCode = 0;
}
	
function UserConfirm(Prompt)
{
	return window.confirm(Prompt);
}
	
function AreYouSure()
{
	return UserConfirm('Are you sure?');
}


function LanguageChar(English, French, Other)
{
	if     ( English &&  French &&  Other) return  "T";
	else if(!English &&  French &&  Other) return  "S";
	else if( English && !French &&  Other) return  "L";
	else if(!English &&  French && !Other) return  "F";
	else if( English && !French && !Other) return  "E";
	else if( English &&  French && !Other) return  "B";
	else if(!English && !French &&  Other) return  "A";
	else                                   return  "U";
}

function LangIsEnglish(LanguageChar)
{
	return ("TLEB".indexOf(LanguageChar) > -1);
}

function LangIsFrench(LanguageChar)
{
	return ("TSFB".indexOf(LanguageChar) > -1);
}

function LangIsOther(LanguageChar)
{
	return ("TSLA".indexOf(LanguageChar) > -1);
}

function EmailIsValid(EmailAddress)
{
	var s = Trim(EmailAddress);
	if(s == "") return false;
	
	// Check the minimum length
	var S_Length  = s.length;
	if(S_Length < 5) return false;
	
	// "@" must exist and not be the first character
	var AT_Place  = s.indexOf("@");
	if(AT_Place < 1) return false;

	// Check minimum length after "@"
	if(S_Length < AT_Place + 4) return false;

	// Check for "@" to be repeated only once
	if(s.indexOf("@", AT_Place + 1) != -1) return false;
	
	// Checking existance of "." after "@"
	var DOT_Place = s.indexOf(".", AT_Place + 2);
	if(DOT_Place == -1) return false;
	
	// "." should not be the last character
	if(DOT_Place == S_Length - 1) return false;
	
	return true;
}

if(document.getElementById && !document.all)
	document.all = function(id)
	{
		return document.getElementById(id);
	}
else if(!document.getElementById && document.all)
	document.getElementById = function(id)
	{
		return document.all(id);
	}

if(!window.showModalDialog)
	window.showModalDialog = function(URL, Caption, Options)
	{
		Options = Options.toUpperCase();
		Options = Replace(Options, ":", "=");
		Options = Replace(Options, ";", ",");
		Options = Replace(Options, "DIALOGHEIGHT", "height");
		Options = Replace(Options, "DIALOGWIDTH" , "width");
		window.open(URL, Caption, Options);
	}
	
/*
'	Code Permanent Rules:
'		1. The first 4 characters are alpha characters:
'		   The first 3 characters should match the first 3 letters of the Last Name. If they do not match, then look at the first 3 characters of the maiden name.
'		   The 4 th character if the first letter of the First Name
'		   If there are any spaces within these characters, they should be replaced by  X
'
'	    2. The next six characters are numerical and represent the birthdate:
'	       The date is in the form DDMMYY.
'	       If the student is female then MM = MM +50
'	     
'		3. The last 2 characters are numerical also but there is no validation.
*/
	function CheckCodePerm(CP, FirstName, LastName, MaidenName, BirthDate, Sex)
	{
		if(CP.length != 12)
			return 1;
			
		if(!(IsLetter(CP.substr(0 , 1)) && IsLetter(CP.substr(1 , 1)) && 
			 IsLetter(CP.substr(2 , 1)) && IsLetter(CP.substr(3 , 1)) && 
			 IsDigit (CP.substr(4 , 1)) && IsDigit (CP.substr(5 , 1)) && 
			 IsDigit (CP.substr(6 , 1)) && IsDigit (CP.substr(7 , 1)) && 
			 IsDigit (CP.substr(8 , 1)) && IsDigit (CP.substr(9 , 1)) && 
			 IsDigit (CP.substr(10, 1)) && IsDigit (CP.substr(11, 1)) )
		  )
			return 2;
		
		CP = CP.toUpperCase();
		
		var ex;
		ex = CP.substr(0, 3);
		
		LastName   = PrepareLastName(LastName);
		MaidenName = PrepareLastName(MaidenName);

		if(ex != LastName && ex != MaidenName)
			return 3;
		
		FirstName = FirstName.toUpperCase().substr(0, 1);
		ex = CP.substr(3, 1).toUpperCase();
		if(ex != FirstName) 
			return 4;
			
		BirthDate = new Date(BirthDate);
		var d;
		d = BirthDate.getDate().toString(); if(d.length < 2) d = "0" + d;
		ex = CP.substr(4, 2);
		if(ex != d) return 5;
		
		d = BirthDate.getMonth() + 1; if(Sex == "F") d = d + 50;
		d = d.toString(); if(d.length < 2) d = "0" + d;
		ex = CP.substr(6, 2);
		if(ex != d) return 6;
		
		d = BirthDate.getYear().toString();
		if(d.length == 4) d = d.substr(2, 2); 
		ex = CP.substr(8, 2);
		if(ex != d) return 7;
		
		return 0;
	}
	
	function PrepareLastName(LastName)
	{
		var i, d = "", c;
		LastName = LastName.toUpperCase();
		for(i = 0; i < LastName.length; i++)
		{
			c = LastName.substr(i, 1);
			if(c >= "A" && c <= "Z")
				d = d + c;
		}
		return (d + '  ').substr(0, 3).replace(" ", "X");
	}

function right(e) 
{
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
		return false;
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
		//alert("Sorry. Right click is not allowd...");
		return false;}
	return true;
}

function ShowProgressWindow()
{
	window.open("/common/uiProgress.asp", "ConcordiaProgressWindow", "center=1, width=250, height=250, toolbar=no, menubar=no, location=no, directories=no");
}

function CloseProgressWindow()
{
	var i;
	for(i=0; i<window.parent.frames.length; i++)
	{
		alert(window.parent.frames(i).name);
		if(window.parent.frames(i).name == "ConcordiaProgressWindow")
		{
			window.parent.frames(i).close();
			break;
		}
	}
}

if(document.layers)window.captureEvents(Event.MOUSEDOWN);
//document.onmousedown=right;
//window.onmousedown=right;


function showuserdetails(userid)
{
	window.open("uiuser.asp?id=" + userid, "", "centerscreen=1,width=300,height=400");
}

function showpaymentdetails(id)
{
	window.open("uipayment.asp?txn_id=" + id, "", "centerscreen=1,width=400,height=500");
}

