// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

/**Alva add for timezone hidden**/
  function hiddenZone(evt)
	{  
	     evt = evt ? evt : (window.event ? window.event : null);
	    
	     var _target=evt.srcElement?evt.srcElement:evt.target;
	     
		var _id= _target.id || _target.parentNode.id; 
		//getAttribute is no meanning,but help to work on Netscape,in that the _id is undefined
	    //_target.parentNode.id just for netscape
			//var _temp=_target.getAttribute("id");
		 
	    //hard code for timezone. 
	   if(_id=="oneZone"||_id=="timezoneLink"||_id=="timezoneList"||_id=="oneZoneHref")
	   { 
	      
	   }else
	   { 
	      if(document.getElementById("timezoneList").style.visibility == "hidden")  
	       {
	       }
	       else
	      {
	        document.getElementById("timezoneList").style.visibility = "hidden"; 
	      }   
	   }
	}
	
	
function AtTrim(s)
{
	var r1, r2, s1, s2, s3;

    r1 = new RegExp("^ *");
    r2 = new RegExp(" *$");

    s1 = ""+s+"";
    s2 = s1.replace(r1, "");
    s3 = s2.replace(r2, "");
    
    r1 = null;
    r2 = null;

    return(s3);
}

function CheckInput()
{
	document.Logon.UserName.value = AtTrim(document.Logon.UserName.value);
//	var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");
    var rx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

	if (document.Logon.UserName.value != "" ||
		document.Logon.Password.value != "" ||
		document.Logon.WebExURL.value != "")
	{
		if(document.Logon.UserName.value=="")
		{
			alert("Please enter your WebEx User Name.");
			document.Logon.UserName.focus();
			return false;	
		}
	
		/*
		if(rx.test(document.Logon.UserName.value)  && document.Logon.WebExURL.value == "")
		{
			alert("This looks like a Training ID. \nWill logon as Training ID.");
			//document.Logon.TrainingName.value = document.Logon.UserName.value;
			document.Logon.UserName.value = "";
			//document.Logon.TrainingPassword.value = document.Logon.Password.value;
			document.Logon.Password.value = "";
			//document.Logon.TrainingName.focus();
			return false;
		}
		*/

		if(document.Logon.Password.value=="")
		{
			alert("Please enter your Password.")
			document.Logon.Password.focus();
			return false;	
		}
    
		if(document.Logon.WebExURL.value=="")
		{
			alert("Please enter your WebEx URL.")
			document.Logon.WebExURL.focus();
			return false;	
		}
		
		if(document.Logon.WebExURL.value.indexOf(".com",0) == -1) 
		{
			alert("Please enter the full WebEx URL.  (e.g. - mycompany.webex.com)")
			document.Logon.WebExURL.focus();
			return false;	
		}
	}	

	if (document.Logon.UserName.value == "")
	{
		//alert("Please enter either your WebEx User ID or your Training ID which is your corporate email.")
		alert("Please enter your WebEx User Name.");
		document.Logon.UserName.focus();
		return false;	
	}

	if((document.Logon.WebExURL.value.indexOf("http://",0) != -1) ||
	   (document.Logon.WebExURL.value.indexOf("https://",0) != -1) ) 
	{
		alert("http or https should not be in your WebEx URL. Example: mycompany.webex.com")
		document.Logon.WebExURL.focus();
		return false;	
	}

	if((document.Logon.WebExURL.value.indexOf("www.",0) != -1)
            && document.Logon.WebExURL.value.indexOf("www.webex.",0) != 0)
	{
		alert("Your WebEx URL should not start with www. Example: mycompany.webex.com")
		document.Logon.WebExURL.focus();
		return false;	
	}
	//document.Logon.TrainingName.value = document.Logon.UserName.value;
    return true;
}

function CheckInputForLogin()
{
	document.studentLoginForm.userName.value = AtTrim(document.studentLoginForm.userName.value);

    var rx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

	if (document.studentLoginForm.userName.value != "" ||
		document.studentLoginForm.password.value != "" ||
		document.studentLoginForm.webexURL.value != "")
	{
		if(document.studentLoginForm.userName.value=="")
		{
			alert("Please enter your WebEx User Name.");
			document.studentLoginForm.userName.focus();
			return false;	
		}

		if(document.studentLoginForm.password.value=="")
		{
			alert("Please enter your Password.")
			document.studentLoginForm.password.focus();
			return false;	
		}
    
		if(document.studentLoginForm.webexURL.value=="")
		{
			alert("Please enter your WebEx URL.")
			document.studentLoginForm.webexURL.focus();
			return false;	
		}
		
		if(document.studentLoginForm.webexURL.value.indexOf(".com",0) == -1) 
		{
			alert("Please enter the full WebEx URL.  (e.g. - mycompany.webex.com)")
			document.studentLoginForm.webexURL.focus();
			return false;	
		}
	}	

	if (document.studentLoginForm.userName.value == "")
	{
		//alert("Please enter either your WebEx User ID or your Training ID which is your corporate email.")
		alert("Please enter your WebEx User Name.");
		document.studentLoginForm.userName.focus();
		return false;	
	}

	if((document.studentLoginForm.webexURL.value.indexOf("http://",0) != -1) ||
	   (document.studentLoginForm.webexURL.value.indexOf("https://",0) != -1) ) 
	{
		alert("http or https should not be in your WebEx URL. Example: mycompany.webex.com")
		document.studentLoginForm.webexURL.focus();
		return false;	
	}

	if((document.studentLoginForm.webexURL.value.indexOf("www.",0) != -1)
            && document.studentLoginForm.webexURL.value.indexOf("www.webex.",0) != 0)
	{
		alert("Your WebEx URL should not start with www. Example: mycompany.webex.com")
		document.studentLoginForm.webexURL.focus();
		return false;	
	}
	//document.studentLoginForm.TrainingName.value = document.studentLoginForm.UserName.value;
    return true;
}

