var xmlHttp;
var usr;
var win_nusr;
var win_nusr_dlg;
var win_p_usr;
var win_p_usr_dlg;
var win_p_rst_usr;
var win_p_rst_usr_dlg;
var win_sup_usr;
var win_sup_usr_dlg;

var def_focus_fld;

var win_nusr_htm = "<p>&nbsp;</p>";
var win_nusr_dlg_htm = "<p>&nbsp;</p>";
var win_p_usr_htm = "<p>&nbsp;</p>";
var win_p_usr_dlg_htm = "<p>&nbsp;</p>";
var win_p_rst_usr_htm = "<p>&nbsp;</p>";
var win_p_rst_usr_dlg_htm = "<p>&nbsp;</p>";
var win_sup_usr_htm = "<p>&nbsp;</p>";
var win_sup_usr_dlg_htm = "<p>&nbsp;</p>";
var active = false;

function set_active () {
	active = true;
}

function onhover (obj) 
	{
		if (obj.className.length < 3) {
			obj.className =obj.className + '-hl';
		} else if (obj.className.substr(obj.className.length - 3, 3) == '-hl') {
			obj.className = obj.className.substr(0, obj.className.length - 3);
		} else {
			obj.className =obj.className + '-hl';
		}
	}
		
function ajaxFunction()	{
	try
  		{  // Firefox, Opera 8.0+, Safari  
			xmlHttp=new XMLHttpRequest(); 
		}
	catch (e)
		{  // Internet Explorer  
		try
			{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.6.0");    }
		catch (e) {	
			try
				{    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
			catch (e)
				{    
				try
					{     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
				catch (e)
					{      
						alert("Your browser does not support AJAX!");      
						return false;      
					}    
				}  
			}
		}
  }

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return curtop;
	}
}

function set_doc_size_new () {
	var _docHeight = (document.height || document.body.offsetHeight);

	var offset = 0;
	var viewportwidth;
 	var viewportheight;
 	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 	if (typeof window.innerWidth != 'undefined'){
      viewportwidth = window.innerWidth;
      viewportheight = window.innerHeight;
 	}  else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
		 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		viewportwidth = document.documentElement.clientWidth;
       	viewportheight = document.documentElement.clientHeight;
 	} else {
 		// older versions of IE
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
 	}
	offset = (viewportheight - _docHeight + 9) + (document.getElementById('pos_a').clientHeight - document.getElementById('pos_b').clientHeight);

	if (offset > 0 && document.getElementById('sizer')) 
			document.getElementById('sizer').style.height = offset + 'px';
			
	
}
  
function set_doc_size () {
	var _docHeight = (document.height || document.body.offsetHeight);

	var offset = 0;
	var viewportwidth;
 	var viewportheight;
 	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 	if (typeof window.innerWidth != 'undefined'){
      viewportwidth = window.innerWidth;
      viewportheight = window.innerHeight;
 	}  else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
		 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		viewportwidth = document.documentElement.clientWidth;
       	viewportheight = document.documentElement.clientHeight;
 	} else {
 		// older versions of IE
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
 	}
   	offset = (viewportheight - _docHeight + 18);
	if (offset > 0 && document.getElementById('sizer')) document.getElementById('sizer').style.height = offset + 'px';
}

function dialog_chk (fld) {
	if (fld.value + '' != '') {
		fld.form.sub_send.disabled = "";
	} else {
		fld.form.sub_send.disabled = "disabled";
	}
}
 
function chkusr(fld, dlg_flag) {
  if (((fld.value + '') != '') && active) { 
  ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	  token_str=token_str.replace("\n", "");	  
	  //alert(token_str);
          if (token_str.indexOf('0') > -1) {
	    	if (dlg_flag) {
				document.getElementById("sub_lgn").disabled = "";
			} else {
				document.getElementById("sub_send_id").disabled = "";
			}
          } else {
	        if (dlg_flag) {
				document.getElementById("sub_lgn").disabled = "disabled";
        		show_usr_err_frm(token_str);
			} else {
				 if (token_str.indexOf('1') > -1) { 
				 	document.getElementById("sub_send_id").disabled = "";        		
				 } else {
					document.getElementById("sub_send_id").disabled = "disabled";        			 
				 }
				
			}
          } 
	 }
	}
    }
  usr = fld.value;
  xmlHttp.open("GET","chkusr_prox.php?usr=" + fld.value + "&idx=" + Math.random(),true);
  xmlHttp.send(null);  	
  }
}

