function swapImg(name,mode,comment){
	if(mode == 's'){
		document.images[name].src = 'images/'+name+'a.jpg';
	}else{
		document.images[name].src = 'images/'+name+'.jpg';
	}
}

function popup(imageFolder,page,type,w,h,val_1,val_2){
	if(type == 'img'){
		window.open(page+'?imageId='+val_1+'&propName='+val_2+'&imageFolder='+imageFolder, "popup", 'width='+w+',height='+h+',titlebar=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0');
	}
}

 
function datePop(type,w,h,val_1,val_2){
	window.open('scripts/calender.php?fieldName='+val_1, 'popup', 'width='+w+',height='+h+',titlebar=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,copyhistory=0');
}
function getDate(fieldName,type) {
	if(type == 'Clear Date'){
		document.getElementById(fieldName).value='';
		document.getElementById(fieldName+"Button").value='Pick Date';
	}else if(type == 'Pick Date'){
		datePop('cal',285,275,fieldName);
	}
}
function format(fieldName,table){
	var temp;
	tempFld = fieldName.replace(table, '');
	tempLtr = tempFld.substring(0,1);
	temp = tempLtr.toUpperCase()+tempFld.substring(1);
	return temp;
}

function validate(formData,tableName){
var message = "";	
	for (i=0;i<formData.length;i++) {
		temp = formData[i].name.split("_");
	if (temp[0] == ''){
		if ((temp[1] == 'date')&&(formData[i].value != '')&&(!Date.parse(formData[i].value))){
				message = message + ' - '+ format(temp[2],tableName) +' is not a valid date.\n\n';
		}else if ((temp[1] == 'num')&&(formData[i].value != '')&&(!parseInt(formData[i].value))){
				message = message + ' - '+ format(temp[2],tableName) +' is not a valid number.\n\n';
		}else if ((formData[i].type == 'textarea')&&(formData[i].value == '<p>&nbsp;<\/p>')){
				message = message + ' - '+ format(temp[2],tableName) +'.\n\n';	
		}else if ((formData[i].type == 'text')&&(formData[i].value == '')){
				message = message + ' - '+ format(temp[2],tableName) +'.\n\n';	
		}else if ((formData[i].type == 'password')&&(formData[i].value == '')){
				message = message + ' - '+ format(temp[2],tableName) +'.\n\n';	
		}else if ((formData[i].type == 'select-one')&&(formData[i].value == '')){
				message = message + ' - '+ format(temp[2],tableName) +'.\n\n';
		}else if ((formData[i].type == 'text')&&(temp[2] == 'Email')&&(formData[i].value != '')){
					var tempArray;
					var check = 0
					tempArray = formData[i].value.split("@");
						if (tempArray.length < 2){
						}else{
							check = check + 1;
							if (tempArray[0].length < 3){
							}else{
								check = check + 1;
								at = tempArray[1].split(".");
								if (at.length < 2){
								}else{
									check = check + 1;
									if(at[0] < 3){
									}else{ 
										check = check + 1;
									}
								}
							}
						}
				if (check != 4){
				message = message + " - Email Address is not a valid Email Address. \n\n";   
				} 
			}
		}
	}
	if (message.length != 0){
		alert("______________________________________________\n\n* The following "+tableName+" details must be completed *\n______________________________________________\n\n" + message+"\n");
		return false;
	}else{	
		return true;
	}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}