/**
 * CVIplayer.js
 *
 * Àü ÆäÀÌÁö °øÅë ½ºÅ©¸³Æ®
 *
 * @author  MIJIN KIM (hasa00-at-skcomms.co.kr)
 * @date    2008-05-28
 *  
 *  // 
***/


var optionsVal = {};

var xmlhttp = null;
var resp = "";

function getAjaxResponce(respObj)
{
//alert(respObj);
//alert(xmlhttp.readyState);
    if (xmlhttp.readyState == 4) 
	{
        if (xmlhttp.status == 200) 
		{
            var resp = xmlhttp.responseText;
            if (resp) 
			{
                var _items = resp;
//alert("_items = " + _items);			
                optionsVal = eval('(' + _items + ')'); //split(",")
                var respFunction = eval(respObj['method']);//CVIPlayerSetAndPlay()
//alert(respFunction);
                respFunction(respObj); 
            }
        }
    }
}


function XMLHTTPReq(method, _url, async, respObj){

    try { //ie6
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
        try { //ie4, ie5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            //xmlhttp = new ActiveXObject("Msxml2.XmlHttp.4.0");
        } 
        catch (E) {
            xmlhttp = false;
        }
    }
    
    // Mozilla, FireFox, Opera, Safari, Konqueror3
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();

		xmlhttp.open("GET", _url, true);//live
		xmlhttp.onreadystatechange = function(){
			getAjaxResponce(respObj)
		};
    } else {
		xmlhttp.onreadystatechange = function(){
   			getAjaxResponce(respObj)
		};
		xmlhttp.open("GET", _url, async);//dev, video upload
	}

    xmlhttp.send(null);
}


function callAjaxCVI(method, mov_id, mov_nm, usr_id, respObj){
    var url = "/_template/common/CyVideoInfra/VideoInfraInterface.php";
    url += "?MTH=" + method + "&mov_id=" + mov_id + "&mov_nm=" + mov_nm + "&usr_id=" + usr_id;

    XMLHTTPReq("GET", url, false, respObj);
}

function checkMajorParam(attPlayAreaId)
{
	
	if( eval(optionsVal['ERROR']) != 'undefind' && optionsVal['ERROR'] != null && optionsVal['ERROR'] != '' && optionsVal['ERROR'] != 'false')
	{
		//alert("Can't play the MOVIE, Try Again :" + optionsVal['ERROR']);
		CVIPlayAreaClear(attPlayAreaId);
		return false;
	}
	else if( optionsVal['VKEY'] == null || optionsVal['VKEY'] == '')
	{
		//alert("Can't play the MOVIE, Try Again : VKEY = " + optionsVal['VKEY']);
		CVIPlayAreaClear(attPlayAreaId);
		return false;	
	}
	else if( optionsVal['MOV_ID'] == null || optionsVal['MOV_ID'] == '')
	{
		//alert("Can't play the MOVIE, Try Again : MOV_ID = " + optionsVal['MOV_ID']);
		CVIPlayAreaClear(attPlayAreaId);
		return false;	
	}
	else
		return true;
}


function CVIPlayAreaClear(attPlayAreaId)
{
	var area;
	if (document.getElementById(attPlayAreaId)) 
		area = document.getElementById(attPlayAreaId);
	else if (document.getElementById("VideoPlayArea"))
		area = document.getElementById("VideoPlayArea");
	else
		return;
		
	CVIPlayerStop(area.id);
	area.innerHTML = "";
	return;
}

function CVIPlayerStop(attPlayAreaId)
{
	if (document.getElementById("player_"+attPlayAreaId)) 
	{
		var player = document.getElementById("player_"+attPlayAreaId);
		player.remote("stop");
	}
	return;
}
