var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null){
		LeftPosition=0;
		TopPosition=20
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=1,location=no,directories=no,status=0,menubar=no,toolbar=no,resizable=1';
	win=window.open(mypage,myname,settings);
}
function DrawImage(ImgD,FitWidth,FitHeight){
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		if(image.width/image.height>= FitWidth/FitHeight){
			if(image.width>FitWidth){
				ImgD.width=FitWidth;
				ImgD.height=(image.height*FitWidth)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		} else{
			if(image.height>FitHeight){
				ImgD.height=FitHeight;
				ImgD.width=(image.width*FitHeight)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
} 
function isDate(op, formatString){
	formatString = formatString || "ymd";
	var m, year, month, day;
	switch(formatString){
		case "ymd" :
			m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));
			if(m == null ) return false;
			day = m[6];
			month = m[5]*1;
			year =  (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));
			break;
		case "dmy" :
			m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));
			if(m == null ) return false;
			day = m[1];
			month = m[3]*1;
			year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));
			break;
		default :
			break;
	}
	if(!parseInt(month)) return false;
	month = month==0 ?12:month;
	var date = new Date(year, month-1, day);
      return (typeof(date) == "object" && year == date.getFullYear() && month == (date.getMonth()+1) && day == date.getDate());
	function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}
}

function ResizeImage(obj, MaxW, MaxH) {
	var imageObject;
	if (obj != null) imageObject = obj;
	var state=imageObject.readyState;
	var oldImage = new Image();
	oldImage.src = imageObject.src;
	var dW=oldImage.width; var dH=oldImage.height;
	if(dW>MaxW || dH>MaxH) {
	  a=dW/MaxW; b=dH/MaxH;
	  if(b>a) a=b;
	  dW=dW/a; dH=dH/a;
	}
	if(dW > 0 && dH > 0) imageObject.width=dW;imageObject.height=dH;
	if(state!='complete' || imageObject.width>MaxW || imageObject.height>MaxH) {
    setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",40);
	}
}