







var myShowForm=false;

var myContentForm = false;

var form_element_prefix = "ctl00_Main_";

var GB_ROOT_DIR = "http://"+greyboxPath(document.location.href)+"/admin/code/JavaScript/greybox/";



function greyboxPath(url_)

{

	url_ = (url_.indexOf('http://') > -1) ? url_.substring(7,url_.length) : url_.substring(8,url_.length);

	url_ = url_.substring(0,url_.indexOf('/'))

	return url_;

}





function ManageContent(Action,thisIDname,thisIDvalue,PartNumber,FileName,K_){

			

	if (myContentForm){

		myContentForm.close();

	}

	

	if(Action=="D"){

		if(document.getElementById('current_content_container')){

			document.getElementById('current_content_container').value="|"+thisIDname+","+thisIDvalue+","+PartNumber+","+K_+"|";

			return false;

		}else{

			return false;

		}

	}

	

	K_ = K_ ? K_ : 0;



//	myContentForm = window.open('/admin/code/Content/ContentForm/ContentForm_'+FileName+'_'+PartNumber+'.aspx?A='+Action+'&B='+thisIDname+'&C='+thisIDvalue+'&D='+PartNumber+'&E='+K_,'ContentManage','toolbars=no,scrollbars=yes,status=yes,location=no,width=600,height=575,resizable=yes,left=10,top=10,postionx=10,positiony=10');

	GB_showCenter('Manage Content','/admin/code/Content/ContentForm/ContentForm_'+FileName+'_'+PartNumber+'.aspx?A='+Action+'&B='+thisIDname+'&C='+thisIDvalue+'&D='+PartNumber+'&E='+K_,700,900);





}





function ShowAddUpdate(FileName,Action,Args,PopUp){



	var isMac = navigator.userAgent.indexOf('Mac') != -1 

		

	if (isMac){

		if (Args){

			if(Args.substring(1,1) != "&"){

				Args = '&'+Args

			}

		}else{

			Args = ''

		}	

	}else{

		if ((Args != undefined) && (Args != '')){

			if(Args.substring(1,1) != "&"){

			Args = '&'+Args

			}

		}else{

			Args = ''

		}

	}

	

	var formName = 'formName'



	var xtraArgs = document.location.href;

	if(xtraArgs.indexOf('?')>0){

		xtraArgs = xtraArgs.substring(xtraArgs.indexOf('?')+1,xtraArgs.length);

		if(Action=="U" || Action=="S" &&Args.indexOf('PK=')>-1){

			xtraArgs=xtraArgs.replace(/PK=[\S]*?&/gi,"");

		}

	}else{

		xtraArgs = "";

	}



	if(Args!=""&&xtraArgs!=""){xtraArgs='&'+xtraArgs;}

	Args += xtraArgs; 

	if(Args!=""&&Args.substring(0,1)!='&'){

		Args='&'+Args;

	}

	if(myShowForm){

		myShowForm.close();

	}

	





	var prefixPath = "/admin/code/AddUpdatePages/";	

	if(PopUp){

		prefixPath = "/admin/code/PopUp/";

	}



//	myShowForm = window.open(prefixPath+FileName+'?A='+Action+Args,formName,'toolbars=no,scrollbars=yes,status=yes,location=no,width=600,height=575,resizable=yes,left=10,top=10,postionx=10,positiony=10');

//	myShowForm.focus();

	

	GB_showCenter('eSprout', prefixPath+FileName+'?A='+Action+Args,700,900);



}



function ShowMailForm(fileName,width,height){
	GB_showCenter('eSprout',fileName,height,width);
}


function ShowPopUp(FileName,useGreyBox,width,height){

	var formName = 'formName'+FileName.replace(/[^a-zA-Z]/gi,"");

	var prefixPath = "/admin/code/PopUp/";



	if (useGreyBox){

		//alert(width);

		GB_showCenter('eSprout',prefixPath+FileName,height,width);

	}else{

		var myPopUpForm = window.open(prefixPath+FileName,formName,'toolbars=no,scrollbars=yes,status=yes,location=no,width=900,height=625,resizable=yes,left=10,top=10,postionx=10,positiony=10');

		myPopUpForm.focus();

	}

}









