function my_afterCopy()
{
	document.getElementById("main_msg").innerHTML = learningTitleMsg;
	var innerString = "";
	innerString += make_input("fromDate","11");
	innerString += "~";
	innerString += make_input("toDate","11");
	innerString += make_button("search","8");	
	//alert(innerString);
	document.getElementById("learning_search").innerHTML = innerString;
}

function show_choicediv(el,lecture_cd){
	var choice_div = document.getElementById("choice_box");
	document.getElementById("tmp_lecture_cd").value = lecture_cd;
	choice_div.style.visibility="visible";
	this.getPosition(el, choice_div);
}

function hide_choicediv(){
	var choice_div = document.getElementById("choice_box");
	choice_div.style.visibility="hidden";
}

function make_input(name, size){
	var input_tag = "";
	input_tag = "<input type=text name="+name+" size="+size+">";
	return input_tag;	
}

function make_button(value, size){
	var input_tag = "";
	input_tag = "<input type=button value="+value+" size="+size+">";
	return input_tag;	
}

function getPosition(tag, choice_div){
    
    if(document.all) {
        var rect = tag.getBoundingClientRect(); 
        choice_div.style.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft)+30;        
        choice_div.style.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop)+10;
    } else { 
        var box = document.getBoxObjectFor(tag);
        choice_div.style.left = box.x; 
        choice_div.style.top = box.y; ;
    }
}

function show_delete_escrow(lecture_cd){
	document.getElementById("lecture_cd").value = document.getElementById("tmp_lecture_cd").value;
	document.getElementById('my_delete_escrow').style.display = 'block';
	hide_choicediv();
}

function hide_delete_escrow(){
	document.getElementById('lecture_cd').value = '';	
	document.getElementById('escrow_comment').value = '';
	document.getElementById('my_delete_escrow').style.display = 'none';	
}

function send_ecrow(){
	
	if (document.getElementById("lecture_cd").value ==""){
		alert("There is no content to escrow.");
		return;
	}
	
	if (document.getElementById("escrow_comment").value ==""){
		alert("There is no comment.");
		return;
	}
	
	if(confirm("Are you sure to escrow this content?")){	
		var url = "/mypage/learning/my_escrow_proc.jsp";
		var rUrl = "/mypage/learning/my_learning_list.jsp";
		var layer = "index";
		
		var params = Form.serialize(delete_escrow_form);
		//alert(params);
	
		//function(url, params, rUrl, layer, callback, method)
		//this.callback(this.req, this.rUrl, this.layer);
	
		new ajax.xhr.Request(url, params, rUrl, layer, escrowResp, 'POST');
	}
	
}

//this.req, this.rUrl, this.layer
function escrowResp(req, rUrl, layer)
{
	var xmlDoc = req.responseXML;
	alert("You've success to escrow the " + document.getElementById("lecture_cd").value);
	hide_delete_escrow();
//	var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue;
//
//	//alert("code:"+ code);
//	if (code =='success')
//	{
//		if (callPage != null && layer !=null)
//			callPage(rUrl,layer); 
//	}
//
//	else if (code =='fail')
//	{
//		var message = xmlDoc.getElementsByTagName('message').item(0).firstChild.nodeValue;
//		var view = document.getElementById('process_err_msg');
//		view.innerHTML = message;
//	}
}

var lectureRequestWindow = null;

function show_request_lecture_form()
{
	if (lectureRequestWindow == null)
	{
		var params = encodeURIComponent(Form.serialize(document.search_form));
			
		lectureRequestWindow = new Ext.Window({
		id:'requestRectureWin',
		title:'Content Request',
		layout:'fit',
		width:713,
		autoHeight:true,
		resizable:false,
		closeAction:'close',
		modal:true
	    });
			
		lectureRequestWindow.on('render', function() { 
		  lectureRequestWindow.load({
	     method: 'GET',
	     url: '/search/popup/request_lecture_form.jsp',
	     callback : function (success, response, request )
	     {   
	     	 if(request.responseText.indexOf('SESSION_OUT') != -1)
		     { 
		         var arr1 = request.responseText.split('|');
		         var arr2 = arr1[1].split('&');
		         		         
		         var rtnUrl = null;
		         var layer = null;
		         var loadJSFunc = null;
		         var params = encodeURIComponent(Form.serialize(document.search_form));
		         for(i=0;i<arr2.length;i++)
		         {
			         switch(i)
			         {
			         	case 0 : rtnUrl = arr2[i].substring(arr2[i].indexOf('=')+1);break;
			         	case 1 : layer = arr2[i].substring(arr2[i].indexOf('=')+1);break;
			         	case 2 : loadJSFunc = arr2[i].substring(arr2[i].indexOf('=')+1);break;		         
			         }
		         }	         
		     
			     login_popups(rtnUrl, layer, loadJSFunc, params);
			     hide_request_lecture_form();		
				 return;
		     }	
	     }
	     	     
	    }); 
	  }); 
	 
	  lectureRequestWindow.on('close', function() { 
		  lectureRequestWindow.close();
		  lectureRequestWindow = null;
	  });
	 
	  lectureRequestWindow.show();
	}	
}



