//open a new window with a set style 
function openwindow(url) {
	if (url) {
		var newwindow = window.open(url,'', 'copyhistory=no,toolbar=yes,width=800,height=550,scrollbars=yes,status=yes,resizable=yes');
	}		
}


function openwindowsizedscroll(url,x,y) {
	if (url) {
		//alert(url);
		var sprop = "'copyhistory=no,scrollbars=yes,toolbar=yes,width=" + x + " height=" + y + " ,status=no,resizable=yes'"
		if(parent.window.newwindow){
		
		} else {
			var displaywindow = window.open(url,'', sprop);
		}
	}		
}

//check if fileexists
function checkuploadfile(filenamelist,filepath) {
	var agree = false;
	var filename = ''; 
	var afilenamelist = new Array();
	var i = 0;	
	var ifilelen = 0;
	
	ifilelen = filepath.lastIndexOf("\\");	
	filename = filepath.substring(ifilelen + 1)
	afilenamelist = filenamelist.split(',');
	do{
		if(filename == afilenamelist[i]){
			agree = confirm('replace this record?')	
			if ( agree ){
				return true;
			}else{
				return false;
			}			
		}
	} while (++i < afilenamelist.length);
}



//redirect to a supplied url
function doredirect(href){
	//needs to do write for ie to wk
	//document.write('doing redirect....')
	window.self.location = href;
}


//execute required code
function doExecCode(vcode){
alert(vcode);
	eval(vcode)
}

//confirm a delete
function confirmdelete(vcode) {
	var agree = false;
	agree = confirm('delete this record?')
	if ( agree )
		doredirect(vcode);
}

//confirm a back out
function confirmbackout(href) {
	var agree = false;
	agree = confirm('Back out the last respondent upload?')
	if ( agree )
		doredirect(href);
}

//confirm reset points
function confirmresetpoints(href) {
	var agree = false;
	agree = confirm('Reset respondents points to zero?')
	if ( agree )
		doredirect(href);
}

//confirm send questionnaire
function confirmsendquestion(href) {
	var agree = false;
	agree = confirm('Are you sure you want to send the email?')
	if ( agree )
		doredirect(href);
}

//confirm send questionnaire
function confirmsendreminder(href) {
	var agree = false;
	agree = confirm('Are you sure you want to send the reminder?')
	if ( agree )
		doredirect(href);
}

//confirm send questionnaire
function confirmsendsummary(href) {
	var agree = false;
	agree = confirm('Are you sure you want to send the summary?')
	if ( agree )
		doredirect(href);
}

//check a date entry
function isValidDate(sDate) {
	//alert(sDate)
	var datePattern = /^(\d{1,2})(\/|)(\d{1,2})\2(\d{2}|\d{4})$/;
	var dateArray = sDate.match(datePattern); // is the format ok?
	//check has a value
	if (dateArray == null) {
		alert("Date is not in a valid format.")
	return false;
	}
	day = dateArray[1];
	month = dateArray[3];
	year = dateArray[4];
	//day
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
	//month
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
	return false;
	}
	//check number of days in month
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
	return false
	}
	// check for february 29th
	if (month == 2) { 
		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;  // date is valid
}

function changeimage(psimagename,psimagesrc){
	eval('document.' + psimagename + '.src = "' + psimagesrc + '"')
}

function OpenPopUpWindow(url)
{
window.open(url,'PopUpWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,Width=700,height=400,screenX=150,screenY=150,top=150,left=150')
}

