
// if the date format is m/d/yyyy or mm/d/yyyy , we convert it to mm/dd/yyyy
function convertDateTo10Char(inDate)
{
	var dateBits = new Array();
	dateBits = inDate.split("/");
	if (dateBits[0].length == 1)
    	{
    		dateBits[0] = "0" + dateBits[0];
    	}
	
	if (dateBits[1].length == 1)
    	{
    		dateBits[1] = "0" + dateBits[1];
    	}

	if (dateBits[2].length == 1)
    	{
    		dateBits[2] = "0" + dateBits[2];
    	}

	return dateBits[0]+"/"+dateBits[1]+"/"+dateBits[2];

}

//to verify the date has 2 '/' in it, return true means BAD format
function DateFormatNotCorrect(inDate)
{
	if (inDate.indexOf("/") > 0)
	{
    		inDate = inDate.substring(inDate.indexOf("/")+1, inDate.length);
		if (inDate.indexOf("/") > 0)
			return false;
		else
			return true;

    	}
    	else
    	return true;
    
}

// This function takes a layer's id as input and 
// switches it from visible to invisible or vica versa
function alternateLayerVisibility(whichLayer) {
	
	var layer;
	
	if (document.getElementById) {		
		// this is the way the standards work

		layer = document.getElementById(whichLayer);
		if(layer.style.visibility == "visible" || layer.style.visibility == "") {
			hideNavLayer(whichLayer);			
		}
		else {
			showNavLayer(whichLayer);
		}
	}
	else if (document.all) {
	// this is the way old msie versions work
		layer = document.all[whichlayer];

		if(layer.style.visibility == "visible" || layer.style.visibility == "") {
			hideNavLayer(whichLayer);
		}
		else {
			showNavLayer(whichLayer);
		}		
	}
	else if (document.layers) {
	// this is the way nn4 works
		layer = document.layers[whichLayer];
		
		if(layer.style.visibility == "visible" || layer.style.visibility == "") {
			hideNavLayer(whichLayer);
		}
		else {
			showNavLayer(whichLayer);
		}
	}
}

function hideNavLayer(whichLayer) {

	if (document.getElementById) {
	// this is the way the standards work
	document.getElementById(whichLayer).style.visibility = "hidden";	
	document.getElementById(whichLayer).style.position = "absolute";
	}
	else if (document.all) {
	// this is the way old msie versions work
	document.all[whichlayer].style.visibility = "hidden";
	}
	else if (document.layers) {
	// this is the way nn4 works
	document.layers[whichLayer].visibility = "hidden";
	}

}

function showNavLayer(whichLayer) {
	if (document.getElementById) {
	// this is the way the standards work
	document.getElementById(whichLayer).style.visibility = "";
	document.getElementById(whichLayer).style.position = "";	
	}
	else if (document.all) {
	// this is the way old msie versions work
	document.all[whichlayer].style.visibility = "";
	document.all[whichlayer].style.position = "";	
	}
	else if (document.layers) {
	// this is the way nn4 works
	document.layers[whichLayer].visibility = "";
	//document.layers[whichLayer].position = "";	
	}

}

function check_uncheck_all(field,object)
{
	if(field != null) {
		field.checked=object.checked;			
	
		for (i = 0; i < field.length; i++)
			field[i].checked = object.checked ;
	}		
}

function postToLayer(whichLayer,content,frame) {
	if (frame.document.getElementById) {	
		frame.document.getElementById(whichLayer).innerHTML = content;
	}
	else if (frame.document.all) {	
		frame.document.all[whichlayer].innerHTML = content;
	}
	else if (frame.document.layers) {
		lyr.open()
		lyr.write(content)
		lyr.close()
	}
}

/*
Set the mouse cursor to an hour glass icon in the given frame
*/
function setPointerBusy(frame) {
    if (frame.document.all)
        for (var i=0;i < frame.document.all.length; i++)
             frame.document.all(i).style.cursor = 'wait';
}

/*
Reset the mouse pointer to the default icon
*/
function resetPointerFrame(frame) {
    if (frame.document.all)
        for (var i=0;i < frame.document.all.length; i++)
             frame.document.all(i).style.cursor = '';	
}

/*
Set the mouse cursor to an hour glass icon
*/
function setPointerBusy() {
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = 'wait';
}

/*
Reset the mouse pointer to the IE's default icon
*/
function resetPointer() {
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = '';
}

/*
Reset the mouse pointer to the pointer icon
*/
function setPointerBlank() {
    if (document.all)
        for (var i=0;i < document.all.length; i++)
             document.all(i).style.cursor = 'default';
}

