//////////////////////////////////// 
var toolVars = null;
//////////////////////////////////// 
function oPage( p, w, h, title ){
	if(!w) w = 440;
	if(!h) h = 260;
	if(!title) title = '';
	var features = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+w+',height='+h+',dependent=1';
	window.popUpWin = window.open(p, title, features);
	window.popUpWin.focus();
}
//////////////////////////////////// 
function writeFlash( xName, xPath, W, H, xVars, xTrasp, xScale, xResponse ){
	
	xVars += "&appExt=php&";
	strSwf = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' + '\r';
	strSwf += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ' + '\r'; 
	strSwf += 'width="' + W + '" height="' + H + '" id="' + xName + '" align="middle"> ' + '\r';
	strSwf += '<param name="FlashVars" value="' + xVars + '">' + '\r';
	if( xScale ) 				strSwf += '<param name="Scale" value="' + xScale + '">' + '\r';
	if( xTrasp==true ) 	strSwf += '<param name="wmode" value="transparent"> ' + '\r';
	strSwf += '<param name="allowScriptAccess" value="sameDomain"> ' + '\r';
	strSwf += '<param name="movie" value="' + xPath + '"> ' + '\r';
	strSwf += '<embed FlashVars="' + xVars + '"  ';
	strSwf += 'src="' + xPath + '" width="' + W + '" height="' + H + '" name="' + xName + '" align="middle" ' ;
	if( xScale ) 				strSwf += 'scale="' + xScale + '"  ';
	if( xTrasp==true ) 	strSwf += 'wmode="transparent" ';
	strSwf += 'swLiveConnect="true" ';
	strSwf += 'allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" /> ' + '\r';
	strSwf += '</object>';

	if( !xResponse ){
		document.write( strSwf );
	} else {
		return strSwf;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getDivStyle( xTg ){
	//////////////////////////////////// 
	var xDiv = document.getElementById(xTg);
	if( !xDiv ) return null;
	//////////////////////////////////// 
	if( document.layers ){ 
		return eval('document.'+xTg); 
	}else if( document.all ){ 
		return eval('document.all.'+xTg+'.style'); 
	}
	if( xDiv ) return xDiv.style;
	return null;
	//////////////////////////////////// 
}
//////////////////////////////////// 
function submitCommonForm( xForm, xURL ){
	var myForm = document.getElementById( xForm );
	if( xURL ){
		myForm.action = myForm.action + xURL;
	}
	myForm.submit();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// 


//////////////////////////////////////////////////////////////////////////////////////////////////////////// 
function carrelloTimerSubmit( xIDitem ){
	setTimeout("submitCommonForm('customForm"+xIDitem+"')", 1000); 
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// 



//////////////////////////////////////////////////////////////////////////////////////////////////////////// Cookie
function parseCookie() {
	//////////////////////////////////// 
	var cookieList = document.cookie.split("; ");
	var cookieArray = new Array();
	for (var i=0; i<cookieList.length; i++) {
		var name = cookieList[i].split("=");
		cookieArray[unescape(name[0])] = unescape(name[1]);
	}
	return cookieArray;
	//////////////////////////////////// 
}
function setCookie( strCookie ){
	//////////////////////////////////// 	
	var expireDate = new Date();
	expireDate.setDate(365 + expireDate.getDate());
	strCookie += "; expires=" + expireDate.toGMTString()+";"; 
	document.cookie = strCookie;
	//////////////////////////////////// 	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// 


//////////////////////////////////////////////////////////////////////////////////////////////////////////// 
function applyHandle( xHandle, xFunction ){
	if( document.layers ){ 		//NS
		document.body[xHandle] = xFunction;
	}else if( document.all ){ //IE
		document.body[xHandle] = xFunction;
	} else {									//MO
		this[xHandle] = xFunction;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////// 




//////////////////////////////////////////////////////////////////////////////////////////////////////////// DATE
function IsDate( xData ){
	////////////////////////////////////
	var d = xData.substring(0, 2);
	var m = xData.substring(3, 5);
	var y = xData.substring(6, 10);
	var valiDate = new Date();
	////////////////////////////////////
	if( xData.length>0 ){
		if( xData.length!=10 )	return false;
		if( isNaN(y) )	return false;
		valiDate.setYear( Number(y) );
		if( isNaN(m) || Number(m)>12 || Number(m)<1)		return false;
		valiDate.setMonth( Number(m) );
		var maxD = getDayInMonth( m, y );
		if( isNaN(d) || Number(d)>maxD || Number(d)<1 )		return false;
		valiDate.setYear( Number(y) );
		return true;	
	}
	return false;
	////////////////////////////////////
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getDayInMonth( xMonth, xYear ){
	////////////////////////////////////
	var myDate = new Date();
	if( !xYear ) xYear = myDate.getFullYear();
	myDate = new Date( xYear, 1, 1 ); 
	myDate.setMonth( xMonth-1 );
	////////////////////////////////////
	for( var i=27;i<=31; i++ ){
  	myDate.setDate( i ); 
		if( myDate.getDate()!=i ){
			return i-1;
		}
	}
	////////////////////////////////////
	return 31;
	////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////////////////////      
var SyncCalendar = {};
///////////////////////////////	
function getCalndarHere( xInput, xDateOnly, xDays ){
	///////////////////////////////	
	var ATCCalendar = document.getElementById("ATCCalendar");
	var ATCCalendarStyle = getDivStyle("ATCCalendar");
	var Args = {strDate:'', useDateOnly:xDateOnly};
	if( xInput.value!=ATC.EMPTYdate ){
		Args.strDate = xInput.value;
	}
	///////////////////////////////	
	SyncCalendar = new PROTO_Calendar( Args, {Div:ATCCalendar, DivStyle:ATCCalendarStyle, Input:xInput}, xDays );
	///////////////////////////////	
	var os = new Array( (xInput.offsetLeft - 1), (xInput.offsetTop - 1) );
	os = getOffsetPos( xInput, os );
	///////////////////////////////
	if( ATCCalendar ){	
		ATCCalendarStyle.display = '';
		ATCCalendarStyle.top = os[0] + 43;
		ATCCalendarStyle.left = os[1] - 20;
	}
	///////////////////////////////	
}  
////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getOffsetPos( xTg, xPos ){
	//////////////////////////////////// 
	if( xTg.offsetParent!=null ){
		xPos[0] += xTg.offsetParent.offsetLeft; 
		xPos[1] += xTg.offsetParent.offsetTop;
		xPos = getOffsetPos( xTg.offsetParent, xPos );
	}
	//////////////////////////////////// 
	return xPos;
	//////////////////////////////////// 
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////////// File Utility
function getFileExt( filePath ){
	var arrExt = filePath.split(".");
	if( arrExt.length>0 ) return arrExt[arrExt.length-1].toLowerCase(); 
	return '';
}
function getFileName( filePath ){
	filePath = filePath.replace(/\//ig,'\\');
	var arrPath = filePath.split("\\");
	if( arrPath.length>0 ) return arrPath[arrPath.length-1]; 
	return '';
}
/////////////////////////////////////////////////////////////////////////////////////////////
function getZeroName( xStr, xN ){
	///////////////////////////////
	var strLength = xStr.toString().length;
	if( strLength>=xN ) return xStr;
	var zeroStr = '00000000000000000000000000000000000000';
	return zeroStr.substring( 0, xN-strLength) + xStr.toString();
	///////////////////////////////
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////// 

