// JavaScript Document
function createEditor(id,obj_id,obj_type,link_type,value,height){
	if (document.all){
		var idGenerator = new IDGenerator(id);
		if (isNaN(height)) height=200;

		var editor = new Editor(idGenerator,link_type,obj_id,obj_type,value,height);
		editor.Instantiate();
	}else{
		document.write("Sorry! your browser does not support this action. Please use Internet Explorer.")
	}
	return true;
}

function popWin(url,width,height,windowName,scrollbar,content){
	var x=(screen.width)?(screen.width-width)/2:100;
	var y=(screen.height)?(screen.height-height)/2:100;

	var features="width="+width+"px,height="+height+"px, top="+y+"px, left="+x+"px";
		features+=(scrollbar)?",scrollbars=yes":"";
	if (!windowName){
		windowName="untitled";
	}
	var popWindow=window.open(url, windowName, features);

	if (popWin.arguments.length==6&&content!=""){
		popWindow.document.write(content);
	}
	if (document.layers){
		window.moveTo(x, y);
	}
	popWindow.focus();
}
function checkForm(frm, arr_ctrl) {

	var count= arr_ctrl.length ;
	var i=0  ;
	for(i=0; i< count; i++) {
		func= trim( arr_ctrl[i][0] ) ;
		if( eval( func ) ) { //== 
			alert( arr_ctrl[i][1] ) ;
			if( arr_ctrl[i][2] != "" )
				eval( "frm."  + arr_ctrl[i][2] ).focus() ;
			return false ; //== Error
		}
	}
	return true ; //== OK
}

function isEmail(s){
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/) != -1)
		return true ;
	return false ;
}
function isString(s){ 
	if (s.search(/^[A-Za-z\s]+$/) != -1)
		return true ;
	return false ;
}
function checkImage(img)
{
	if (img.search(/\.((gif)|(GIF)|(jpg)|(JPG)|(bmp)|(BMP)|(pnp)|(PNP))\b$/) != -1)
		return true ;
	return false ;
}

function trim(str) {
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isNegative(str) {
	if( isNaN(str) || str <= 0 )
		return true ;
	return false ;
}

function isBlank(str) {
	if( str == "" ) 
		return true ;
	return false ;
}
function open_calendar(frm_name,frm_field,func)
{
	if(!func)
		func=""
	var url="calendar/calendar.htm#"+frm_name+"="+frm_field +"="+func
	popWin(url,300,250,"calendar","no","")
		//popWin(url,width,height,windowName,scrollbar,content)

}
function isDate(date,type){
	if (!(type==0||type==1||type==2)) {alert("Please specify date type in check form function!"); return false;}
	var day, month, year;
	var dateText=new Array("null","january","february","march","april","may","june","july","august","september","october","november","december");
	var thisdate=trim(date);
	
	//validate basic format
	var dateType=new Array();
	dateType[0]=/^\d{1,2}(\-|\/|\.|\s)\d{1,2}(\-|\/|\.|\s)\d+$/;	//date format dd mm yyyy
	dateType[1]=/^\d{1,2}(\-|\/|\.|\s)\d{1,2}(\-|\/|\.|\s)\d+$/;	//date format mm dd yyyy
	dateType[2]=/^\d{1,2}(\-|\/|\.|\s)\w{3,9}(\-|\/|\.|\s)\d+$/;	//date format dd mmmm yyyy
	if (thisdate.search(dateType[type])==-1) return false;
	
	var seperator=(thisdate.indexOf("-")!=-1)?"-":(thisdate.indexOf("/")!=-1)?"/":(thisdate.indexOf(".")!=-1)?".":(thisdate.indexOf(" ")!=-1)?" ":"";
	if (seperator=="") return false;	//no seperator

	var dateParam=thisdate.split(seperator);
	if (dateParam.length!=3) return false;	//use difference seperator
	
	//day month year from date string
	day=dateParam[0]; 
	year=dateParam[2];
	switch (type){
		case 0:
			month=dateParam[1];
		break;
		case 1:
			day=dateParam[1];
			month=dateParam[0];
		break;
		case 2:
			month=inArray(dateParam[1].toLowerCase(),dateText);
		break;
	}
	if (!month) return false;
	if (!senseDate(day,month,year)) return false;	
	return true;
}


function inArray(itemToCheck,targetArray){
	var i=-1; var result=false;
	if (!isArray(targetArray)) return false;
	while ((i<targetArray.length-1)&&(!result)){
		i++;
		result=(targetArray[i].indexOf(itemToCheck)!=-1)?true:false;
	}
	if (result) return i;
	return false;
}

function isArray(obj){
	if (obj.constructor.toString().indexOf("Array")==-1)
		return false;
	return true;
}

function senseDate(day,month,year){ 
	if ((day<1)||(day>31)) return false;
	if ((month<1)||(month>12)) return false;
	if ((year<1000)||(year>3000)) return false;
	if ((month==2)&&(day>29)) return false;
	if (((month==4)||(month==6)||(month==9)||(month==11))&&(day>30)) return false;
	if ((month==2)&&(day==29)){
		var div4=year%4;
        var div100=year%100;
        var div400=year%400;
		if (div4!=0) return false;
		if ((div100==0)&&(div400!=0)) return false;
	}
	return true;
}