
var assetField;

//Foundation scripts
function confirmDelete()
 {
  if (confirm("Are you sure you want to delete this record?")) {
top.location.href="folders.asp?action=delete&record=1";
  }
}

function sendMessage(message)
{
	alert(message) 
}


function resetDate(whichField)
{
year2 = document.Main[whichField + "_year"].value;
month2 = document.Main[whichField + "_month"].value;
day2 = document.Main[whichField + "_day"].value;  
var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");  
var inpDate = day2 + month2 + year2;    
var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;  

//Check ddmmyyyy date supplied
if (! filter.test(inpDate))
  {
 	document.Main[whichField].value = '';
  }
/* Check Valid Month */    
filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;  
if (! filter.test(month2))   
  { 
  document.Main[whichField].value = '';  
  }
/* Check For Leap Year */
var N = Number(year2);   
if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
  	{   
   DayArray[1]=29; 
  	}
/* Check for valid days for month */
for(var ctr=0; ctr<=11; ctr++)
  	{   
   if (MonthArray[ctr]==month2)
   	{  
 if (day2<= DayArray[ctr] && day2 >0 )
   { 
   document.Main[whichField].value = month2 + "/" + day2 + "/" + year2;
   } 
 else
   { 
  document.Main[whichField].value = '';
   }
   	}
   }
}

function resetHour(whichField)
{
	hour2 = document.Main[whichField + "_hour"].value;
	minute2 = document.Main[whichField + "_minute"].value;
   document.Main[whichField].value = hour2 + ":" + minute2 + ":" + "00";
   
}

function confirmpassword(oForm) {
	string1 = oForm.Password.value;
	string2 = oForm.ConfirmPassword.value;
	if (string1 == string2) {
		return true;
	} else {
		alert("Try your passwords again.");
		oForm.Password.value='';
		oForm.ConfirmPassword.value='';
		return false;
	}
}

function jump(oSelect) {
	var url = oSelect.item(oSelect.selectedIndex).value;
	window.location.href= url;
	return false;
}

function validateForm(oForm) {
	var ok = true;
	for (var i = 0; i < oForm.length; i++) {
		var reqFlag = oForm.elements[i].id;
		var reqValue = oForm.elements[i].value;
       if ((reqFlag.indexOf("True") > 0) && (reqvalue==''))  {
	   	ok = false;
		}
   }
   if (!ok) { 
   	alert("Required information is missing."); 
	}
	return ok;
}

function launch(url,parameters) {
  self.name = "opener";
  remote = window.open(url, "remote", parameters);
}

function launchAssetManager(field) {
	assetField = field;
	parameters = "width=625,height=420,scrolling=no,resizable=no";
	launch("/editor/assetmanager/assetmanager2.asp",parameters);
}

function setAssetValue(url) {
	insertURL(assetField,url);
}



function insertURL (field,val) {
	//document.all.Main.elements[field].value= val;
	document.getElementById("Main").elements[field].value=val;
}

var activeFlyoutID;
var activeFlyoutIDX;
var activeFlyoutState;

function clearFlyouts() {
	if (activeFlyoutID!=undefined) {
		var myReference = getRefToDiv(activeFlyoutID,activeFlyoutIDX);
		var active = (myReference.status==undefined) ? activeFlyoutState : myReference.status;
		if (!active) {hideFlyout(activeFlyoutIDX);}
	}
}

function doNothing() {}

function getRefToDiv(divID,idx) {
	//customised to suit this particular page - DON'T COPY THIS UNLESS YOU KNOW WHAT YOU ARE DOING!!
	if( document.layers ) { return document.layers['menu'+ idx].document.layers[divID]; }
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	if( document['menu'+idx] ) { return document['menu'+ idx].document[divID]; }
	return false;
}

function showFlyout(idx,obj,divid,type) {

	var divobj = getRefToDiv(divid);
	var id = "flyout" + idx;
	var myReference = getRefToDiv(id,idx);
	if (!myReference) { return; }
	if (!isNaN(activeFlyoutIDX)) {hideFlyout(activeFlyoutIDX);}
	activeFlyoutID = myReference.id;
	activeFlyoutIDX = idx;
	myReference.status = true;
	moveFlyout(idx,obj,divobj,type);
	if( myReference.style ) { myReference.style.visibility = 'visible'; } else {
		if( myReference.visibility ) { myReference.visibility = 'show'; } else {
			 return; } }
}

function hideFlyout(idx) {
	var id = "flyout" + idx;
	var myReference = getRefToDiv(id,idx);
	if( !myReference ) { window.alert('trying to hide'); return; }
	if( myReference.style ) { myReference.style.visibility = 'hidden'; } else {
		if( myReference.visibility ) { myReference.visibility = 'hide'; } else {
			 return; } }
}


function moveFlyout(idx,obj,divobj,type) {
	var w = obj.offsetWidth;
	var h = obj.offsetHeight;
	var l = getObjX(divobj);
	var t = getObjY(divobj);
	
	var id = "flyout" + idx;
	var myReference = getRefToDiv(id,idx), noPx = document.childNodes ? 'px' : 0;
	if( !myReference ) { return; }
	if( myReference.style ) { myReference = myReference.style; }
	if (type=="down") {
		t = t+h;
	} else {
		l = l+w;
	}
	myReference.left = l + noPx; myReference.top = t + noPx;
}

function getObjX(obj) {
	var agt=navigator.userAgent.toLowerCase();
	var l = obj.offsetLeft;
	for (i=0;i<100;i++) {
		if ((obj.tagName=='TABLE') ||(obj.tagName=='TD')){
			l+= obj.offsetLeft;
		}
		if (agt.indexOf("firefox") != -1) {
			obj = obj.parentNode;
		} else {
			obj = obj.parentElement;
		}
		if (obj==null) {break;}
	}
	return l;
}

function getObjY(obj) {
	var agt=navigator.userAgent.toLowerCase();
	var t = obj.offsetTop;
	for (i=0;i<100;i++) {
		if ((obj.tagName=='TABLE') ||(obj.tagName=='TD')){
			t+= obj.offsetTop;
		}
		if (agt.indexOf("firefox") != -1) {
			obj = obj.parentNode;
		} else {
			obj = obj.parentElement;
		}
		if (obj==null) {break;}
	}
	return t;
}

function releaseFlyout(idx,state) {
	var id = "flyout" + idx;
	var myReference = getRefToDiv(id,idx);
	if( !myReference ) { return; }
	myReference.status = state;
	activeFyoutStatus = state;
}

function publish() {
	document.all.content_Description.innerHTML = document.all.content_Draft.innerHTML;
	document.all.Description.value = document.all.Draft.value;
}

function makedraft() {
	document.all.content_Draft.innerHTML = document.all.content_Description.innerHTML;
	document.all.Draft.value = document.all.Description.value;
}


