function popup(filename,caption, options){ 
var vOptions = options;
	if (vOptions ==null || vOptions.length == 0){
	vOptions = 'toolbar=no,location=no,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes,width=800,height=600';
	} 
var w = window.open(filename,caption,vOptions);
w.focus();
}
function popupFixed(filename,caption, w, h){ 
//String.Format("javascript:popupFixed('{0}','{1}', {2}, {3})",  sLink, sCaption, 700, 500)
var vOptions;
var l, t;	
if ((w==null) || (w.length == 0)){
	w=700;
} 
if ((h==null) || (w.length == 0)){
	h=500;
} 
t=(screen.availHeight-h)/2;
l=(screen.availWidth-w)/2;
if (isNaN(t) || t<0){
	t=50;
	h=screen.availHeight-100;
}
if (isNaN(l) || l<0){
	l=50;
	w=screen.availWidth-100;
}
	
vOptions = 'width='+ w + ',height='+ h + ',top='+ t + ',left=' + l + ', toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes';
var w = window.open(filename,caption,vOptions);
w.focus();
}

function popupFixedSimple(filename,caption, w, h){ 
//no bars and etc.
var vOptions;
var l, t;	

if ((w==null) || (w.length == 0)){
	w=700;
} 
if ((h==null) || (w.length == 0)){
	h=500;
} 
t=(screen.availHeight-h)/2;
l=(screen.availWidth-w)/2;
if (isNaN(t) || t<0){
	t=50;
	h=screen.availHeight-100;
}
if (isNaN(l) || l<0){
	l=50;
	w=screen.availWidth-100;
}
	
vOptions = 'width='+ w + ',height='+ h + ',top='+ t + ',left=' + l + ', toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no';
var w = window.open(filename,caption,vOptions);
w.focus();
}

function popupScrollable(filename,caption, w, h){ 
//no bars and etc.
var vOptions;
var l, t;	

if ((w==null) || (w.length == 0)){
	w=700;
} 
if ((h==null) || (w.length == 0)){
	h=500;
} 
t=(screen.availHeight-h)/2;
l=(screen.availWidth-w)/2;
if (isNaN(t) || t<0){
	t=50;
	h=screen.availHeight-100;
}
if (isNaN(l) || l<0){
	l=50;
	w=screen.availWidth-100;
}
	
vOptions = 'width='+ w + ',height='+ h + ',top='+ t + ',left=' + l 
vOptions += ', toolbar=yes,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes';
var w = window.open(filename,caption,vOptions);
w.focus();
}



function ShowHideImage(imgID,show){
var img;
img=document.getElementById(imgID);
	if (img!=null){
		if (show=='show'){
			img.className='ShowImage';
		}
		else{
			img.className='HideImage';
		}

	}

}

function GetKeyEvent(that, evt){
	//keyCode for IE; which for NS
	if ((evt.keyCode == 13) || (evt.which == 13)){
		return isDateOK(that.form)
		}
}		

function isDateOK(frm) {
// make regular expression as
//			month							day						year
//start(one or two numeric)(fSlash)(one or two numeric)(fSlash)(two or four numeric)end
var sDate
var re = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4}|\d{2})$/;
sDate=frm.txtDate.value
var matchArray = sDate.match(re); // is the format ok?
var month
var day
var year
//document.write(matchArray.length)
	if (matchArray==null){//entry does'not match pattern
		alert("Wrong Date");
		return false;	
	}	
	else{//entry  matches pattern
		month= matchArray[1]; // month
		day = matchArray[3];//day
		year = matchArray[5];//year		
		if ( month < 1 || month > 12) { 
			alert("Month must be between 1 and 12.");
			return false;
			}
		if (day < 1 || day > 31) {
			alert("Day must be between 1 and 31.");
			return false;
			}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			alert("This Month doesn't have 31 days.")
			return false;
			}
	
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) {
				alert("February " + year + " doesn't have " + day + " days.");
			return false;
			} 					  		   
		}
		return true;		
		}
}

function txtEmailKeyEvent(that, evt){
	//keyCode for IE; which for NS
	if ((evt.keyCode == 13) || (evt.which == 13)){
		return isEmailOk(that.form)
		}
}	

function isEmailOk (txtID) {
	var emailAddr;
	var txt;
	debugger;
	
	txt=document.getElementById(txtID);
	if (txt!=null){
		emailAddr = txt.value;
		//right trim address: any white space(s) at the end/global ==> to empty string
		emailAddr = emailAddr.replace(/\s+$/g, '')
			  
		if (!isEmailAddress(emailAddr)) {
			alert('Please enter correct email address!');
			txt.focus();
			txt.select();
			return false
		} 
		//  set new value in box
		txt.value = emailAddr
		return true;  
	}
	
}

function isEmailAddress (string) {
  var addressPattern =  /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  // test method returns true or false
  return addressPattern.test(string);
}

function PopulateGenericPrintingWindow(divToPrint) {
//debugger;
var PrintFrame;
this.document.all['Content'].innerHTML = parent.document.all[divToPrint].innerHTML;
  PrintFrame = parent.frames['HiddenPrintFrame'];
  if (PrintFrame) {
		// IE requires you to set focus first
		PrintFrame.focus();
		PrintFrame.print();
  }
}

function popupPrint(){
//no bars and etc.
var vOptions;
var sHTML;
debugger;
var sourceContent= window.document.getElementById("pnlContent");	
sHTML=sourceContent.innerHTML;
vOptions = 'toolbar=yes,location=no,directories=no,status=no,menubar=yes,resizable=no,copyhistory=no,scrollbars=no';
var w = window.open('PrintWindow.aspx','',vOptions);
w.focus();
//var destContent=w.document.getElementById('pnlPrintContent');
w.document.getElementById('pnlPrintContent').innerHTML=sHTML;
//w.print();
}

function swapDiv (show, hide) {
        document.getElementById(show).style.display = "block";
        document.getElementById(hide).style.display = "none";
}
