ie=document.all?1:0;
function call_module(module)
{
	alert(module);
}

function toLower(fm,fld)
{
	eval('document.'+fm+'.'+fld+'.value=document.'+fm+'.'+fld+'.value.toLowerCase()');
}
function check_form(){

	if (document.user.username.value == ""){
		alert("Please enter your user name.");	
		document.user.username.focus();
	}

	else if (document.user.password.value == ""){
		document.user.username.value=document.user.username.value.toLowerCase();
		alert("Please enter your password.");	
		document.user.password.focus();
	}	        

	else {
		document.user.method="post";
		document.user.action="index.php?mode=login";
		document.user.submit();
	}

}

function register_form(){
        if (document.Register.keycode.value == ""){
                alert("Please enter your Key Code.");
                document.Register.keycode.focus();
        }
		else if (document.Register.usertype.selectedIndex == 0){
                alert("Please select user type.");
                document.Register.usertype.focus();
        }
		else if (document.Register.username.value == ""){
                alert("Please enter user name.");
                document.Register.username.focus();
        }
		else if(document.Register.username.value != "" && check_spl(document.Register.username.value))
		{
			alert("User name can contain only alphanumeric and '_' characters.");
			document.Register.username.select();
		}
        else if (document.Register.password.value == ""){
                alert("Please enter password.");
                document.Register.password.focus();
        }
        else if (document.Register.cpassword.value == ""){
                alert("Please re-type the password.");
                document.Register.cpassword.focus();
        }
        else if (document.Register.password.value != document.Register.cpassword.value)
		{
		alert("Please enter correct password.");	
		document.Register.password.select();
	    }
        else if (document.Register.mailid.value == ""){
                alert("Please enter Email.");
                document.Register.mailid.focus();
        }
		else if(document.Register.mailid.value!="" && !eMail(document.Register.mailid.value)){
                alert("Please enter valid Email.");
                document.Register.mailid.select();
        }
        else {
                document.Register.method="post";
                document.Register.action="index.php?mode=login";
                document.Register.submit();
        }

}

function check_spl(txt)
{
	var spl_char=0;
	var valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	for(var i=0;i<txt.length;i++)
	{
		if(valid.indexOf(txt.charAt(i)) < 0)
		{
			spl_char=1;		
			break;
		}	
		else
			continue;
	}
	
	if(spl_char==1)
		return true;
	else
		return false;
}
function change_mailid(){

        if (document.Chmail.newemail.value == ""){
                alert("Please enter new Email.");
                document.Chmail.newemail.focus();
        }
	else if(document.Chmail.newemail.value!="" && !eMail(document.Chmail.newemail.value)){
                alert("Please enter valid Email.");
                document.Chmail.newemail.select();
	}
        else {
                document.Chmail.method="post";
                document.Chmail.submit();
        }

}
function forgotpwd_form(){

        if (document.Register.keycode.value == ""){
                alert("Please enter your Key Code.");
                document.Register.keycode.focus();
        }
        else {
                document.Register.method="post";
                document.Register.action="index.php?mode=forgotpwd";
                document.Register.submit();
        }

}

function forgot_password()
{
	if(document.usermail.mailid.value=="")
	{
		alert("Please enter your Email.");
		document.usermail.mailid.focus();
	}
	else if(document.usermail.mailid.value!="" && !eMail(document.usermail.mailid.value))
	{
		alert("Please enter valid Email.");
		document.usermail.mailid.focus();
		document.usermail.mailid.select();
	}
	else
	{
		document.user.method="post";
		document.usermail.action="index.php?mode=forgot_password";
		document.usermail.submit();
	}	
}

function eMail(emailStr) 
{
	  
	var result = false
	var theStr = new String(emailStr)
	var index = theStr.indexOf("@");
	if (index > 0)
	{
	   var pindex = theStr.indexOf(".",index);
	   if ((pindex > index+1) && (theStr.length > pindex+1))
	  	result = true;
	}
	return result;
}

function validate_sample_test_login(){
	if (document.sampletest.firstname.value == ""){
		alert("Please type your first name.");
		document.sampletest.firstname.focus();

	}
	else if (document.sampletest.lastname.value == ""){
		alert("Please type your last name.");
		document.sampletest.lastname.focus();

	}
	else if(document.sampletest.email.value=="")
	{
		alert("Please enter  Email.");
		document.sampletest.email.focus();
	}
	else if(document.sampletest.email.value!="" && !eMail(document.sampletest.email.value))
	{
	   alert("Please enter a valid Email.");
	   document.sampletest.email.focus();
	   document.sampletest.email.select();
	}  
	else 
	{
		document.sampletest.action="index.php?mode1=sample_test";
		document.sampletest.submit();
	}
}