function closeForm(){

	try{

		parent.parent.GB_hide();

	} catch(err){

		opener.document.location.href=opener.document.location.href;

		window.close();

	}

}



function RunOrderByColumnName(ColumnName){



	if(document.getElementById('ctl00_Main_OrderByColumnName')){

		var currOrderByColumnName = document.getElementById('ctl00_Main_OrderByColumnName')

		if(currOrderByColumnName.value==ColumnName+' ASC'){

			currOrderByColumnName.value=ColumnName+' DESC';

		}else{

			currOrderByColumnName.value=ColumnName+' ASC';

		}

			

	}

	document.forms[0].submit();

}







function showPrint(PrintKey){

	var myPrint = window.open('/admin/code/Print/ManagePrint.aspx?A='+PrintKey,PrintKey,'toolbars=yes,scrollbars=yes,status=yes,location=no,width=650,height=575,resizable=yes,left=10,top=10,postionx=10,positiony=10');

	myPrint.focus();



}



function showPrintPage(Page){

	var URL = "/Admin/Code/PopUp/PopUp_Print.aspx?page="+Page;

	GB_showCenter('Print Page',URL,null,778);



}









function ChangePage(Action,To,Step){

	var regRetVal = new RegExp(/retVal=[\S|\s]*/gi);

	var regURL = new RegExp(/http:\/\/[\S]*?\.[\S]*?\//i);

	var retVal = regRetVal.exec(document.location.href); 

	retVal = retVal ? retVal[0] : "";



	var baseURL = regURL.exec(document.location.href);

	baseURL = baseURL[0];

	var currPage = document.location.href;

	currPage = currPage.substring(baseURL.length-1,currPage.length);

	Step = Step ? Step : 0;





	if(Action=="BACK"){

		var itemName="";itemValue="";itemArray = new Array();

		retVal = retVal.replace(/\%3a/gi,":");

		retVal = retVal.replace(/\%7C/gi,"|");

		if(retVal.substring(0,7)=='retVal='){

			retVal = retVal.substring(7,retVal.length);

		}

		var retHistory = retVal.split(/\|/gi);

		for(k=0;k<retHistory.length;k++){

			itemName = retHistory[k].substring(0,retHistory[k].indexOf(':'))

			itemValue = retHistory[k].substring(retHistory[k].indexOf(':')+1,retHistory[k].length);

			itemArray[itemName] = URLDecode(itemValue);

		}

		

		if(itemArray.length>=Step){

			if(itemArray[Step].indexOf('&retVal=')>0){

				retVal = itemArray[Step];

				retVal = retVal.substring(retVal.indexOf('&retVal=')+8,retVal.length)

				itemArray[Step] = itemArray[Step].substring(0,itemArray[Step].indexOf('&retVal=')+7)+"="+URLEncode(retVal)+'|';

			} 

			document.location.href = itemArray[Step];

		}else{

			alert('Could not find Step in the retVal of the previous querystring');

			return false;

		}

	

	}else if(Action=="NEXT"){

		// append to retVal if applicable		

		if(retVal){

			currPage = (currPage.substring(currPage.length-1,currPage.length)!='|') ? currPage+'|' : currPage;

			retVal+=Step+":"+URLEncode(currPage)

			if (To.indexOf("?")==-1){

				To+='?'+retVal;

			}else{

				To+="&"+retVal;

			}

			document.location.href = To;

		}else{

			retVal = "&retVal="+Step+":"+URLEncode(currPage)+'|'

			To+=retVal;

			document.location.href = To;

		}	

		

	}else{

		alert('No Action Specified: BACK OR NEXT');

		return false;

	}



}







function Get_Cookie(name) { 

   var start = document.cookie.indexOf(name+"="); 

   var len = start+name.length+1; 

   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 

   if (start == -1) return null; 

   var end = document.cookie.indexOf(";",len); 

   if (end == -1) end = document.cookie.length; 

   return unescape(document.cookie.substring(len,end)); 

} 



function Set_Cookie( name, value, expires, path, domain, secure ){

// set time, it's in milliseconds

var today = new Date();

today.setTime( today.getTime() );



/*

if the expires variable is set, make the correct 

expires time, the current script below will set 

it for x number of days, to make it for hours, 

delete * 24, for minutes, delete * 60 * 24

*/



if ( expires )

{

expires = expires * 1000 * 60 * 60 * 24;

}

var expires_date = new Date( today.getTime() + (expires) );



document.cookie = name + "=" +escape( value ) +

( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 

( ( path ) ? ";path=" + path : "" ) + 

( ( domain ) ? ";domain=" + domain : "" ) +

( ( secure ) ? ";secure" : "" );

}





function Delete_Cookie(name,path,domain) { 

   if (Get_Cookie(name)) document.cookie = name + "=" + 

      ( (path) ? ";path=" + path : "") + 

      ( (domain) ? ";domain=" + domain : "") + 

      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 

} 











function URLEncode (clearString) {

  var output = '';

  var x = 0;

  clearString = clearString.toString();

  var regex = /(^[a-zA-Z0-9_.]*)/;

  while (x < clearString.length) {

    var match = regex.exec(clearString.substr(x));

    if (match != null && match.length > 1 && match[1] != '') {

    	output += match[1];

      x += match[1].length;

    } else {

      if (clearString[x] == ' ')

        output += '+';

      else {

        var charCode = clearString.charCodeAt(x);

        var hexVal = charCode.toString(16);

        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();

      }

      x++;

    }

  }

  return output;

}





function URLDecode (encodedString) {

  var output = encodedString;

  var binVal, thisString;

  var myregexp = /(%[^%]{2})/;

  while ((match = myregexp.exec(output)) != null

             && match.length > 1

             && match[1] != '') {

    binVal = parseInt(match[1].substr(1),16);

    thisString = String.fromCharCode(binVal);

    output = output.replace(match[1], thisString);

  }

  return output;

}





function ChangeLang(curlang){

    var dom = document.domain;
    var loc = document.location.href;
    var locs = loc.substring(loc.indexOf(dom)+1+dom.length,loc.length);
    var newurl = "";
            
    dom = dom.indexOf('hudsondemo') > -1 ? dom+':81' : dom;
    locs = locs.replace('81/','');
      
   
            
    if(!curlang){
        // change to KOR
        newurl = 'http://'+dom+'/KOR/'+locs
        window.location.href=newurl;
    }else if(curlang=='KOR'||loc.indexOf('/KOR/')>0){
        // change to ENG
        newurl = loc.replace('/KOR/','/');
        window.location.href=newurl;        
    }else{
        // change to KOR
        newurl = 'http://'+dom+'/KOR/'+locs;  
        window.location.href=newurl;
    }


}




//Drop-Down Menu Start



var DDSPEED = 2;

var DDTIMER = 2;



// main function to handle the mouse events //

function ddMenu(id,d){

  var h = document.getElementById(id + '-ddheader');

  var c = document.getElementById(id + '-ddcontent');

  clearInterval(c.timer);

  if(d == 1){

    clearTimeout(h.timer);

    if(c.maxh && c.maxh <= c.offsetHeight){return}

    else if(!c.maxh){

      c.style.display = 'block';

      c.style.height = 'auto';

      c.maxh = c.offsetHeight;

      c.style.height = '0px';

    }

    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);

  }else{

    h.timer = setTimeout(function(){ddCollapse(c)},50);

  }

}



// collapse the menu //

function ddCollapse(c){

  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);

}