function hide_request_lecture_form()
{
	lectureRequestWindow.close();	
	loginPopupWindow = null;
}

function send_lecture_request()
{	
	if(document.getElementById('detail').value == '')
	{		
		document.getElementById('detail').style.backgroundColor='yellow';
		document.getElementById('detail').focus();
		return;
	}
	
	var url = "/mypage/learning/my_lecture_request_action.jsp";	 
	var rUrl = null;		
	var layer = null;
	var params = Form.serialize(form_lecture_request);	
	new ajax.xhr.Request(url, params, rUrl, layer, res_lecture_request, 'POST');
}

function res_lecture_request(req, rUrl, layer)
{
	var xmlDoc = req.responseXML;
	var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue;	
	var message = null;    
    
	if (code =='success')
	{	
		//document.getElementById(layer).innerHTML = 'request success!';
		hide_request_lecture_form();
		
	} else if (code =='fail')
	{
		hide_request_lecture_form();
		//message = xmlDoc.getElementsByTagName('message').item(0).firstChild.nodeValue;
		//document.getElementById(layer).innerHTML = message;
	}
	
}


function my_learning_page_paging(tot_cnt, cur_page, page_row)
{
	//alert('my_learning_page_paging');
	PG = new Paging(tot_cnt, 'my_learning_paging');
	PG.config = {
		thisPageStyle: 'font-weight: bold; color:#33B7FB',
		//otherPageStyle: 'color: #000000',
		itemPerPage: page_row,	// Listing cnt
		pagePerView: 5,		// Paging per number Block
		cur_page:cur_page
	}
	//alert(PG.toString());
	document.getElementById('my_learning_paging_div').innerHTML = PG.toString();
}

function my_learning_page_init()
{	
	//alert('my_learning_page_init');
	Event.observe($('per_pg'), 'change', my_learning_page_paging($('tot_cnt').value, $('cur_pg').value, $('per_pg').value));
	
	for (var i=0; i<parseInt($('per_pg').value); i++)
	{	
		var cell = document.getElementById("cell_my_learn"+i);	
		Event.observe(cell, "mousedown", mouseDownOnCell.bind(this));
	}
}

function my_learning_paging(num)
{
	$('cur_pg').value = num;
	var params = Form.serialize('my_learning_form');	
	
	var val = document.getElementById('view').value;	
	var url = null;
	if(val == '1')
		url = '/mypage/learning/my_learning_list.jsp?';
	else
		url = '/mypage/learning/my_interesting_list.jsp?';
	
	callPage(url+params, 'index', my_learning_page_init,'my_learning_page_init');
}

function chg_my_learing()
{
	var val = document.getElementById('view').value;	
	var url = null;
	if(val == '1')
		url = '/mypage/learning/my_learning_list.jsp';
	else
		url = '/mypage/learning/my_interesting_list.jsp';
	
	callPage(url, 'index', my_learning_page_init,'my_learning_page_init');
		
}

var couponWindow = null;

function show_use_coupon_form()
{
	if (couponWindow == null)
	{
		var params = null;
			
		couponWindow = new Ext.Window({
		id:'requestCouponWindow',
		title:'coupon authentication',
		layout:'fit',
		width:730,		
		autoHeight:false,
		resizable:true,
		closeAction:'close',
		autoScroll:true,
		modal:true
	    });
			
		couponWindow.on('render', function() { 
			couponWindow.load({
	     method: 'GET',
	     url: '/mypage/learning/popup/learning_popup.jsp',
	     callback : function (success, response, request )
	     {   				 
	     	 if(request.responseText.indexOf('SESSION_OUT') != -1)
		     { 
		         var arr1 = request.responseText.split('|');
		         var arr2 = arr1[1].split('&');
		         		         
		         var rtnUrl = null;
		         var layer = null;
		         var loadJSFunc = null;
		         params = '0=0';
		         for(i=0;i<arr2.length;i++)
		         {
			         switch(i)
			         {
			         	case 0 : rtnUrl = arr2[i].substring(arr2[i].indexOf('=')+1);break;
			         	case 1 : layer = arr2[i].substring(arr2[i].indexOf('=')+1);break;
			         	case 2 : loadJSFunc = arr2[i].substring(arr2[i].indexOf('=')+1);break;		         
			         }
		         }	         
		     
			     login_popups(rtnUrl, layer, loadJSFunc, params);
			     hide_use_coupon_form();		
				 return;
		     }	
	     }
	     	     
	    }); 
	  }); 
	 
		couponWindow.on('close', function() { 
			couponWindow.close();
			couponWindow = null;
	  });
	 
		couponWindow.show();
	}	
}



