toggle=false;
var winhelp;
function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
self.name = "mainWin"; }

/************************************************
Purpose	:	To get the cookie value
Logic	:	Get the cookie value.
			Parse it and get the required string
************************************************/
function getcookie(cookiename)
{
	cookie_tmp=document.cookie;
	var pairs=cookie_tmp.split(";");
	for (i=0;i<pairs.length;++i)
	{
		var pairsplit=pairs[i].split("=")
		if (ltrim(pairsplit[0])==cookiename)
		{
			if(pairsplit.length>1)
			{ 
				return pairsplit[1]
			}
			else return 0;
		}
	}
	return 0;
}
function setCookie()
{
		document.cookie="errorvar=1;";
}
function getcategory(formelement,strsel) 
{
   	for (i=0;i< formelement.options.length;i++)
	   if (formelement.options[i].value == strsel)
		return i;
		
		return 0;
}

/************************************************
Purpose	:	To Display Error Message
Logic	:	Get the error message
			Use error.asp to Display the error
************************************************/
function alerte(errmsg)
{
	if(getcookie())
	{
		document.cookie="errorvar=0;";
		 if  (self.navigator.appName == "Microsoft Internet Explorer")
		 {
			window.showModalDialog('error.asp?t=e&e='+errmsg,'','dialogWidth:300px;dialogHeight:120px;help:no;status:no;');
		 }
		 else if (window.navigator.appName == "Netscape")
		 {
			height_tmp=(screen.availHeight-120)/2;
			width_tmp=(screen.availWidth-300)/2;
			window.open('error.asp?t=e&e='+escape(errmsg)+'&type=NE','','alwaysRaised=yes,alwaysLowered=yes,menubar=no,location=no,toolbar=no,scrollbars=no,dependent=yes,width=300px,height=120px,screenX='+height_tmp+',screenY='+width_tmp+"'")
		}
	}
}
/************************************************
Purpose	:	To Display Success Message
Logic	:	Get the success message
			Use error.asp to Display the message
************************************************/
function alerts(errmsg)
{
	 if(getcookie())
	 {
		document.cookie="errorvar=0;";
		if  (self.navigator.appName == "Microsoft Internet Explorer")
		{
		window.showModalDialog('error.asp?t=s&e='+errmsg,'','dialogWidth:300px;dialogHeight:120px;help:no;status:no;')
		}
		else if (window.navigator.appName == "Netscape")
		{
		height_tmp=(screen.availHeight-120)/2;
		width_tmp=(screen.availWidth-300)/2;
		window.open('error.asp?t=s&e='+escape(errmsg)+'&type=NE','','alwaysRaised=yes,alwaysLowered=yes,menubar=no,location=no,toolbar=no,scrollbars=no,dependent=yes,width=300px,height=120px,screenX='+height_tmp+',screenY='+width_tmp+"'")
		}
	}
}
/************************************************
Purpose	:	Used to launch the Help screen
Logic	:	Launch Help screen
			If help screen is launched, keep the help screen on the top
************************************************/
function focusme()
{
	//document.Frmcourseadmin.test.value=document.Frmcourseadmin.test.value+1
  if (toggle == "opened")
  {
    winhelp.focus();
  } 

}
function unloadme()
{
	//alert(toggle);
	if (toggle == "opened")
	{
		winhelp.close_remote();
	}
}
function launchhelp(filename)
{
		//win=window.open("'"+helpcourse.asp?courseid='+document.Frmcourseadmin.Txtcourseid.value,'','menubar=no,location=no,toolbar=no,scrollbars=yes,width=500,height=400')
		//if(window.navigator.appName=="Netscape")
		//{
		// filename_tmp=filename.split("=")
		// filename=filename_tmp[0]+ "=" +escape(filename_tmp[1])
		 
		// }
		 
		if (toggle != "opened")
		{
			toggle="opened";
			winhelp=window.open(filename,'eDvantageHelp','resizable=yes,menubar=no,location=no,toolbar=no,scrollbars=yes,width=500,height=400')
			winhelp.moveTo(100,100);
		}
		else
		{
			winhelp.close_remote();
			winhelp=window.open(filename,'eDvantageHelp','resizable=yes,menubar=no,location=no,toolbar=no,scrollbars=yes,width=500,height=400')
			winhelp.moveTo(100,100);
		}
		
}