function choose_tech(tech)
{
	if(tech=="Java" || tech=="CPlus")
		eval('document.location.href="index.php?mode=class_room&mode1='+tech+'101&mode2=welcome"');
	else
		alert('At present, only the Java class is in progress.');
}


ie=document.all?1:0;
var lp_win;
var ns_win;
var lp_win_options;
var ns_win_options;
var w=screen.width;
var h=screen.height;
var l=(w-600)/2;
var t=(h-500)/2;

var ll=(w-300)/2;
var tt=(h-300)/2;

eval('lp_win_options="menubar=no,statusbar=no,scrollbars=yes,left='+l+',top='+t+',width=600,height=500"');

function open_lp()
{
	if (lp_win && lp_win.open && !lp_win.closed)
		lp_win.focus();
	else
		eval('lp_win=window.open("lp.html","LearningPath",lp_win_options)');
}

function open_ens(folder)
{
	if (ns_win && ns_win.open && !ns_win.closed)
		ns_win.focus();
	else
		eval('ns_win=window.open("'+folder+'/get_eknap.php","eKnapsack",lp_win_options)');
}

var MockTest;
//var wt=screen.width-50;
//var ht=screen.height-75;

var wt,ht,lt,tt;
if(ie)
{
	wt=500;
	ht=400;
	lt=(screen.width-500)/2;
	tt=(screen.hight-400)/2;
}	
else
{
	wt=screen.width-50;
	ht=screen.height-80;
	lt=20;
	tt=20;
}
function LoadMT(technology,testid)
{

   /*var installed=InsCodeSaw();
   if(installed)
   {
   eval('MockTestoptions = "resizeable=yes,directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width='+wt+',left='+lt+',top=20,height='+ht+'"');
    if(MockTest && MockTest.open && !MockTest.closed)
        MockTest.focus();
    else
        eval('MockTest=window.open("include/test_validation.php?mode='+technology+'&testid='+testid+'&configPath=/var/jakarta-tomcat-3.2.4/webapps/examples/jsp/thomson/config.internet.inc.php","MT",MockTestoptions)');
  }
  else
  {
	var x=confirm("CodeSaw could not be detected on your machine. \n\nClick OK to install CodeSaw.");
	if(x)
		{
			var url = document.location.href;
			var start = url.indexOf("\/\/");
			url = url.substring(start+2);
			var end = url.indexOf("\/");
			var ip = url.substring(0,end);
			document.location.href="http://"+ip+"/install/Code_Saw_Setup.exe";
		}
  } */

   eval('MockTestoptions = "resizeable=yes,directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width='+wt+',left='+lt+',top=20,height='+ht+'"');
    if(MockTest && MockTest.open && !MockTest.closed)
        MockTest.focus();
    else
        eval('MockTest=window.open("include/test_validation.php?mode='+technology+'&testid='+testid+'&configPath=/var/jakarta-tomcat-3.2.4/webapps/examples/jsp/thomson/config.internet.inc.php","MT",MockTestoptions)');

}


var help_win;
var wh=screen.width-150;
var hh=screen.height-150;
var lh=75;
var th="50";
var helpfile="";
function LoadHelp(opt,book)
{
	
	if(book=='java' || book=='cpp')
	{
		if(opt=="common")
			helpfile="help/help.html";
		else
			helpfile="../help/help.html";

	}	
	else
	{
		if(opt=="common")
			helpfile="help/help_book.html";
		else
			helpfile="../help/help_book.html";
	}
    eval('Helpoptions = "directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width='+wh+',left='+lh+',top=30,height='+hh+'"'); 
    if(help_win && help_win.open && !help_win.closed)
        help_win.focus();
    else
        eval('help_win=window.open(helpfile,"Help",Helpoptions)');
}

