function addOption( selectType, vIndex, vText, vValue ){
	selectType.options[vIndex]=new Option(vText, vValue, true, true);//optionName;
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) { //v4.0
  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=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function fncLoad() {
	preloadImages('/img/btn_contactusA.gif','/img/btn_casestudiesA.gif','/img/btn_teleradiologyA.gif','/img/btn_ourservicesA.gif','/img/btn_aboutusA.gif')
}

// REMOVE IE LINK BOX //

function CSRemoveIEbox(){
if (document.images&&navigator.userAgent.indexOf("MSIE")!=-1){
	for(i=0;i<document.links.length;i++){
		target=eval("document.links[i]")
		target.onfocus=blurHandler
		}
	}
}

function blurHandler(){
obj=window.event.srcElement
if(obj.tagName == "A"||obj.tagName=="AREA") obj.blur()
}

// FORM VALIDATION
function fncSubmit(obj) {
	obj.sub_but.disabled=true; //DISABLE THE SUBMIT BUTTON
	//if (vrichtext=="yes") copyValues();
	var req=obj.required_fields;
	
	var submitflag=true;
	var notice="There was an error with your form:\n\n";
	if (req && req.value != "") {
		//Means the required fields are present, let's check for values
		var arrFields=obj.required_fields.value.split("|")
		for(var x=0; x<=arrFields.length-1; x++) {
			var arrName=arrFields[x].split(",");
			var str="if (obj."+arrName[0]+".value == '') { notice += '>>  "+arrName[1]+"\\n'; submitflag=false;}";
			eval(str);
		}
		notice += "\nPlease check these errors and resubmit!"
	} else {
		//Means there isn't a required fields parameter; keep going
	}
	if (submitflag) {
		if( obj.usingWysiwyg ){
			if( obj.usingWysiwyg.value=="true" ){
				updateRTEs();
			}
		}
		obj.submit();
	} else {
		alert(notice);
		obj.sub_but.disabled=false; //ENABLE THE SUBMIT BUTTON IF NOT SUBMITTED
	}
}

function fncSubmitDelete(obj) {
	obj.sub_but.disabled=true; //DISABLE THE SUBMIT BUTTON
	obj.submit();
}

// FORM VALIDATION
function fncSubmitMode(obj, mode) {
	
	var notice="There was an error with your form:\n\n";
	
	obj.page.value='1';
	obj.mode.value=mode;
	
	//alert(mode);
	
	obj.submit();
}

// FORM VALIDATION
function fncSubmitModePost(obj, mode) {
	
	var notice="There was an error with your form:\n\n";
	
	obj.method = "post";
	obj.action = "index.php?mode=delete";
	obj.page.value='1';
	obj.mode.value=mode;
	
	//alert(mode);
	
	obj.submit();

}

function fncSubmitSort(vSortBy, vSortDir) {
	
	var notice="There was an error with your form:\n\n";
	
	//alert( vSortBy );

	document.listform.mode.value='list';
	document.listform.sortDir.value = vSortDir;
	document.listform.sortBy.value = vSortBy;
	document.listform.submit();

	//alert(notice);

}

function fncSubmitPage( vPage ) {
	
	document.listform.mode.value='list';
	document.listform.page.value = vPage;
	document.listform.submit();

}


// POPUP CALENDAR
function fncPopCal(a,d) {
  win2=window.open("../classes/cal.asp?a="+a+"&dt="+d,"","width=215,height=175")
  win2.creator=self
}


// OPENS CENTERED POPUP WINDOW

function fncCenteredChildWindow(URL,vHeight,vWidth,vScroll,vStatus) {
	if (screen.width) {
		var winl=(screen.width-vWidth)/2;
		var wint=(screen.height-vHeight)/2;
	} else { 
		winl=0;wint=0;
	}
	if(winl<0)winl=0;
	if(wint<0)wint=0;
	window.open(URL,'myWin','height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus+',top='+wint+',left='+winl+',resizable=no')
}

// OPENS A CHILD WINDOW

function fncChildWindow(URL,vHeight,vWidth,vScroll,vStatus) {
  window.open(URL,'myWin','height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus)
}

//CheckBox
function fncCheckBox(vid, vfield, value){
	
	window.location="?mode=checked&id="+vid+"&field="+vfield+"&value="+value;
	
}

//////////////////////////////////////
//	selectAll						//
//	-used on list page to select.	//
//////////////////////////////////////

function selectAll(obj){

	count = obj.elements.length
	for (i=0; i<count; i++){
		if (obj.elements[i].name == 'batchselect[]' ){
			obj.elements[i].checked = obj.chkAll.checked;
		}
	}
	
}

function show(id,button){
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		el = document.getElementById(button);
		el.value = 'Hide Help';
	} else {
		el.style.display = 'none';
		el = document.getElementById(button);
		el.value = 'Need Help?';
	}
}

function setFormValue(field,n_value){
	document.getElementById(field).value = n_value;
}


function checkAllPermsX(prefix){

	//alert('here');

    chk_all = findObj(prefix+'_all');
    if(chk_all){
        new_state = chk_all.checked;

		chk_view = findObj(prefix+'_view');
		if(chk_view){
		    chk_view.checked = new_state;
		}

		chk_add = findObj(prefix+'_add');
		if(chk_add){
		    chk_add.checked = new_state;
		}

		chk_edit = findObj(prefix+'_edit');
		if(chk_edit){
		    chk_edit.checked = new_state;
		}

		chk_delete = findObj(prefix+'_delete');
		if(chk_delete){
		    chk_delete.checked = new_state;
		}

	}

}