function helponthis(filename)
{				 
	winhelp=window.open(filename,'','menubar=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=400')		
}

/****************************General Validation Functions*****************************/
/************************************************
Purpose	:	Function to check for integer
Logic	:	Parse the string and find Integers
***********************************************/
function checkNum(instring)
{
	if(instring=="0")
		return true;
	else
	{
		//Radix parameter is given with parseInt to avoid octal conversions
		x = parseInt(instring,10);
		if (isNaN(x))
			return false;
		else
		{
			if(x>0)
				if(instring==x) 
					return true;
				else
					return false;
			else
			return false;
		}
	}

}

/************************************************
Purpose	:	Function to check for integer
Logic	:	Parse the string and find Integers
***********************************************/
function checkPrice(instring)
{
	var x;

	if ((instring=="0") || (instring=="0.0"))
		return true;
	else
	{
		//Radix parameter is given with parseInt to avoid octal conversions
		x = parseFloat(instring);
		if ((isNaN(x)) || (x < 0.0))
			return false;
		else
			return true;
	}

}
/************************************************
Purpose	:	Function checks for blank space inbetween characters
Logic	:	Parse the string and find Whitespaces
***********************************************/
function checkWhitespace(s)
{
	checkfor=" \t\n\r";
	flag=true;
	for(i=0;i<s.length;i++)
	{
		// take the first character
		var c=s.charAt(i);
		if(checkfor.indexOf(c)== -1)
		{  
			flag=true;
		}
		else
		{
			flag=false;
			break;
		}
	}
	//No white space in between
	if(i>=s.length)
		flag= true;
	else
		flag=false;
	return flag;
}
/************************************************
Purpose	:	Function checks for special characters
Logic	:	Parse the string and find special char
***********************************************/

function checkSpecial(s)
{
	checkfor=" ~!@#$%^&*()_+=-{}[]`|\\\"\'\:\;<>,.?/";
	flag=true;
	for(i=0;i<s.length;i++)
	{
		// take the first character
		var c=s.charAt(i);
		if(checkfor.indexOf(c)== -1)
		{  
			flag=true;
		}
		else
		{
			flag=false;
			break;
		}
	}
	//No white space in between
	if(i>=s.length)
		flag= true;
	else
		flag=false;
	return flag;
}


/************************************************
Purpose	:	Function to encrypt the textarea
Logic	:	Replace the new line char with '@@'
***********************************************/
function textencrypt(s)
{
	//a=s.replace(/\n|\r/g,'@@');
	// DTS ID: EDVANT1.0S_000026
	a=s.replace(/\r/g,'@@');
	a=a.replace(/\n/g,'');
	return a;
}
/************************************************
Purpose	:	Function to decrypt the textarea
Logic	:	Replace '@@@@' and '@@' with new line char.
***********************************************/
function textdecrypt(s)
{
	//a=s.replace(/@@@@/g,'\n');
	//a=a.replace(/@@/g,'\n');
	// DTS ID: EDVANT1.0S_000026
	a=s.replace(/@@/g,'\r');
	return a;
}

/***********************************************
Purpose	:	Function for trimming left most spaces in the string
***********************************************/
function ltrim(s)
{
	var i;
	instringlength=s.length;
	if (instringlength>0)
	{
		for(i=0;i<instringlength;i++)
		if(s.charAt(i)!=' ' &&  s.charAt(i)!='\t' && s.charAt(i)!='\b' && s.charAt(i) != '\r' && s.charAt(i) != '\n')
			break;
		return s.substring(i);
	}	
	else
	{
		return s;
	}	
}
/***********************************************
Purpose	:	To verify the date format.
***********************************************/
var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field. Please enter it now."

// i - abbreviation for "invalid"
var iDatePrefix = "The Day, Month, and Year for "
var iDateSuffix = " do not form a valid date.  Please reenter them now."

// Global variable defaultEmptyOK defines default return value 
var defaultEmptyOK = false


function makeArray(n)
{
   for (var i = 1; i <= n; i++)
   {
      this[i] = 0
   } 
   return this
}

//var daysInMonth = makeArray(12);
//var daysInMonth = new String(12);
var daysInMonth = new Array();
daysInMonth[1] = 31;

daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;

daysInMonth[4] = 30;

daysInMonth[5] = 31;