function test_login_validate()
{
	if(document.Test.password.value=="")
	{
		alert("Enter your password.");
		document.Test.password.focus();
	}
	else if(document.Test.insmailid.value!="" && !eMail(document.Test.insmailid.value))
	{
		alert("Enter valid Email.");
		document.Test.insmailid.select();
	}
	else
	{
		document.Test.method="post";
		document.Test.submit();
	}
}
var pdv_flag=0;
var pdv_win;
var f=0;
var s_no=1;
var ss_option=0;
function change_s_no(s,o)
{
	ss_option=o;
	s_no=s;
	if(o==0)	chapter_index=existing_chapters[o];
	else	chapter_index=o;
}
function call_pdv()
{
	if(ie)
	{
		if(ss_option==0)
			pdv_win=window.open(pdv_url_out,"PDV",pdv_win_options);	
		else
			pdv_win=window.open(pdv_url_in,"PDV",pdv_win_options);				
		pdv_win.focus();	
	}
	else
	{
		if(navigator.appVersion.indexOf("5.0")>=0)
			return;	
		if(pdv_win && pdv_win.open && !pdv_win.closed)	
		{
			f=1;
			if(ss_option==0)
				pdv_win=window.open(pdv_url_out,"PDV",pdv_win_options);	
			else
				pdv_win=window.open(pdv_url_in,"PDV",pdv_win_options);	
			pdv_win.focus();	
		}	
		else
		{
			if(ss_option==0)
				pdv_win=window.open(pdv_url_out,"PDV",pdv_win_options);	
			else
				pdv_win=window.open(pdv_url_in,"PDV",pdv_win_options);	
			f=0;
				setTimeout("call_temp_pdv()",500);	
		}	
		
	}		
}

function call_temp_pdv()
{
	pdv_win.close();
	call_pdv();
}

var mm_url;
function call_mindmap()
{
	eval('mm_url="le_obj_main.html"');
	if (mm_win && mm_win.open && !mm_win.closed)	
		mm_win.focus();
	else
		mm_win=window.open(mm_url,"MindMap",mm_win_options);	
}

var quiz_url;
var temp_c;
var quiz_exist=0;
var temp_ql;
var location_url;
function call_quiz()
{
	if(quiz_win && quiz_win.open && !quiz_win.closed)
	{
		quiz_win.close();
		eval('quiz_win=window.open("quiz_main.html","Quiz",quiz_win_options)');
	}	
	else
		eval('quiz_win=window.open("quiz_main.html","Quiz",quiz_win_options)');			
}


var cns_win;
var cns_win_options;
var w=screen.width;
var h=screen.height;	
var ll=(w-850)/2;
var tt=(h-500)/2;
	 
eval('cns_win_options="menubar=no,statusbar=no,scrollbars=yes,left='+ll+',top='+tt+',width=850,height=500"');
	
function call_eknapsack(option)
{
	if(option=="course")
	{
		if (cns_win && cns_win.open && !cns_win.closed)	
			cns_win.focus();
		else
			eval('cns_win=window.open("../eknapsack/get_eknap.php?option=course","eKnapsack",cns_win_options)');
	}
	else
	{
		if (cns_win && cns_win.open && !cns_win.closed)	
				cns_win.focus();
		else
			eval('cns_win=window.open("eknapsack/get_eknap.php?option=common","eKnapsack",cns_win_options)');
	}
	
}

function change_pwd()
{
	if(document.ChangePwd.oldpwd.value=="")
	{
		alert("Enter your old password.");
		document.ChangePwd.oldpwd.focus();
	}	
	else if(document.ChangePwd.newpwd.value=="")	
	{
		alert("Enter your new password.");
		document.ChangePwd.newpwd.focus();
	}	
	else if(document.ChangePwd.rnewpwd.value=="")	
	{
		alert("Retype your new password.");
		document.ChangePwd.rnewpwd.focus();
	}	
	else if(document.ChangePwd.newpwd.value!=document.ChangePwd.rnewpwd.value)
	{
		alert("Enter the correct password.");
		document.ChangePwd.newpwd.select();
	}	
	else
	{		
		document.ChangePwd.method="post";
		document.ChangePwd.action="myprofile.php";
		document.ChangePwd.submit();
	}	
}
function send_mail()
{
	if(document.Score.insmail.value=="")
	{
		alert("Enter your Instructor's Email.");
		document.Score.insmail.focus();
	}	
	else if(document.Score.insmail.value!="" && !eMail(document.Score.insmail.value))
	{
	   	alert("Please enter a valid Email.");
	   	document.Score.insmail.select();
	}  
	else
		document.Score.submit();		
}

function contact_us()
{
	if(document.comment.email.value=="")
	{
		alert("Enter your Email.");
		document.comment.email.focus();
	}	
	else if(document.comment.email.value!="" && !eMail(document.comment.email.value))
	{
		alert("Please enter a valid Email.");
		document.comment.email.select();
	}
	else if(document.comment.remarks.value=="")
	{
		alert("Please enter your comments.");
		document.comment.remarks.focus();
	}
	else
		document.comment.submit();
	
}	