/*
Reset the mouse pointer to the pointer icon
*/
function setPointerBlankFrame(frame) {
    if (frame.document.all)
        for (var i=0;i < frame.document.all.length; i++)
             frame.document.all(i).style.cursor = 'default';
}

/*
Converts src of images with id image from node_open to node_closed or vica versa
*/
function alternateNodeHandle(image) {
	alternateImageBasedOnState(image,"/common/resources/shared/images/node-closed.gif","/common/resources/shared/images/node-open.gif","closed","open");
}

function alternateImageBasedOnState(image,one_src,two_src,state_one,state_two) {
	
	var object
	
	if (document.getElementById) {
	// this is the way the standards work
		object = document.getElementById(image);
	}
	else if (document.all) {
	// this is the way old msie versions work
		object = document.all[image];
	}
	else if (document.layers) {
	// this is the way nn4 works
		object = document.layers[image];
	}
	
	if (object.object_state == state_one) {
		object.src = two_src;
		object.object_state = state_two;
	}
	else {
		object.src = one_src;	
		object.object_state = state_one;
	}			
}

function window_popup(name,url,width,height,scrollbars,resizeable){
	a=window.open(url,name,'width=' + width + ',height=' + height + ',screenX=100,screenY=100,resizable=' + resizeable + ',scrollbars=' + scrollbars + ',dependent=yes');
}

function controls_to_form_field(control_name,hidden_field) {
	var temp;		
	temp="";
	if(control_name != null) {		
		if (typeof control_name.value != "undefined") {				
			temp = control_name.value;
		}
		else {
			for (i = 0; i < control_name.length; i++) {
				if(control_name[i].checked)				
					temp = temp + control_name[i].value + ',';
				}		
		}
	} else {
		if (control_name.checked)
			temp = control_name.value;	
	}			
	hidden_field.value=temp;
}

function object_move(workspace_id,from_object_id) {
	object_custom_move(workspace_id,from_object_id,document.subobjects.object_id);
}
	
function object_custom_move(workspace_id,from_object_id,source_data) {
	var temp;		
	temp="";
	control_name = source_data;

	if(control_name) {		
		if(control_name != null) {		
			if (typeof control_name.value != "undefined") {
	//			alert('singleton');
				temp = control_name.value + ',';
			}
			else {
	//			alert('else');
				for (i = 0; i < control_name.length; i++) {
					if(control_name[i].checked)
						temp = temp + control_name[i].value + ',';
					}		
			}
		} else {
			if (control_name.checked)
				temp = control_name.value;	
		}
	}

	temp = temp.substring(0,temp.length-1);
	if(!temp.length) {
		alert(JS_message1);
	}
	else {
		window_popup('move','/objects/browse.cfm?workspace_id=' + workspace_id + '&return_to=' + escape('/objects/move.cfm?source_ids=' + temp + '&parent_id=' + from_object_id) + '&action_type=move',400,400,'yes','yes');
	}
}

function object_move_to_swf_destination(workspace_id, from_object_id, to_object_id) {
	var temp;		
	temp="";
	control_name = subobjects.object_id;
	if(control_name) {		
		if(control_name != null) {		
			if (control_name.value != null) {
	//			alert('singleton');
				temp = control_name.value + ',';
			}
			else {
	//			alert('else');
				for (i = 0; i < control_name.length; i++) {
					if(control_name[i].checked)
						temp = temp + control_name[i].value + ',';
					}		
			}
		} else {
			if (control_name.checked)
				temp = control_name.value;	
		}
	}
	temp = temp.substring(0,temp.length-1);
	if(!temp.length) {
		alert(JS_message1);
	}
	else {
		document.location='/objects/move.cfm?workspace_id=' + workspace_id + '&source_ids=' + temp + '&parent_id=' + from_object_id + '&destination_id=' + to_object_id;
	}
}

function workflow_add_destination(workspace_id, object_id) {
	window_popup('move','/objects/browse.cfm?workspace_id=' + workspace_id + '&return_to=' + escape('/objects/content_folder/workflow_destination_add.cfm?object_id=' + object_id) + '&action_type=workflow_add',400,400,'yes','yes');
}

function workflow_remove_destination(workspace_id, object_id) {
	controls_to_form_field(temp_selected_parties,parties.selected_parties);parties.submit();
}