function prst (fld, fld2) {
  if (((fld.value + '') != '') && ((fld2.value + '') != '')) { 
  ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4) {
	 		if(xmlHttp.status==200) {
	  			token_str =  new String(xmlHttp.responseText);
   	  			token_str=token_str.replace("\n", "");	  
				win_p_usr.hide();
				win_p_usr_dlg.hide();
				if (token_str.indexOf('Success') > -1) {
					if (def_focus_fld.value == "") {
						def_focus_fld.value = usr;
					}
					set_p_rst_usr_win();
					setTimeout("win_p_rst_usr.hide()", 2000);
  	  			} else {
					set_p_rst_usr_dlg_win();
					setTimeout("win_p_rst_usr_dlg.hide()", 2000);
	  			}
				setTimeout("default_focus()",2500);
				
	 		}
		}
    }
  usr = fld.value;
  xmlHttp.open("GET","prst_prox.php?usr=" + fld.value + "&eml=" + fld2.value + "&idx=" + Math.random() ,true);
  xmlHttp.send(null);  	
  }
}

function accreq (fld, fld2) {
  if (((fld.value + '') != '') && ((fld2.value + '') != '')) { 
  ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4) {
	 		if(xmlHttp.status==200) {
	  			token_str =  new String(xmlHttp.responseText);
   	  			token_str=token_str.replace("\n", "");	
				win_nusr.hide();
				win_nusr_dlg.hide();
				
				if (token_str.indexOf('Sent') > -1) {
					if (def_focus_fld.value == "") {
						def_focus_fld.value = usr;
					}
					set_sup_usr_win();
					setTimeout("win_sup_usr.hide()", 2000);
  	  			} else {
					set_sup_usr_dlg_win();
					setTimeout("win_sup_usr_dlg.hide()", 2000);
	  			}
				setTimeout("default_focus()",2500);
				
	 		}
		}
    }
  usr = fld.value;
  xmlHttp.open("GET","support_prox.php?msg=" + fld.value + "&eml=" + fld2.value + "&idx=" + Math.random() ,true);
  xmlHttp.send(null);  	
  }
}

function show_usr_err_frm (usr_code) {
   if (usr_code.indexOf('3') > -1) {
      set_nusr_dlg_win ();
   } else if (usr_code.indexOf('1') > -1) {
      set_p_usr_win ();
   } else {
      set_p_rst_usr_dlg_win ();
   }
}



function show_nusr () {
  win_nusr.show();  	 
}

function show_nusr_dlg () {
  win_nusr_dlg.show();  	 
}

function show_rpwd () {
  var ihtm = win_p_usr.getContent().innerHTML;
 
 win_p_usr.getContent().innerHTML = ihtm.replace("[$USR]", "");
  win_p_usr.show();
}

function default_focus_init() {
	def_focus_fld = document.getElementById('mainlgn').ssousername;	
}

function default_focus() {
	def_focus_fld.focus();
}

function index_init() {   
	nusr_win_init ();
	nusr_dlg_win_init ();
	p_usr_win_init ();
	p_usr_win_dlg_init ();
	p_rst_usr_win_init ();
	p_rst_usr_win_dlg_init ();
	sup_usr_win_init();
	sup_usr_win_dlg_init();
	WindowStore.init();	
	default_focus_init();
	default_focus();
}

function nusr_win_init () {
   win_nusr = new Window('1', {className: "alphacube", title: "Request CTU Portal Access", width:450, height:250, top:70, left:100}); 
   win_nusr.getContent().innerHTML = win_nusr_htm; 
   
} 

function nusr_win_update () {
    win_nusr.getContent().innerHTML = win_nusr_htm;    
	win_nusr.show();
}

function nusr_dlg_win_init () {
   win_nusr_dlg = new Window('2', {className: "alphacube", title: "Request CTU Portal Access", width:450, height:270, top:70, left:100}); 
   win_nusr_dlg.getContent().innerHTML = win_nusr_dlg_htm;    
   
}

function nusr_dlg_win_update () {
	win_nusr_dlg.getContent().innerHTML = win_nusr_dlg_htm;  
	win_nusr_dlg.show();
}

function p_usr_win_init () {
    win_p_usr = new Window('3', {className: "alphacube", title: "Reset Account Password", width:300, height:200, top:70, left:100}); 
    win_p_usr.getContent().innerHTML = win_p_usr_htm;    	
}

function p_usr_win_update () {
    win_p_usr_htm = win_p_usr_htm.replace("[$USR]", usr);
	win_p_usr.getContent().innerHTML = win_p_usr_htm;  
	win_p_usr.show();
	setTimeout("p_usr_win_update_focus()",500);
}

function p_usr_win_update_focus() {
	try {
		win_p_usr.setSize(350, 200);
		document.getElementById('prst_c3').focus();
	} catch (e) {
		setTimeout("p_usr_win_update_focus()",500);
	}
}