function InsCodeSaw()
{	
        var mime_avail;
	if(ie)
	{
		mime_avail=detect_plugin();
	}
	else
	{
		for(var m=0;m<navigator.mimeTypes.length;m++)
		{
			if(navigator.mimeTypes[m].type=="application/x-codesaw")
			{
				mime_avail=true;
				break;
			} 
			else 
			{
					
				mime_avail=false;
				continue;
			}
    		}
	}
	return mime_avail;
}

function close_child_windows(option)
{
	if(option=="course")
	{
		if(parent.frames["Tabs"].cns_win && parent.frames["Tabs"].cns_win.open && !parent.frames["Tabs"].cns_win.closed)
			parent.frames["Tabs"].cns_win.close();
		if(parent.frames["Tabs"].pdv_win && parent.frames["Tabs"].pdv_win.open && !parent.frames["Tabs"].pdv_win.closed)
			parent.frames["Tabs"].pdv_win.close();
		if(parent.frames["Tabs"].mm_win && parent.frames["Tabs"].mm_win.open && !parent.frames["Tabs"].mm_win.closed)
			parent.frames["Tabs"].mm_win.close();
		if(parent.frames["Tabs"].quiz_win && parent.frames["Tabs"].quiz_win.open && !parent.frames["Tabs"].quiz_win.closed)
			parent.frames["Tabs"].quiz_win.close();
		if(help_win && help_win.open && !help_win.closed)
			help_win.close();
		parent.document.location.href="../index.php?mode=logout";
	}
	else
	{
		if(cns_win && cns_win.open && !cns_win.closed)
			cns_win.close();
		if(MockTest && MockTest.open && !MockTest.closed)
			MockTest.close();			
		document.location.href="index.php?mode=logout";
	}
}

function window_resize()
{
	if(ie)
	{
		window.resizeTo(screen.width-40,screen.height-50);
		window.moveTo(20,20);
	}	
	else
	{
		/*netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
		window.moveTo(20,20);	
		window.outerWidth=500;
		window.outerHeight=400;*/
		
	}	
}

function save_inst_info()
{
	if(document.InsInfo.insmailid.value=="")
	{
		alert("Enter Instructor's Email.");
		document.InsInfo.insmailid.focus();
	}	
	else if(document.InsInfo.insmailid.value!="" && !eMail(document.InsInfo.insmailid.value))
	{
		alert("Please enter a valid Email.");
		document.InsInfo.insmailid.select();
	}
	else
		document.InsInfo.submit();
}

function image_over(im_name)
{	
	eval('document.'+im_name+'.src="../lm_images/'+im_name+'_over.jpg"');  
}
function image_out(im_name)
{
 	eval('document.'+im_name+'.src="../lm_images/'+im_name+'_normal.jpg"');   
}

window.onback=history.forward();

var ypos=0;
document.onmousemove = getMousepos;

var val_win;
function validate_user(selected_user)
{
	var val_win_options;
	var w=screen.width;
	var h=screen.height;
	var ll=(w-350)/2;
	var tt=(h-150)/2;
	eval('val_win_options="menubar=no,statusbar=no,scrollbars=no,left='+ll+',top='+tt+',width=350,height=200"');
	
	if(document.forms[1].usertype.selectedIndex==0)
	{
		if (val_win && val_win.open && !val_win.closed)
			val_win.close();
	}
	else
	{
		if (val_win && val_win.open && !val_win.closed)
		{
				eval('val_win=window.open("include/user_type.php?usertype='+selected_user+'","UserType",val_win_options)');
				val_win.focus();
		}
		else
		{
			eval('val_win=window.open("include/user_type.php?usertype='+selected_user+'","UserType",val_win_options)');
			val_win.focus();
		}
	}
	//eval('window.showModalDialog("include/user_type.php?usertype='+selected_user+'")');
}

function validate_usertype(user_type)
{
	if(user_type=='st')
	{
		if(document.forms[0].ins_email.value=='')
		{
			alert("Please enter Email.");
			document.forms[0].ins_email.focus();
		}
		else
		{
			if(!eMail(document.forms[0].ins_email.value))
			{
				alert("Please enter valid Email.");
				document.forms[0].ins_email.select();
			}
			else 
				document.forms[0].submit();
		}
	}
	else
	{
		if(document.forms[0].sales_rep.value=='')
		{
			alert("Please enter Email.");
			document.forms[0].sales_rep.focus();
		}
		else
		{
			if(!eMail(document.forms[0].sales_rep.value))
			{
				alert("Please enter valid Email.");
				document.forms[0].sales_rep.select();
			}
			else 
				document.forms[0].submit();
		}
	}
}

function getMousepos(e)
{
	ypos=window.event.y+120;
}

function kill_user_type_win()
{
	if(val_win && val_win.open && !val_win.closed)
			val_win.close();
}