function hide_use_coupon_form()
{
	couponWindow.close();	
	loginPopupWindow = null;
}


function requestAuthCouponNo()
{
	var url = "/mypage/learning/coupon_action.jsp";	
	var layer = null;
	var params = "cmd=auth&coupon_no="+document.getElementById('coupon_no').value;
	progress_bar(true);
	new ajax.xhr.Request(url, params, null, layer, responseAuthCouponNo, 'POST');
}

function responseAuthCouponNo(req)
{
	var xmlDoc = req.responseXML;
	var code = xmlDoc.getElementsByTagName('code').item(0).firstChild.nodeValue;

    var message = null;    
	if (code =='success')
	{		
		document.getElementById('divBtn').style.display = 'none';
		//couponWindow.setWidth(740);
		couponWindow.setHeight(500);
		couponWindow.setAutoScroll(true);
		//couponWindow.setAutoHeight(false);
		message = xmlDoc.getElementsByTagName('data').item(0).firstChild.nodeValue;
		var dataSet = eval( "(" +  message + ")" );
		
		var coupon_no = null;
		var limit_dt = null;
		var lecture_cd = null;
		var title = null;
		
		var lectuerData = '';
		
		for(var i=0; i<dataSet.coupon_detail.length; i++)
		{
			coupon_no = dataSet.coupon_detail[i].coupon_no;
			limit_dt = dataSet.coupon_detail[i].limit_dt;
			lecture_cd = dataSet.coupon_detail[i].lecture_cd;
			title = decodeURL(dataSet.coupon_detail[i].title);
			
			if(i == 0)
				lectuerData = "<a href=\"javascript:sc_lect_detail('"+lecture_cd+"');hide_use_coupon_form();\">"+fixLength(title, 40, '...')+"</a>";
			else 
				lectuerData = lectuerData +"<br>"+"<a href=\"javascript:sc_lect_detail('"+lecture_cd+"');hide_use_coupon_form();\">"+fixLength(title, 40, '...')+"</a>";
			
		}
		
		document.getElementById('div_coupon_msg').innerHTML = 'You can learn the following courses until'+yyyymmddFormat(limit_dt)+' enjoy seemile.com'; 
		document.getElementById('div_lecture_data').innerHTML = lectuerData;
		
		
		try
		{
			document.getElementById('label_coupon_lecture_list').style.display = '';
		} catch(e)
		{}
		
	}else if (code =='fail')
	{
		message = xmlDoc.getElementsByTagName('data').item(0).firstChild.nodeValue;
		var view = document.getElementById('div_coupon_msg');
		view.innerHTML = message;
	}	
	
	progress_bar(false);
}


function show_coupon_lecture_list()
{
	if (couponWindow == null)
	{
		var params = null;
			
		couponWindow = new Ext.Window({
		id:'requestCouponWindow',
		title:'coupon lecture list',
		layout:'fit',
		width:740,
		height:500,
		autoScroll:true,		
		//scroll:
		autoHeight:false,
		resizable:true,
		closeAction:'close',
		modal:true
	    });
			
		couponWindow.on('render', function() { 
			couponWindow.load({
	     method: 'GET',
	     url: '/mypage/learning/popup/learning_popup.jsp?cmd=coupon_lecture_list',
	     callback : function (success, response, request )
	     {   				 
	     	 if(request.responseText.indexOf('SESSION_OUT') != -1)
		     { 
		         var arr1 = request.responseText.split('|');
		         var arr2 = arr1[1].split('&');
		         		         
		         var rtnUrl = null;
		         var layer = null;
		         var loadJSFunc = null;
		         params = '0=0';
		         for(i=0;i<arr2.length;i++)
		         {
			         switch(i)
			         {
			         	case 0 : rtnUrl = arr2[i].substring(arr2[i].indexOf('=')+1);break;
			         	case 1 : layer = arr2[i].substring(arr2[i].indexOf('=')+1);break;
			         	case 2 : loadJSFunc = arr2[i].substring(arr2[i].indexOf('=')+1);break;		         
			         }
		         }	         
		     
			     login_popups(rtnUrl, layer, loadJSFunc, params);
			     hide_use_coupon_form();		
				 return;
		     }	
	     }
	     	     
	    }); 
	  }); 
	 
		couponWindow.on('close', function() { 
			couponWindow.close();
			couponWindow = null;
	  });
	 
		couponWindow.show();
	}	
}




