/********************************************************************************************************************************************
*
* Description	:	Class for comment functions library
* Author		:	LCH
* Create Date	:	2006.10.13
*
********************************************************************************************************************************************/
function CCF()
{	
	//{{ Method
	//
	this.CreateOption	;
	this.CreateWindow	;
	
	// Xml operation	
	this.LoadXmlFile	;		
	
	//
	this.Alert			;

	// File name operation
	//
	this.GetFileExType	;
	this.GetFileName	;
	
	
	//
	this.GetObject		;
	this.GetParentObject;
	this.GetParentObjectEx;
	
	//
	this.GetRadioCheckValue;
	this.SetRadioCheckValue;
	
	this.FocusTextBox;
	this.TextBoxLength;
	
	// Exe file by xml
	this.ExeFile		;
	
	//
	this.ConvertTimeToNormal;
	
	//
	//}}
	
	//
	// Porperty
	//
	this.m_oXmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
	
	
	//
	this.JsReplace;
	
	//
	this.CreateWindowX;
	
	
	//
	this.oAjaxXmlHttp	=new ActiveXObject('Microsoft.XMLHTTP');
	this.AjaxCreate;
	this.AjaxCreatePostData;
}

/*
 *
 */
CCF.prototype.AjaxCreatePostData=function(vsrc,vfun,vinfo)
{
	var vURL=vsrc;
	this.oAjaxXmlHttp.open('POST',vURL,true);// async request -------------->> WEB 2.0 AJax
	this.oAjaxXmlHttp.setRequestHeader("content-length",vinfo.length);
	this.oAjaxXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
	this.oAjaxXmlHttp.onreadystatechange=vfun;
	this.oAjaxXmlHttp.send(vinfo);	
}



/*
 *
 */
CCF.prototype.ConvertTimeToNormal=function(vTimex)
{
	// one hour
	var vHour=1*60*60;
	
	// one minute
	vMinute=1*60;
	
	// hour
	var vH=parseFloat(vTimex)/parseFloat(vHour);	
	var vHx=(new String(vH)).split('.')[0];
	var vHxx='0.'+(new String(vH)).split('.')[1];	
	
	// minute
	var vM=parseFloat(vHxx)*vHour/parseFloat(vMinute);	
	var vMx=(new String(vM)).split('.')[0];
	var vMxx='0.'+(new String(vM)).split('.')[1];
	
	// second	
	var vS=new String(parseInt(parseFloat(vMxx)*vMinute));
	
	// process format
	if(vHx.length<2)
		vHx='0'+vHx;
	if(vMx.length<2)
		vMx='0'+vMx;
	if(vS.length<2)
		vS='0'+vS;
	
	// ok	
	return (vHx+':'+vMx+':'+vS);
}

/*
 *
 */
CCF.prototype.AjaxCreate=function(vsrc,vfun)
{
	var vURL=vsrc;
	this.oAjaxXmlHttp.open('GET',vURL,true);// async request -------------->> WEB 2.0 AJax
	this.oAjaxXmlHttp.onreadystatechange=vfun;
	this.oAjaxXmlHttp.send();	
}

/*
 *
 */
CCF.prototype.CreateWindowX=function(vsrc,vcx,vcy)
{
	// Attach window object
	//
    var vWin=window.document.all('ID_WIN_X');

	// Jump 
    vWin.innerHTML='<iframe id=ID_WIN_EX frameborder=0  width=100%; height=100%; scrolling=no src=/tv/win.aspx?vsrc='+vsrc+' ></iframe>';
    
    // Adjust window position
    //
	var vX=document.body.scrollLeft+event.x;//-10;
	var vY=document.body.scrollTop+event.y+11;    
	vWin.style.left=vX-vcx/2;
	vWin.style.top=vY;
	vWin.style.width=vcx;
	vWin.style.Height=vcy;
    
    // View
    vWin.style.display='';
}

CCF.prototype.JsReplace=function(str,search, replace)
{
	var regex = new RegExp(search, "g");
	return str.replace(regex, replace);
}

//
CCF.prototype.TextBoxLength=function(vStrLen,vMaxLen,vMinLen)
{
	if(vStrLen>=vMinLen && vStrLen <=vMaxLen)
	{
		return true;
	}
	else
		return false;
}
//
CCF.prototype.FocusTextBox=function(vo)
{
	vo.select();
	vo.focus();
}


// Exe a file by xml
//
CCF.prototype.ExeFile=function(vURL)
{
	this.m_oXmlHttp.open('GET',vURL,false);//sync request -------------->> WEB 2.0 
	this.m_oXmlHttp.send();	
}

// Get a value from radio input element
//
CCF.prototype.GetRadioCheckValue=function(vo)
{
	// One
	//
	if(isNaN(parseInt(vo.length)))
	{
		return vo.value;
	}
		
	// More ...
	var v;
	for(var i=0;i<vo.length;i++)
	{
		if(vo[i].checked)
		{
			v=vo[i].value;
			break;
		}
	}
	
	//
	return v;
}

// Set a value from radio input element
//
CCF.prototype.SetRadioCheckValue=function(vo,vx)
{
	for(var i=0;i<vo.length;i++)
	{
		if(vo[i].value==vx)
		{
			vo[i].checked=true;
			break;
		}
	}
}

// Get a object by id
//
CCF.prototype.GetObject=function(vId)
{
	try
	{
		return window.document.all(vId);
	}
	catch(ex)
	{
		return null;
	}
}

// Get a object by id
//
CCF.prototype.GetParentObject=function(vParent,vId)
{
	return eval('window.'+vParent).document.all(vId);
}

// Get a object by id
//
CCF.prototype.GetParentObjectEx=function(vId)
{
	return window.parent.document.all(vId);
}

// 在 SELECT 对象的特定位置添加一列
//
CCF.prototype.CreateOption=function(voSel/* SELECT 对象 */,vPos/* 插入的位置(0,1,2...) */,vText,vValue)
{
	//
	var oOption = window.document.createElement("OPTION");
	voSel.options.add(oOption,vPos);
	oOption.innerText = vText;
	oOption.value = vValue;	
}

// Open a new IE WINDOW
//
CCF.prototype.CreateWindow=function(vUrl)
{
	window.open(vUrl);
}

// Load xml file from url
//
CCF.prototype.LoadXml=function(vUrl)
{	
	// Get data by Microsoft XML Http request
	//
	try
	{
		var vURL=vUrl;
		this.m_oXmlHttp.open('GET',vURL,false);// sync request -------------->> WEB 2.0 AJax
		this.m_oXmlHttp.send();	
		return	this.m_oXmlHttp.responseXML;//OK				
	}
	catch(ex)
	{
	}
}

// Alert
//
CCF.prototype.Alert=function(vs)
{
	window.alert(vs);
}


/*
 * Get file name
 */
 function CCF.prototype.GetFileName(vFilePath)
 {
	if(vFilePath.indexOf('\\')==-1)
		return '';
	
	//
	var varPath=vFilePath.split('\\');
	var vFilename=varPath[varPath.length-1];
	return vFilename;	// File name ,here
 }
 
/*
 * Get file extention type
 */
 function CCF.prototype.GetFileExType(vFilePath)
 {
	if(vFilePath.indexOf('.')==-1)
		return '';
	
	//
	var varPath=vFilePath.split('.');
	var vFileExname=varPath[varPath.length-1];
	return vFileExname;	// File name ,here
 }
 
 /*
  * Global var
  */
 var g_vCcf=new CCF();  

//
window.document.write('<span id=ID_WIN_X  style="Z-INDEX: 0; POSITION: absolute;　display:none;"></span>');	// Pop window 