daysInMonth[6] = 30;

daysInMonth[7] = 31;

daysInMonth[8] = 31;

daysInMonth[9] = 30;

daysInMonth[10] = 31;

daysInMonth[11] = 30;

daysInMonth[12] = 31;


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}


function isInteger (s)
{
	var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);


        if (!isDigit(c)) return false;
    }

    return true;
}


function isSignedInteger (s)
{
	if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;

        var secondArg = defaultEmptyOK;


        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}


function isNonnegativeInteger (s)
{
	var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s,10) >= 0) ) );
}


function isYear (s)
{
	if (isEmpty(s)) 
	{
       if (isYear.arguments.length == 1)
			return defaultEmptyOK;
       else
		return (isYear.arguments[1] == true);
	}
    if (!isNonnegativeInteger(s))
		return false;
//    return ((s.length == 2) || (s.length == 4));
	return (s.length == 4);
}



function isIntegerInRange (s, a, b)
{
	if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    if (!isInteger(s, false)) return false;

    var num = parseInt (s,10);
    return ((num >= a) && (num <= b));
}


function isMonth (s)
{
	if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}


function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}


function daysInFebruary (year)
{
    return ( (year % 4 == 0) &&( !(year % 100 == 0) || (year % 400 == 0) ) ? 29 : 28 );
}


//function isDate (year, month, day)
function isDate (inmonth, inday, inyear)
{

    var year=inyear;
    var month=inmonth;
    var day=inday;
    if (year.length < 4)
      {
        year= "20" + year;
      }
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false)))
		return false;

//  Use the parseInt() function with the radix paramater 
//  with 10 (decimal) otherwise assumes octal.. !?
    var intYear = parseInt(year,10);

    var intMonth = parseInt(month,10);

    var intDay = parseInt(day,10);


    if (intDay > daysInMonth[intMonth])
		return false; 

    if ((intMonth == 2) && (intDay >daysInFebruary(intYear)))
		return false;

    return true;
}


function checkDate (yearField, monthField, dayField, labelString, OKtoOmitDay)
{
    if (checkDate.arguments.length == 4)
		OKtoOmitDay = false;
    if (!isYear(yearField))
	{
		alert ('Please enter a valid year in the ' + labelString + ' field.');
		return false;
	}
    if (!isMonth(monthField))
	{
		alert ('Please enter a valid month in the ' + labelString + ' field.');
		return (false);
	}
    if ( (OKtoOmitDay == true) && isEmpty(dayField) )
		return true;
    else if (!isDay(dayField)) 
	{
		alert ('Please enter a valid day in the ' + labelString + ' field.');
		return false;
	}
    if ( isDate(yearField, monthField, dayField))
       return true;

	// error message
    alert (iDatePrefix + labelString + iDateSuffix)
    return false;
}


function validateDate (givenDate, labelString)
{
	var i;
	var yearField, monthField, dayField;
	var validDate;

	dateElements = givenDate.value.split('/');
	if (dateElements.length < 3)
	{
		alert ('Please enter day, month and year for the "'
					+ labelString + '" field.');
		givenDate.select();
		givenDate.focus();
		return (false);
	}

	validDate = checkDate (dateElements [2], dateElements [1], dateElements [0],
							labelString);
	if (!validDate)
	{
		givenDate.select();
		givenDate.focus();
		return false;
	}

	return true;
}

//**********Email validation is now added *************//
/***********************************************
Purpose	:	To verify the Email format.
***********************************************/
var whitespace="\t\n\r";

function isEmpty(s)
   {
     return((s==null) ||(s.length==0))
   }