// cancel the collapse if a user rolls over the dropdown //

function cancelHide(id){

  var h = document.getElementById(id + '-ddheader');

  var c = document.getElementById(id + '-ddcontent');

  clearTimeout(h.timer);

  clearInterval(c.timer);

  if(c.offsetHeight < c.maxh){

    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);

  }

}



// incrementally expand/contract the dropdown and change the opacity //

function ddSlide(c,d){

  var currh = c.offsetHeight;

  var dist;

  if(d == 1){

    dist = (Math.round((c.maxh - currh) / DDSPEED));

  }else{

    dist = (Math.round(currh / DDSPEED));

  }

  if(dist <= 1 && d == 1){

    dist = 1;

  }

  c.style.height = currh + (dist * d) + 'px';

  c.style.opacity = currh / c.maxh;

  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';

  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){

    clearInterval(c.timer);

  }

}



//Drop-Down Menu Stop



var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {

  var keyCode = (isNN) ? e.which : e.keyCode; 

  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

  if(input.value.length >= len && !containsElement(filter,keyCode)) {

    input.value = input.value.slice(0, len);

    input.form[(getIndex(input)+1) % input.form.length].focus();

  }



  function containsElement(arr, ele) {

    var found = false, index = 0;

    while(!found && index < arr.length)

    if(arr[index] == ele)

    found = true;

    else

    index++;

    return found;

  }



  function getIndex(input) {

    var index = -1, i = 0, found = false;

    while (i < input.form.length && index == -1)

    if (input.form[i] == input)index = i;

    else i++;

    return index;

  }

  return true;

}



