/********************************************************  
 *																Ajax									*
 ********************************************************/
window.ajax = {
    httpRequest: ((window.XMLHttpRequest) ? new window.XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP")),
    request: function(){
        var sUrl = arguments[0];
        var sData = arguments[1];
        var oCallBack = arguments[2];
        
        var sMethod = 'GET';
        
        sUrl += (sUrl.split('?').length > 1) ? '&' : '?';
        sUrl += 'iProcess=' + new Date().toString().replace(/\s/gi, '');
        
        if (!(!sData)) 
            sMethod = 'POST';
        
        this.httpRequest.open(sMethod, sUrl, oCallBack);
        
        this.httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        this.httpRequest.setRequestHeader("Cache-Control", "");
        this.httpRequest.setRequestHeader("Pragma", "");
        this.httpRequest.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
        
        if (!(!oCallBack)) {
            this.httpRequest.onreadystatechange = oCallBack;
        }
        
        this.httpRequest.send(sData);
    }
}

window.elementActValue = function()
{
	var oOwner = arguments[0];

	var sReturn = '';
	
	switch ( oOwner.tagName.toUpperCase() ) {
		case 'TEXTAREA':
			sReturn = oOwner.value;
			break;
		case 'INPUT':
			switch ( oOwner.getAttribute('type').toUpperCase() ){
				case 'CHECKBOX':
					sReturn = oOwner.checked ? oOwner.value : '';
					break;
				case 'RADIO':
					sReturn = oOwner.checked ? oOwner.value : '';
					break;
				default:
					sReturn = oOwner.value;
					break;
			}
			
			break;
		case 'SELECT':
			sReturn = oOwner.options[oOwner.selectedIndex].value;
			break;
		default:
			break;
	}

	return sReturn;	
}

window.finder = function()
{
	var oOwner = arguments[0];
	var sAttrName = arguments[1];
	var sAttrVar = arguments[2];
	
	var oReturn = null;
	
	if ( oOwner.hasChildNodes() ) {
		for ( var i=0; i < oOwner.childNodes.length; i++ ) {
			if ( oOwner.childNodes[i].getAttribute(sAttrName) == sAttrVar ){
				oReturn = oOwner.childNodes[i];
				break;
			}
			else {
				oReturn = arguments.callee(oOwner.childNodes[i], sAttrName, sAttrVar);
				if ( oReturn != null )
					break;
			}
		}
	}
	
	return oReturn;
}

window.linking = function()
{
	location.href  = arguments[0];
}

function clearNaddParam(){
    var linkHref = document.URL.split('?')[0];
    
    for (var i = 0; i < arguments.length; i++) {
        linkHref += addSplit(linkHref) + arguments[i] + '=' + arguments[++i];
    }
    
    location.href = linkHref;
}

function clearNaddParamReturn(){
    var linkHref = arguments[0].split('?')[0];
    
    for (var i = 1; i < arguments.length; i++) {
        linkHref += addSplit(linkHref) + arguments[i] + '=' + arguments[++i];
    }
    
    return linkHref;
}


function addSplit(){
    var linkHref = arguments[0];
    
    if (linkHref.indexOf('?') == -1) 
        return '?';
    else 
        return '&';
}

function popWin() 
{
	var sUrl = arguments[0];
	var sQuery = arguments[1];
	var winName = arguments[2];
	var winOpt = arguments[3];
	
    var strUrl = sUrl + sQuery;
    window.open(strUrl, winName, winOpt);
}

/**
function 4 record 
**/

function requestList4Year()
{
	var iYear = arguments[0];	
	var data = 'meet_year=' + iYear;

	window.ajax.request('/record/incType4Year.aspx', data, responseList4Year);	
}

function requestList4Year_eng()
{
	var iYear = arguments[0];	
	var data = 'meet_year=' + iYear;

	window.ajax.request('/record/incType4Year_eng.aspx', data, responseList4Year_eng);	
}

function responseList4Year()
{
	if ( this.readyState == 4 ) {

		if (this.responseText.substring(0, 4) == 'Err:') {
			alert(this.responseText);
		}
		else {
			document.getElementById('incType4Year').outerHTML = this.responseText;
			
			requestList4DataType(document.getElementById('incOnly4Year2Select').options[document.getElementById('incOnly4Year2Select').selectedIndex].value, document.getElementById('incType4Year').options[document.getElementById('incType4Year').selectedIndex].value);
		}
	}
}

function responseList4Year_eng()
{
	if ( this.readyState == 4 ) {

		if (this.responseText.substring(0, 4) == 'Err:') {
			alert(this.responseText);
		}
		else {
			document.getElementById('incType4Year').outerHTML = this.responseText;
			
			requestList4DataType_eng(document.getElementById('incOnly4Year2Select').options[document.getElementById('incOnly4Year2Select').selectedIndex].value, document.getElementById('incType4Year').options[document.getElementById('incType4Year').selectedIndex].value);
		}
	}
}

function requestList4DataType()
{
	var iYear = arguments[0];
	var iSeq = arguments[1];	
	var data = 'meet_year=' + iYear + '&meet_seq=' + iSeq;

	window.ajax.request('/record/incDataType.aspx', data, responseList4DataType);	
}

function requestList4DataType_eng()
{
	var iYear = arguments[0];
	var iSeq = arguments[1];	
	var data = 'meet_year=' + iYear + '&meet_seq=' + iSeq;

	window.ajax.request('/record/incDataType_eng.aspx', data, responseList4DataType);	
}

function responseList4DataType()
{
	if ( this.readyState == 4 ) {

		if (this.responseText.substring(0, 4) == 'Err:') {
			alert(this.responseText);
		}
		else {
			if ( !(!document.getElementById('incDataType') ))
				document.getElementById('incDataType').outerHTML = this.responseText;
			
			runActivity();
		}
	}
}

function runActivity()
{
	if ( !(!window.ajaxList[0]) )
				window.ajaxList[0]();
}

function runAjax()
{
	document.getElementById(arguments[0]).style.filter='Alpha(Opacity=30);gray();';	
}

function popMatchReport()
{
	var qs = '?iMeet_Year=' + arguments[0] + '&iMeet_Seq=' + arguments[1] + '&iGame_Id=' + arguments[2];
	popWin('/matchcenter/popup_matchReport.aspx',qs, 'matchReport', 'width=1103,height=760,scrollbars=yes,resizable=yes')
}

function popMatchReport_Eng()
{
	var qs = '?iMeet_Year=' + arguments[0] + '&iMeet_Seq=' + arguments[1] + '&iGame_Id=' + arguments[2];
	popWin('/matchcenter/popup_matchReport_eng.aspx',qs, 'matchReport', 'width=1103,height=760,scrollbars=yes,resizable=yes')
}