function isWhitespace(s)
  {
    var i;
    if(isEmpty(s))
    return true;
    for(i=0;i<s.length;i++)
       {
         //Check that current character isn't whitespace
         var c=s.charAt(i);
         if(whitespace.indexOf(c)==-1)
         return false;
       }

//All characters are whitespace
return true;


}
/*
function isEmail(s)
{
 if(isEmpty(s))
 if(isEmail.arguments.length==1)
  return defaultEmptyOK;
 else
 return (isEmail.arguments[1]==true);
 
 if(isWhitespace(s))
  return false;

//there must be >=1 character before @, so start looking at characters
//posiion 1(ie second character)
var i=1;
slength=s.length
while( ( i<slength) && (s.charAt(i) != "@") )
{
 i++;
}

if( (i >=  s.length) || (s.charAt(i)!= "@"))
  return false;
 else i+=2;
 

while( ( i<slength) && (s.charAt(i) != ".") )
{
 i++;
}


if( (i >=  s.length-1) || (s.charAt(i)!= "."))
  return false;
 else return true;
 }

*/
function checkcookie()
{
  part = document.cookie;
  ind = part.indexOf("userlogin");
  if (ind == -1)
     location.replace("error.html");
  else
  {
   start = part.indexOf("=",ind);
   if (start == -1)
     location.replace("error.html");
   theval = part.substr(start+1,6);
   if (theval!="caught")
     location.replace("error.html");
  }	

}

//onkeypress="allow_alpha_num_only(event,this)"
//add the above code in text boxes whereever required.
function allow_alpha_num_only(event,obj) {
if (navigator.appName != 'Netscape')
{
	if(event.keyCode ==13)
	{
		event.returnValue=true
		return
	}
	if(obj.value.length == 0)
	{
		if ((event.keyCode < 48) ||  (event.keyCode >57 & event.keyCode <65) || (event.keyCode >90 & event.keyCode <97) || (event.keyCode >122))
		{
			//setborder(obj)
			window.status="Special character and Spaces are not allowed as first character"
			event.returnValue=false
		}
		else
		{
			event.returnValue=true
		}
	}
	if(obj.value.length >0 )
	{
		if(!checkSpecial(obj.value.charAt(0)))
		{
			obj.value=""
			//setborder(obj)
			window.status="Special character and Spaces are not allowed as first character"
			event.returnValue=false
		}
	}
}
}
//onkeypress="allow_alpha_only(event,this)"
//add the above code in text boxes whereever required.
function allow_alpha_only(event,obj) {
if (navigator.appName != 'Netscape')
{
	if(event.keyCode ==13)
	{
		event.returnValue=true
		return
	}
	if(obj.value.length == 0)
	{
		if ((event.keyCode >64 & event.keyCode <91) ||  (event.keyCode >96 & event.keyCode <123) || (event.keyCode >90 & event.keyCode <97))
		{
			event.returnValue=true
		}
		else
		{
			//setborder(obj)
			obj.value=""
			
			window.status="Special character, Number and Spaces are not allowed as first character"
			event.returnValue=false
			
		}
	}
	if(obj.value.length >0 )
	{
		if(!isNaN(obj.value))
		{
			obj.value=""
			//setborder(obj)
			window.status="Special character, Number and Spaces are not allowed as first character"
			event.returnValue=false
		}
		if(!checkSpecial(obj.value.charAt(0)))
		{
			obj.value=""
			//setborder(obj)
			window.status="Special character, Number and Spaces are not allowed as first character"
			event.returnValue=false
		}
	}
}
}
/***********************************************
Purpose	:	Function for trimming left most spaces in the string
***********************************************/
function rtrim(s)
{
	var i;
	var j=0;
	instringlength=s.length;
	for(i=instringlength-1;i>=0;i--)
	{
		if(s.charAt(i)!=' ')
		{	J=1;
			break;
		}
	}
	return s.substring(0,i);
}
function allow_ccnum_only(event,obj) 
{
	if(event.keyCode ==13)
	{
		event.returnValue=true
		return
	}

	if (event.keyCode > 47  & event.keyCode <58 ) 
	{
		event.returnValue=true
	}
	else
	{
		//setborder(obj)
		window.status="Only Number is allowed."
		event.returnValue=false
	}
}

function clearborder(obj)
{
	obj.style.borderBottom="black thin ridge"
	obj.style.borderRight="black thin ridge"
	obj.style.borderLeft="black thin ridge"
	obj.style.borderTop="black thin ridge"
}
function setborder(obj)
{
	obj.style.borderBottom="red thin double"
	obj.style.borderRight="red thin double"
	obj.style.borderLeft="red thin double"
	obj.style.borderTop="red thin double"
}

function clearall(obj)
{
	 var formelement=obj.elements
	 window.status="none"
	 for(i=0;i< obj.elements.length;i++)
	 {
		if(formelement[i].type=="text" || formelement[i].type=="password")
		{
			clearborder(formelement[i])
		}
	 }
}