/*Emeet Integration*/

function eMEET(prodid, id, section, alias,userIP, lang, role){

	var ip = "222.122.6.76";
	var obj;
	
    if (!document.all.EMPCRWeb){
        obj = document.getElementById('EMPCRWeb');
        if(!obj){
            alert('Unable to find EMPCR Web');
            return;
        }       
    }else{
        obj = document.all.EMPCRWeb;    
    }


	
	obj.SetLang(lang);
	obj.SetProtocol(1);
         
    

	if(lang==0)
	{
	    obj.SetTitle('eSprout LLC TÖÁÀP­!ÇÜÂ¤Â\Ñ  V3.0');	
	}
	else
	{
	    obj.SetTitle('eSprout LLC eLearning System V3.0');	
	}
	

	//alert("EMPCRWeb.RunEx('"+prodid+"','"+ip+"','EMPCLIME.exe','"+id+"','"+alias+"','"+role+"','"+section+"','ESPROUT','9999', '', '','','')");
	obj.RunEx(prodid,ip,'EMPCLIME.exe',id,alias,role,section,'ESPROUT','9999', '', '','','');
	return ;

	

}





function getPaymentForm(price,item,name,email,args,sid){
	var payform = document.getElementById('aspnetForm');
	
	var mxNo = setMxIssueNO();
	var mxDt = mxNo;
	
	
	// set values
	document.getElementById('Amount').value = price;
    document.getElementById('CcProdDesc').value = item;
    document.getElementById('CcNameOnCard').value = name;
    document.getElementById('email').value = email;	
    document.getElementById('MSTR').value = args;
    document.getElementById('MSTR2').value = args;
    document.getElementById('MxIssueNO').value = mxNo+'-'+sid;
    document.getElementById('MxIssueDate').value = mxDt;
	
	TG_PAY = window.open("","TG_PAY", "resizable=yes, width=390, height=360");
	TG_PAY.focus();
	payform.target="TG_PAY";
	payform.action="https://npg.tgcorp.com/dlp/start.jsp";
	payform.submit();
}