function WarningInfo(strurl,strinfo)
{
	var ret = confirm(strinfo);
 	if (ret == true)
	{
		top.location.replace(strurl)
		return true;
	}
} 

function Back() 
{
	location.href="Javascript:history.go(-1)";
}

function Register(form,urlval)
{
	if(CheckSelecte(form, true) == true)
	{
		var ret = confirm("Are you sure you want to register for the selected session?");
	 	if (ret == true)
		{
			form.action=urlval
			form.submit();
			return true;
		}
	}
	else
	{
		alert("Select a session time option.");
	}
	return false;
} 

function WarningInfo(form,strurl,strinfo)
{
	var ret = confirm(strinfo);
 	if (ret == true)
	{
		form.action = strurl;
		form.submit();
		return true;
	}
	else
		return false;
} 

function Change(form,urlval)
{
	form.action = urlval;
	form.submit();
}

function CheckSelecte(FormName,checked) 
{	
 	len = FormName.elements.length;
 	var i=0;
	for( i=0; i < len; i++) 
	{
		if (FormName.elements[i].name== 'ClassScheduleID') 
		{
			if(FormName.elements[i].checked==checked)
			return true;
		}
	} 
	return false;
}

function autoResize()
{
   	try
    {       
        if(dom){
            document.getElementById("contentFrame").style.height= contentFrame.document.body.scrollHeight;       
		//	alert("DOM : contentFrame height=" + contentFrame.document.body.scrollHeight);
        }		
		else if(ie4){
            document.all["contentFrame"].style.height=contentFrame.document.body.scrollHeight;   
		//	alert("IE 4 : contentFrame height=" + contentFrame.document.body.scrollHeight);
        }
        else if(nn4){
            document.layers["contentFrame"].style.height=contentFrame.document.body.scrollHeight;   
		//	alert("nn4 layers : contentFrame height=" + contentFrame.document.body.scrollHeight);
        }
		parent.mainFrame.scrollTo(0,0);
    }
    catch(e){  //the alert was scaring customers with "Object error", though it was still working.
		  //alert(e);
	}
}

//for later use, if need to get to top frame without using top variable
function getTop() {
	if (parent != null)
	{
		if (parent.location.href.indexOf("university.webex.com") > -1 || parent.location.href.indexOf("ossotr") > -1)
		{
			if ((parent.parent != null) && (parent.parent.location.href.indexOf("university.webex.com") > -1 || parent.parent.location.href.indexOf("ossotr") > -1))
			{
				return parent.parent;
			} else return parent;
		}  return parent;
	} else return top;
}
	

function refreshMainFrame(url){	
	try
	{
        top.mainFrame.location.href = url;
    }
    catch(e){
	    top.location.href = url;
	}
}

function refreshMainFrame_new(url){	
	try
	{
        window.location.href = url;
    }
    catch(e){
	}
}

function login(){
    refreshMainFrame("../frame/Login.jsp");
}

function welcome(){
    refreshMainFrame("welcome.jsp");
}

function welcome_new()
{
    refreshMainFrame_new("../content/welcome.jsp");
}

function loginTo(LandURL){
    refreshMainFrame("../frame/Login.jsp?LandURL="+LandURL);
}

function wbtlogin(PopupURL){
    //props=window.open('../content/studentlogin.jsp?LandURL=../frame/TrainingList.jsp&PopupURL='+PopupURL, 'poppage', 'toolbars=0,scrollbars=0,location=0,statusbars=0,menubars=1,resizable=1,width=750,height=490');
    refreshMainFrame("../frame/Login.jsp?LoginAction=WBT&PopupURL="+PopupURL);
}

function courseLogin(CourseID){
    refreshMainFrame("../frame/Login.jsp?LoginAction=ClassReg&CourseID="+CourseID);
}

function refreshOpener(url){	
	try
	{
        opener.top.mainFrame.location.href = url;
    }
    catch(e){
	    opener.top.location.href = url;
	}
}