function validatefirstchar(obj)
{
	 var formelement=obj.elements
	 for(llll=0;llll< obj.elements.length;llll++)
	 {
		if(formelement[llll].type=="text")
		{
			if(!checkTeleSpecial(formelement[llll].value.charAt(0)))
			{
				//setborder(formelement[llll])
				alert("Special character,Spaces are not allowed as first character")
				formelement[llll].focus();
				return false;
			}

		}
	 }
	 return true;
}


//onkeypress="allow_tele_num_only(event,this)"
//add the above code in text boxes whereever required.
//add the above code use to enter telephone number

function allow_tele_num_only(event,obj) {
	if(event.keyCode ==13)
	{
		event.returnValue=true
		return
	}
	if(obj.value.length == 0)
	{
		if ((event.keyCode != 43) && (event.keyCode < 48) ||  (event.keyCode >57 & event.keyCode <65) || (event.keyCode >90 & event.keyCode <97) || (event.keyCode >122))
		{
			//setborder(obj)
			window.status="Special character and Spaces are not allowed as first character"
			event.returnValue=false
		}
		else
		{
			event.returnValue=true
		}
	}
	if(obj.value.length >0 )
	{
		if(!checkTeleSpecial(obj.value.charAt(0)))
		{
			obj.value=""
			//setborder(obj)
			window.status="Special character and Spaces are not allowed as first character"
			event.returnValue=false
		}
	}
}

//used to allow + as a first charactor in telephone

function checkTeleSpecial(s)
{
	checkfor=" ~!@#$%^&*()_=-{}[]`|\\\"\'\:\;<>,.?/";
	flag=true;
	for(i=0;i<s.length;i++)
	{
		// take the first character
		var c=s.charAt(i);
		if(checkfor.indexOf(c)== -1)
		{  
			flag=true;
		}
		else
		{
			flag=false;
			break;
		}
	}
	//No white space in between
	if(i>=s.length)
		flag= true;
	else
		flag=false;
	return flag;
}

//*********************************8
//function used for credit card validation
//input parameter ccard value
//output true or false

function ccCheck(ccnumber)
{
if(isNaN(ccnumber))
	return false;
else
	{
	if(ccnumber==0)
		return false;
	}

var ccno,cclength,s2,s3,mr,q,isvalid;
ccno=ccnumber;
cclength=ccno.length;


if(cclength == 0)
{
	return isvalid;
}
s2="";
s3=0;
mr="1";
q="";
isvalid=false;//whether card is valid 
for(x=cclength-1;x>=0;x--) 
{
	q=ccno.substring(x,x+1); 
	s2=s2+q*mr;
	mr=((mr==1)?2:1);
}

for(x=s2.length-1;x>=0;x--)
	{
	s3=s3+eval(s2.charAt(x));
	}
	isvalid=(s3%10);
	isvalid=((isvalid==0)?true:false);
	return isvalid;

}

//To check whether the first character is Special character and Number
function validateNetfirstchar(obj)
{	
	var s=obj.value;
	if((!checkSpecial(s.charAt(0))) || (!isNaN(s.charAt(0))))
		{
		//setborder(formelement[llll])
		alert("Special character,Spaces and Numbers are not allowed as first character");
		obj.focus();
		return false;
		}

	else
		return true;
	
}


function validatefirstsplchar(obj)
{	
	var s=obj.value;
	if(!checkSpecial(s.charAt(0)))
		{
		alert("Special character,Spaces are not allowed as first character");
		obj.focus();
		return false;
		}

	else
		return true;
	
}

function checknetTeleSpecial(s)
{
	checkfor=" ~!@#$%^&*()_=-{}[]`|\\\"\'\:\;<>,.?/";
	flag=true;
	var c=s.charAt(0);
		if(checkfor.indexOf(c)== -1)
		{  
			flag=false;
			
		}
		else
		{
			flag=true;
			
		}
		
	return flag;
}

/*date functions added by hari hara sudhan */
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth()	+ numMonths;
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	
	return returnDate;

}
function YearAdd(startDate, numYears)
{
		return DateAdd(startDate,0,0,numYears);
}
function MonthAdd(startDate, numMonths)
{
		return DateAdd(startDate,0,numMonths,0);
}

function DayAdd(startDate, numDays)
{
		return DateAdd(startDate,numDays,0,0);
}