function setMxIssueNO() {
	
	var time = new Date();
	var year = time.getYear() + "";
	var month = time.getMonth()+1;
	var date = time.getDate();
	var hour = time.getHours();
	var min = time.getMinutes();
	var sec = time.getSeconds();
	if(month<10) {
		month = "0" + month;
	}
	if(date<10) {
		date = "0" + date;
	}
	if(hour<10) {
		hour = "0" + hour;
	}
	if(min<10) {
		min = "0" + min;
	}
	if(sec<10) {
		sec = "0" + sec;
	}
	return  year + month + date + hour + min + sec;

}

function hideTags(a){

    var f;
    for(j=0;j<a.length;j++){
        f = document.getElementById(a[j]);
        if(f) f.style.display='none';
    }
}

function toggleCancel(fieldset,btn){
    var f = document.getElementById(fieldset);
    var b = document.getElementById(btn);
    if (!f) return false;
    if (!b) return false;
    f.style.display = f.style.display == 'block' ? 'none' : 'block';      
    b.style.display = b.style.display == 'block' ? 'none' : 'block';      
}




function changeWireForm(t){

    var l = new Array();
    var r = new Array();
    var v = new Array();

    if (t == "W"){
	    l["account_name"] = "Name on Account";
        v["ctl00_Main_ROW_Username"] = "block";

    }else if(t == "D"){
	    l["account_name"] = "Name on Deposit";
	    v["ctl00_Main_ROW_Username"] = "none";

    }

    Run_Form_Label_Obj_(l,r,v);

}



function defaultEmail(data){
	
	var x_to = "";
	var x_from = "";
	var x_subject = "";
	var x_body = "";
	
	data = data.substring(1,data.length-2);
	var items = data.split('>|<');
	try	{
			x_to = items[0];
			x_from = items[1];
			x_subject = items[2];
			x_body = items[3];
		}catch(e){
			//alert(e);
		}	
	
	if(x_to) document.getElementById('ctl00_Main_ToValue').value = x_to;
	if(x_from) document.getElementById('ctl00_Main_From').value = x_from;
	if(x_subject) document.getElementById('ctl00_Main_Subject').value = x_subject;
	if(x_body) tinyMCE.activeEditor.setContent(x_body);
	
}



function AutoEnroll(studentID){

    if(confirm('Are you sure you want to auto-enroll this student as paid?')){
	    document.getElementById('ctl00_Main_txtStudent').value=studentID;
	    return true;
    }else{
	    return false;
    }

}



function showmore(id){
     $('#'+id).toggle(400);
}

function markAsRead(id){
    var a = new Array('a_','b_','c_','d_','e_','f_');
    for(i=0;i<a.length;i++){
        var o = document.getElementById(a[i]+id);
        if(o) o.className = a[i]=='f_' ? 'inboxdelete' : 'inboxrow';
    }
}


function disapproveBio(fieldName){
    var obj = document.getElementById(fieldName);

    if(!confirm('Are you sure you want to disapprove this bio?\n\nIf yes, please enter the reason in the following textbox, this will be emailed to the teacher to update')){
        return false;
    }

    var txt = prompt('Please enter the reason that you are disapproving the bio');
    obj.value = txt
    return true;
}


function setComposeAddress(Username){
   
    var toObj = document.getElementById('ctl00_Main_ToID');
    var hideTo = document.getElementById('hideTo');
    
    toObj.innerHTML = '['+Username+']&nbsp;' + toObj.innerHTML.replace(/\[.*?\]&nbsp;/gi,'');
    toObj.innerHTML = toObj.innerHTML.replace('Add Recipient','Change Recipient');
   
    hideTo.value = Username;
    
    // close address book
    showmore('AddressBook');

}



$(window).scroll(function()
{
   var topWhat = $(window).scrollTop();
   var min = 0;
   var height = $(window).height();
   var offSet = parseFloat(height / 2) - (179 / 2);

    if($.browser.msie && $.browser.version==6.0){
        topWhat = topWhat < min ? min : topWhat;
    }else{
        topWhat = topWhat < min ? min : topWhat;
    }
    
    topWhat += offSet;
  
    
  $('#floatingBoxContainer').animate({top: topWhat + "px" },{queue: false, duration: 350});
});