function object_copy(workspace_id,from_object_id) {

	var temp;		
	temp="";
	control_name = document.subobjects.object_id;
	if(control_name) {		
		if(control_name != null) {		
			if (typeof control_name.value != "undefined") {
	//			alert('singleton');
				temp = control_name.value + ',';
			}
			else {
	//			alert('else');
				for (i = 0; i < control_name.length; i++) {
					if(control_name[i].checked)
						temp = temp + control_name[i].value + ',';
					}		
			}
		} else {
			if (control_name.checked)
				temp = control_name.value;	
		}	
	}
	temp = temp.substring(0,temp.length-1);
	if(!temp.length) {
		alert(JS_message2);
	}
	else {
		window_popup('copy','/objects/browse.cfm?workspace_id=' + workspace_id + '&return_to=' + escape('/objects/copy.cfm?source_ids=' + temp + '&parent_id=' + from_object_id) + '&action_type=copy',400,400,'yes','yes');
	}
}

// for IM ContactList window
function launchContactListWindow()
{
	winwidth = 238; // width of the new window
     	winheight = 310; // height of the new window
	winleft = (screen.width / 2) - (winwidth) ; // center the window right to left
	wintop = (screen.height / 2) - (winheight); // center the window top to bottom
	
	var features = 'toolbar=0,scrollbars=0,location=0,frameborder=no,border=0,status=0,menubar=0';
	features += ',height=' + winheight + ',width=' + winwidth+',top=' + wintop + ',left=' + winleft ;
	windowHandle = window.open('/im/IM_show_contact_list.cfm?chat_with=','contactListWindow',features);
}

// for IM ContactList then begin  chat with user
function launchContactListWindow2( chat_with )
{
	winwidth = 238; // width of the new window
     	winheight = 310; // height of the new window
	winleft = (screen.width / 2) -(winwidth/2); // center the window right to left
	wintop = (screen.height / 2) - (winheight); // center the window top to bottom

	var features = 'toolbar=0,scrollbars=0,location=0,frameborder=no,border=0,status=0,menubar=0';
	features += ',height=' + winheight + ',width=' + winwidth+',top=' + wintop + ',left=' + winleft ;
	windowHandle = window.open('/im/IM_show_contact_list.cfm?chat_with='+chat_with,'contactListWindow',features);
}


//for Converting PowerPoint to Flash , then show progress bar
function launchProgressBarWindow()
{
	winwidth = 600; // width of the new window
	winheight = 150; // height of the new window
	winleft = (screen.width / 2) - (winwidth/2) ; // center the window right to left
	wintop = (screen.height / 2) - winheight-30; // center the window top to bottom
	var features = 'toolbar=0,scrollbars=0,location=0,frameborder=no,border=0,status=0,menubar=0';
	features += ',height=' + winheight + ',width=' + winwidth+',top=' + wintop + ',left=' + winleft ;
			
	progressHandle = window.open('/rtc/progress.cfm','progressWindow',features);	
	progressHandle.focus();
}
//close the window opened above
function closeProgressBarWindow()
{
	closeHandle=window.open('','progressWindow');	
	closeHandle.close();
}



function show_av_clip(unique_av_id, flashcom_ip, enable_ssl)
{
	if(flashcom_ip == null)
	{
		flashcom_ip="192.168.1.10";
	}

	if(enable_ssl == null)
	{
		enable_ssl="0";
	}
	
	var av_div=getDiv(unique_av_id);
	if (av_div.style.display == "none")
	{
		if(av_div.innerHTML =="&nbsp;")
		{
			 base_url="flashcom_server_ip="+flashcom_ip+"&enable_ssl_flashcom="+enable_ssl+"&unique_id="+unique_av_id;
			 av_div.innerHTML='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH=215 HEIGHT=241 id=av_recorder ALIGN= >';
			 av_div.innerHTML+='<PARAM NAME=movie VALUE="/im/av_recorder.swf?'+base_url+'"> <PARAM NAME=quality VALUE=high> ';
			 av_div.innerHTML+='<PARAM NAME=bgcolor VALUE=#FFFFFF> ';
			 av_div.innerHTML+='<EMBED src="/im/av_recorder.swf?'+base_url+'" quality=high bgcolor="#FFFFFF" WIDTH=215 HEIGHT=241 NAME=av_recorder ALIGN=  TYPE=application/x-shockwave-flash></EMBED>';
			 av_div.innerHTML+='</OBJECT>';
		}
		av_div.style.display = "";
	}
	else
	{
		av_div.style.display = "none";
	}
}
function getDiv(name)
{
	if (document.all)
	return document.all(name);
	else if( document.layers)
	return document.layers[name];
	else
	return "CANNOT GET DIV";

}

function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style)
    link.style.cursor = 'default';
}
function enableLink (link) {
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style)
    link.style.cursor = 
      document.all ? 'hand' : 'pointer';
}
function toggleLink (link) {
  if (link.disabled) 
    enableLink (link)
  else 
    disableLink (link);
  link.disabled = !link.disabled;
}



var is_popup_calendar;