function p_usr_win_dlg_init () {
    win_p_usr_dlg= new Window('4', {className: "alphacube", title: "Request Password Reset", width:450, height:270, top:70, left:100}); 
    win_p_usr_dlg.getContent().innerHTML = win_p_usr_dlg_htm;    
	
}

function p_usr_win_dlg_update () {
    win_p_usr_dlg.getContent().innerHTML = win_p_usr_dlg_htm;  
	win_p_usr_dlg.show();
	setTimeout("p_usr_win_dlg_update_focus()",500);
}

function p_usr_win_dlg_update_focus() {
	try {
		win_p_usr_dlg.setSize(350, 200);
		document.getElementById('prst_c2').focus();
	} catch (e) {
		setTimeout("p_usr_win_dlg_update_focus()",500);
	}
}


function p_rst_usr_win_init () {
    win_p_rst_usr= new Window('5', {className: "alphacube", title: "Password Request Sent.", width:450, height:270, top:70, left:100}); 
    win_p_rst_usr.getContent().innerHTML = win_p_rst_usr_htm;    
	
}

function p_rst_usr_win_update () {
    win_p_rst_usr.getContent().innerHTML = win_p_rst_usr_htm;  
	win_p_rst_usr.show();
}

function p_rst_usr_win_dlg_init () {
    win_p_rst_usr_dlg= new Window('6', {className: "alphacube", title: "Portal Account Error.", width:450, height:270, top:70, left:100}); 
    win_p_rst_usr_dlg.getContent().innerHTML = win_p_rst_usr_dlg_htm;    
	
}

function p_rst_usr_win_dlg_update () {
    win_p_rst_usr_dlg.getContent().innerHTML = win_p_rst_usr_dlg_htm;  
	win_p_rst_usr_dlg.show();
}

function sup_usr_win_init () {
    win_sup_usr= new Window('7', {className: "alphacube", title: "Account Request Sent", width:450, height:270, top:70, left:100}); 
    win_sup_usr.getContent().innerHTML = win_sup_usr_htm;    
	
}

function sup_usr_win_update () {
    win_sup_usr.getContent().innerHTML = win_sup_usr_htm;  
	win_sup_usr.show();
}

function sup_usr_win_dlg_init () {
    win_sup_usr_dlg= new Window('8', {className: "alphacube", title: "Account Request Error", width:450, height:270, top:70, left:100}); 
    win_sup_usr_dlg.getContent().innerHTML = win_sup_usr_dlg_htm;    
	
}

function sup_usr_win_dlg_update () {
    win_sup_usr_dlg.getContent().innerHTML = win_sup_usr_dlg_htm;  
	win_sup_usr_dlg.show();
}



function set_nusr_win () {
	ajaxFunction(); 
	xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
	   win_nusr_htm = token_str;
         nusr_win_update();            	    
       } 
	 }	
    }
  xmlHttp.open("GET","create_usr.htm",true);
  xmlHttp.send(null);    
}

function set_nusr_dlg_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	   // alert(token_str);	
	    win_nusr_dlg_htm = token_str;
		nusr_dlg_win_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","create_usr_dialog.htm",true);
  xmlHttp.send(null);    
}

function set_p_usr_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
            win_p_usr_htm =  token_str;
			p_usr_win_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","create_usr_pwd.htm",true);
  xmlHttp.send(null);    
}

function set_p_usr_dlg_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
            win_p_usr_dlg_htm =  token_str;
            p_usr_win_dlg_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","create_usr_pwd_dialog.htm",true);
  xmlHttp.send(null);    
}

function set_p_rst_usr_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
            win_p_rst_usr_htm =  token_str;
            p_rst_usr_win_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","dialog_usr_rst.htm",true);
  xmlHttp.send(null);    
}

function set_p_rst_usr_dlg_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
            win_p_rst_usr_dlg_htm =  token_str;
            p_rst_usr_win_dlg_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","dialog_usr_err.htm",true);
  xmlHttp.send(null);    
}

function set_sup_usr_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
            win_sup_usr_htm =  token_str;
            sup_usr_win_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","support_usr_rst.htm",true);
  xmlHttp.send(null);    
}

function set_sup_usr_dlg_win () {
 ajaxFunction();
  xmlHttp.onreadystatechange=function()
    {
	if(xmlHttp.readyState==4) {
	 if(xmlHttp.status==200) {
	  token_str =  new String(xmlHttp.responseText);
    	    //alert(token_str);
            win_sup_usr_dlg_htm =  token_str;
            sup_usr_win_dlg_update ();
          } 
	 }	
    }
  xmlHttp.open("GET","support_usr_err.htm",true);
  xmlHttp.send(null);    
}