function subnav(id,img){
   document.getElementById(id).src=img;
}


function hidebox(id,l){
    l = l ? l : 400;
    $('#'+id).fadeOut(l);
}

function showbox(id,l){
    l = l ? l : 400;
    $('#'+id).fadeIn(l);
}



function showTime(field){

    document.getElementById('_current').value = field;
    
    // if the time of the current day is not 1/1/1900 then set it
    var start = document.getElementById('start_'+field).value;
    var end = document.getElementById('end_'+field).value;
    var t = "";
    if(start!='1/1/1900'){
        t = start.substr(start.indexOf(' ')+1);
        t = t.replace(':00 ',' ');
        document.getElementById('_starttime').value = t;
    }
    
    if(end!='1/1/1900') {
        t = end.substr(start.indexOf(' ')+1);
        t = t.replace(':00 ',' ');
        document.getElementById('_endtime').value = t ;
    }
    
    
    $('#setTimeBox').fadeIn(400);
}

function hideTime(){
    document.getElementById('_current').value = '';
    $('#setTimeBox').fadeOut(400);
    updateOccurences();

}

function cancelTime(field){

    document.getElementById('ch_'+field).checked = false
    document.getElementById('set_'+field).value = '';
    hideTime();

}

function setTimeBoxToggle(fieldName){
    // set the value based on true/false
    var isTrue =  document.getElementById('ch_'+fieldName).checked;
    document.getElementById('set_'+fieldName).value = isTrue ? '1' : '';
    if(document.getElementById('start_'+fieldName).value=='1/1/1900' && isTrue){
        showTime(fieldName);
    }
    updateOccurences();
}

function saveTime(fieldName){
    // set the current fields to the end time
    var s = document.getElementById('_starttime').value
    var e = document.getElementById('_endtime').value
    
    if (s==''||e==''){
        alert('Start Time and End Time are required');
        return false;
    }
    
    
    var d = fieldName.substr(0,2)+'/'+fieldName.substr(2,2)+'/'+fieldName.substr(4);
    document.getElementById('start_'+fieldName).value = d + ' ' + s;
    document.getElementById('end_'+fieldName).value = d + ' ' + e;
    document.getElementById('label_'+fieldName).innerHTML = s + ' - ' + e;
    document.getElementById('ch_'+fieldName).checked = true;
    setTimeBoxToggle(fieldName);
    // close form
    hideTime();
    
      
}

function updateOccurences(){

    // increment and decrement the class occurences based on what the user does
    var counter = 0;
    var _startDate = "";
    var _endDate = "";
    var sessions = document.getElementById('ctl00_Main_ClassOccurence');
    var c = document.getElementById('wrapcalendar1').getElementsByTagName('input');
    for(d=0;d<c.length;d++){
        if(c[d].id.substring(0,4)=='set_'){
            counter += c[d].value == '1' ? 1 : 0;   
            if(_startDate=="" && c[d].value=='1'){
                // get first item
                _startDate = c[d].id.substr(4,2) + '/' + c[d].id.substr(6,2) + '/' + c[d].id.substr(8,4);
            }else if(c[d].value=='1'){
                // keep setting the end date
                _endDate = c[d].id.substr(4,2) + '/' + c[d].id.substr(6,2) + '/' + c[d].id.substr(8,4);
            }
        }
    }
    // updated
    sessions.value = counter;
    
    // set date
    var startDateObj = document.getElementById('ctl00_Main_StartDate');
    var endDateObj = document.getElementById('ctl00_Main_EndDate');
    
    // check start date / end date
    if(Date.parse(_startDate) < Date.parse(startDateObj.value)){
        startDateObj.value = _startDate;
    }
    
  
    
    if(Date.parse(_endDate) > Date.parse(endDateObj.value)){
        endDateObj.value = _endDate;
    }
  
    
}