// <![CDATA[

var dcs = new dcs();


function dcs()
{	
	this.third_party = 'DCS';
	
//	this.dsp_host = 'ad.dev.designcentersearch.com';
	this.dsp_host = 'shopad.net';
	
	this.truque_client = 'SHOPAD'; 

	//uncomment these two lines for designsearchpro.com
	this.dsp_path = '';
	this.artwork_path = '';

	this.selectedTabIndex = 1;
	
	this.eye_context = '';
	this.eye_context_params = '';
	
	
	 this.loadTruqueContent = function(truqueID, ref_type, ref_id, tab_index)
	 {
		if ($('truqueDiv'+truqueID).style.display == 'block')
		{
			var cookie = dcs.GetCookie('DCSTRUQUEGUID');
			
		 	new Ajax.Updater('truqueDiv'+truqueID, dcs.dsp_path+'/dsp/client/actions/index.php', 
		 		{
		 			parameters:'script=index.php'+
		 						'&dsp_host='+dcs.dsp_host+
		 						'&tabIndex='+tab_index+
		 						'&truque_id='+truqueID+
		 						'&third_party='+dcs.third_party+
		 						'&truque_client='+dcs.truque_client+
		 						'&ref_type='+ref_type+
		 						'&ref_id='+ref_id+
		 						'&eye_context='+dcs.eye_context+
								'&dcs_guid='+cookie+
		 						dcs.eye_context_params, 
		 				onComplete:function(r){dcs.truqueContentLoaded(truqueID, ref_type, ref_id);}
		 		});
	 	}
	 }
	 
	 
	 this.truqueContentLoaded = function(truqueID, ref_type, ref_id)
	 {	
	 	if ($('dcs_login') == null && $('dcs_item_create') == null) 
	 	{
	 		dcs.showTruqueMenu(truqueID);
	 	}
	
	 	if ($('dcs_item_create_'+ref_id) != null)
	 	{
	 		new Ajax.Request(dcs.dsp_path+'dsp/client/actions/import_item.php', 
	 			{
	 				parameters:'itemID='+ref_id+
	 							'&dsp_host='+dcs.dsp_host, 
		 			onComplete:function(r){dcs.itemImported(r, truqueID, ref_type, ref_id);}
		 		});
	 	}
	 }
	 
	this.itemImported = function(r, truqueID, ref_type, ref_id)
	{
		var newItemID = parseInt(r.responseText);
		
		if (newItemID == 0 || isNaN(newItemID))
		{
			if ($('truqueDiv'+truqueID).style.display == 'block')
			{
				$('truqueDiv'+truqueID).innerHTML = "<table width='350px' height='150px'><tr><td align='center' style='color:red;font-size:14px;'>Failed to export item to DSP!<br/><br/>Please contact the system administrator</td></tr></table>";
			}
		}
		else
		{
			dcs.loadTruqueContent(truqueID, ref_type, ref_id);		
		}
	}	

	this.Login = function(truqueID, ref_type, ref_id)
	{
		new Ajax.Updater('truqueDiv'+truqueID, dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=login.php'+
							'&dsp_host='+dcs.dsp_host+
							'&login='+window.document.getElementById('dcs_login_'+truqueID).value+
							'&password='+window.document.getElementById('dcs_password_'+truqueID).value+
							'&truque_id='+truqueID+
							'&ref_type='+ref_type+
							'&ref_id='+ref_id+
							'&third_party='+dcs.third_party+
							'&truque_client='+dcs.truque_client, 
					onComplete:function(r)
					{
						//if ($('dcs_guid'))
						//{
						//	dcs.SetCookie('DCSTRUQUEGUID', $('dcs_guid').value, 180, '/', '.'+dcs.dsp_host, 0);
						//}
					}
			});
	}
	
	this.Logout = function(truqueID, ref_type, ref_id)
	{
		if (dcs.dsp_host.indexOf('nydc.com') >= 0)
		{
			window.location.href = 'http://nydc.com/main/logout.php';
			return;
		}
		
		
		new Ajax.Updater('truqueDiv'+this.currentTruqueID, dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:'script=logout.php'+
							'&dsp_host='+dcs.dsp_host,
				onComplete:function()
				{
					dcs.SetCookie('DCSTRUQUEGUID', '', 180, '/', '.'+dcs.dsp_host, 0);
					if (dcs.dsp_host.indexOf('.designcentersearch.com') >= 0)
						dcs.SetCookie('DCSTRUQUEGUID', '', 180, '/', '.designcentersearch.com', 0);
					//$('dcs_guid').value = '';
					//dcs.switchTab(1, '', truqueID, ref_type, ref_id);
					window.location.reload();
				}
			});
	}
	
	
	this.SetCookie = function( name, value, expires, path, domain, secure ) 
	{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		
		/*
		if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24
		*/
		if ( expires )
		{
		expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		
		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	}


	this.GetCookie = function( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}		
	
	
	
	
	
	/**
	 *	Add or remove an item to/from a design library section
	 *
	 */
	this.toggleDesignLibraryItemAccess = function(truqueID, ref_type, ref_id, dcs_ref_id, designLibrarySectionID, mainDesignLibrarySectionID)
	{
		$('dcs_designLibrarySectionSaved'+designLibrarySectionID+'_'+truqueID).style.display = 'none';
		$('dcs_designLibrarySectionIndicator'+designLibrarySectionID+'_'+truqueID).style.display = 'block';
		
		if ($('check_design_library_tab_'+designLibrarySectionID+'_'+truqueID).checked)
		{
			if (designLibrarySectionID != mainDesignLibrarySectionID)
				$('check_design_library_tab_'+mainDesignLibrarySectionID+'_'+truqueID).checked = true;
			
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/design_library_ref_add.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=ADD'+
								'&designLibrarySectionID='+designLibrarySectionID+
								'&ref_type='+ref_type+
								'&ref_id='+dcs_ref_id+
								'&third_party='+dcs.third_party+
								'&truque_client='+dcs.truque_client, 
					onComplete: function(r){
		
						$('dcs_designLibrarySectionIndicator'+designLibrarySectionID+'_'+truqueID).style.display = 'none';
						$('dcs_designLibrarySectionSaved'+designLibrarySectionID+'_'+truqueID).style.display = 'block';
					}
				});
		}
		else
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/design_library_ref_add.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=DELETE'+
								'&designLibrarySectionID='+designLibrarySectionID+
								'&ref_type='+ref_type+
								'&ref_id='+dcs_ref_id+
								'&third_party='+dcs.third_party,
					onComplete:function(r){
							//uncheck the main section, only if this was the last section the item belonged to 
							if (r.responseText == 'LAST')
							{
								$('check_design_library_tab_'+mainDesignLibrarySectionID+'_'+truqueID).checked = false;
							}
							
							$('dcs_designLibrarySectionIndicator'+designLibrarySectionID+'_'+truqueID).style.display = 'none';
							$('dcs_designLibrarySectionSaved'+designLibrarySectionID+'_'+truqueID).style.display = 'block';
					}
				});
		}
	}
	
	
	
	/**
	 *	Add or remove an item to/from the main design library section
	 *
	 */
	this.toggleDesignLibraryItemAccessAndClose = function(truqueID, ref_type, ref_id, dcs_ref_id, designLibrarySectionID, mainDesignLibrarySectionID)
	{
		$('dcs_designLibrarySectionSaved'+designLibrarySectionID+'_'+truqueID).style.display = 'none';
		$('dcs_designLibrarySectionIndicator'+designLibrarySectionID+'_'+truqueID).style.display = 'block';
		
		if ($('quick_check_design_library_tab_'+designLibrarySectionID+'_'+truqueID).checked)
		{
			if (designLibrarySectionID != mainDesignLibrarySectionID)
				$('check_design_library_tab_'+mainDesignLibrarySectionID+'_'+truqueID).checked = true;
			
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/design_library_ref_add.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=ADD'+
								'&designLibrarySectionID='+designLibrarySectionID+
								'&ref_type='+ref_type+
								'&ref_id='+dcs_ref_id+
								'&third_party='+dcs.third_party+
								'&truque_client='+dcs.truque_client, 
					onComplete: function(r){
		
						$('dcs_designLibrarySectionIndicator'+designLibrarySectionID+'_'+truqueID).style.display = 'none';
						$('dcs_designLibrarySectionSaved'+designLibrarySectionID+'_'+truqueID).style.display = 'block';
						dcs.hideTruque(truqueID);
					}
				});
		}
		else
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/design_library_ref_add.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=DELETE'+
								'&designLibrarySectionID='+designLibrarySectionID+
								'&ref_type='+ref_type+
								'&ref_id='+dcs_ref_id+
								'&third_party='+dcs.third_party,
					onComplete:function(r){
							//uncheck the main section, only if this was the last section the item belonged to 
							if (r.responseText == 'LAST')
							{
								$('check_design_library_tab_'+mainDesignLibrarySectionID+'_'+truqueID).checked = false;
							}
							
							$('dcs_designLibrarySectionIndicator'+designLibrarySectionID+'_'+truqueID).style.display = 'none';
							$('dcs_designLibrarySectionSaved'+designLibrarySectionID+'_'+truqueID).style.display = 'block';
							dcs.hideTruque(truqueID);
					}
				});
		}
	}
	
	
	
	/*
	 *	Add/remove an item to/from a client project room
	 *
	 */
	this.toggleClientProjectItemAccess = function(truqueID, ref_type, ref_id, dcs_ref_id, accountPackageID, mainAccountPackageID)
	{
		$('dcs_clientPackageSaved'+accountPackageID+'_'+truqueID).style.display = 'none';
		$('dcs_clientPackageIndicator'+accountPackageID+'_'+truqueID).style.display = 'block';
		
		if (accountPackageID != mainAccountPackageID)
		{
			if ($('check_project_room_'+accountPackageID+'_'+truqueID).checked)
			{
				$('check_project_room_'+mainAccountPackageID+'_'+truqueID).checked = $('check_project_room_'+accountPackageID+'_'+truqueID).checked;
			}	
		}
		
		if ($('check_project_room_'+accountPackageID+'_'+truqueID).checked)
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/account_package_ref_add.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=ADD'+
								'&accountPackageID='+accountPackageID+
								'&ref_type='+ref_type+
								'&ref_id='+dcs_ref_id+
								'&third_party='+dcs.third_party+
								'&truque_client='+dcs.truque_client, 
					onComplete: function(r)
					{
						$('dcs_clientPackageIndicator'+accountPackageID+'_'+truqueID).style.display = 'none';
						$('dcs_clientPackageSaved'+accountPackageID+'_'+truqueID).style.display = 'block';
					}
				});
		}
		else
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/account_package_ref_add.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=DELETE'+
								'&accountPackageID='+accountPackageID+
								'&ref_type='+ref_type+
								'&ref_id='+dcs_ref_id+
								'&third_party='+dcs.third_party, 
					onComplete: function(r){
							//uncheck the main section, only if this was the last section the item belonged to 
							if (r.responseText == 'LAST')
							{
								$('check_project_room_'+mainAccountPackageID+'_'+truqueID).checked = false;
							}
							
							$('dcs_clientPackageIndicator'+accountPackageID+'_'+truqueID).style.display = 'none';
							$('dcs_clientPackageSaved'+accountPackageID+'_'+truqueID).style.display = 'block';
					}
				});
		}
	}
	
	
	
	this.sendEmail = function(truqueID, ref_type, ref_id, dcs_ref_id)
	{	
	
		var recipient = $('dcs_recipient_'+truqueID).value;
		var destination = 'new_destination';
		
		if ($('dcs_saved_address_'+truqueID).checked)
		{
			recipient = $('dcs_email_history_'+truqueID).options[$('dcs_email_history_'+truqueID).selectedIndex].value;
			destination = 'saved_destination';
		}
		
		var subject = encodeURIComponent($('dcs_subject_'+truqueID).value);
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php',
			{
				parameters:'script=actions/send_email.php'+
							'&dsp_host='+dcs.dsp_host+
							'&ref_type='+ref_type+
							'&ref_id='+dcs_ref_id+
							'&third_party='+dcs.third_party+
							'&recipient='+encodeURIComponent(recipient)+
							'&destination='+encodeURIComponent(destination)+
							'&cc='+$('dcs_cc_'+truqueID).value+
							'&subject='+subject+
							'&message='+encodeURIComponent($('dcs_message_'+truqueID).value)+
							'&add_cc='+($('dcs_add_cc_'+truqueID).checked ? $('dcs_add_cc_'+truqueID).value : '')+
							'&truque_client='+dcs.truque_client, 
				onComplete:function(r){
						if (r.responseText == '')
						{
							window.document.getElementById('emailFeedback_'+truqueID).innerHTML = "<b>Your email has been sent. Thank you.</b>";
							window.document.getElementById('emailFeedback_'+truqueID).style.color = '#108CDA';
						}
						else
						{
							window.document.getElementById('emailFeedback_'+truqueID).innerHTML = "There was an error while sending your e-mail.<br/>Please contact the system administrator.<br/>"+r.responseText;
							window.document.getElementById('emailFeedback_'+truqueID).style.color = 'red';
						}
				}
			});
	}
	
	


	


	/** 
	 *
	 *		===== Display functionality =====
	 *
	 */

	//Timer for hiding the truque div
	this.truqueTimer = null;
	
	//currently active truque div
	this.currentTruqueID = null;
	
	
	this.scheduleShowTruque = function(truqueID, ref_type, ref_id, eye_context, eye_context_param, tab_index)
	{
		if (wdg('truqueDiv'+truqueID).style.display == 'block')
		{
			this.cancelHideTruque();
			return;
		}
			
		this.truqueTimer = setTimeout("dcs.showTruque('"+truqueID+"', '"+ref_type+"', '"+ref_id+"', '"+tab_index+"')", 500);
		this.eye_context = eye_context;
		this.eye_context_params = eye_context_param;
	}
	
	/**
	 * Displays the functionality div with a loading message and triggers the loading of the actual content
	 *
	 */
	this.showTruque = function(truqueID, ref_type, ref_id, tab_index)
	{
		$('truqueDiv'+truqueID).style.display = 'block';
		
		//make http request to load the content
		this.loadTruqueContent(truqueID, ref_type, ref_id, tab_index);
	}
	
	/**
	 *
	 *
	 */
	this.showTruqueMenu = function(truqueID)
	{
		var truqueDivPos = findPos($('truqueDiv'+truqueID));
		var truqueContainerPos = findPos($('truqueContainer'+truqueID));
	}
	
	
	/**
	 * Schedules the hiding of the truque div if the mouse leaves it
	 *
	 */
	this.scheduleHideTruque = function(truqueID)
	{
		//if onmouseout on a yet invisible item, cancel display timer
		if ($('truqueDiv'+truqueID).style.display == 'none')
		{
			window.clearTimeout(this.truqueTimer);
			return;
		}
		this.truqueTimer = setTimeout("dcs.hideTruque('"+truqueID+"')", 3000);
	}
	
	
	/**
	 * Hides the truque div 
	 *
	 */
	this.hideTruque = function(truqueID)
	{
		$('truqueDiv'+truqueID).style.display = 'none';
	}
	
	
	
	this.cancelHideTruque = function()
	{
		window.clearTimeout(this.truqueTimer);
	}
	
	
	this.switchTab = function(tabIndex, tabAction, truqueID, ref_type, ref_id, accountProjectID, accountPackageID, designLibrarySectionID, previousTabAction)
	{
		new Ajax.Updater('truqueDiv'+truqueID, dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:'script=index.php'+
							'&dsp_host='+dcs.dsp_host+
							'&tabIndex='+tabIndex+
							'&tabAction='+tabAction+
							'&truque_id='+truqueID+
							'&ref_type='+ref_type+
							'&ref_id='+ref_id+
							'&third_party='+dcs.third_party+
							'&truque_client='+dcs.truque_client+
		 					'&eye_context='+dcs.eye_context+
		 					dcs.eye_context_params+
							'&accountProjectID='+accountProjectID+
							'&accountPackageID='+accountPackageID+
							'&designLibrarySectionID='+designLibrarySectionID+
							'&previousTabAction='+previousTabAction
			});
			
		this.selectedTabIndex = tabIndex;
	}

	this.getTabIndexAction = function(tabIndex)
	{
		if (tabIndex == 1)
			return 'add';
		else if (tabIndex == 2)
			return 'email';
		else if (tabIndex == 3)
			return 'print';
	}
	
	this.goToAccount = function(guid)
	{
//		window.open("http://"+dcs.dsp_host+"/account_admin/?guid="+guid, '_blank', 'status=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,titlebar=yes,scrollbars=yes,resizable=yes');
		window.open("http://dsp.us.com/account_admin/?guid="+guid, '_blank', 'status=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,titlebar=yes,scrollbars=yes,resizable=yes');
	}
	
	
	this.goToWeb = function(url)
	{
		window.open(url, '_blank', 'status=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,titlebar=yes,scrollbars=yes,resizable=yes');
	}
	
	
	/**
	 * Projects functions
	 */
	
	
	this.addProject = function()
	{
		var projectName = wdg('projectName').value;
		var projectEmail = wdg('projectEmail').value;
		var projectPassword = wdg('projectPassword').value;
		
		if (projectName !='' && projectEmail != '' && projectPassword != '')
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=../../account_admin/client_projects/actions/client_project_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=ADD'+
								'&label='+encodeURIComponent(projectName)+
								'&email='+encodeURIComponent(projectEmail)+ 
								'&password='+encodeURIComponent(wdg('projectPassword').value)+
								'&addLibrary='+((wdg('addLibrary').checked)?'yes':'no'),
					onComplete:function(response){dcs.switchTab(1, 'SHOW_PRJ', dcs.currentTruqueID);}
				});
		}
	}
	
	/**
	 * Quickly add a project from the Add tree
	 */
	this.quickAddProject = function(truqueID, ref_type, ref_id, dcs_ref_id, new_div_id)
	{
		var projectName = wdg('accountProjectLabel_'+truqueID).value;
		var projectEmail = wdg('accountProjectEmail_'+truqueID).value;
		var projectPassword = wdg('accountProjectPassword_'+truqueID).value;
		
		if (projectName !='' && projectEmail != '' && projectPassword != '')
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/client_project_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=QUICK_ADD'+
								'&'+Form.serialize('NewAccountProjectForm_'+truqueID)+
								'&truque_id='+truqueID+
								'&ref_type='+ref_type+
								'&ref_id='+ref_id+
								'&third_party='+dcs.third_party+
								'&dcs_ref_id='+dcs_ref_id, 
					onComplete:function(response){
						//remove the default message which appears if no client project existed before this
						if (wdg('noClientProjectDiv_'+truqueID))
						{
							wdg('table_client_projects_'+truqueID).deleteRow(0);
						}
						var tr = wdg('table_client_projects_'+truqueID).insertRow(0);
						var td = tr.insertCell(0);
						td.innerHTML = response.responseText;
						
						wdg(new_div_id).style.display = "none";
						wdg('new_client_project_name_'+truqueID).value = "";
						wdg('new_client_project_email_'+truqueID).value = "";
						wdg('new_client_project_password_'+truqueID).value = "";
					}
				});
		}
	}
	
	
	this.delProject = function(projectID, label, count)
	{
		var count = parseInt(count);
		if(confirm(	'Are you sure you want to delete the project \''+
				   	decodeURIComponent(label)+ '\' ?' +
				    ( (count>0)?'\n\n'+decodeURIComponent(label)+' contains '+count+' room'+((count>1)?'s !\n\n ':' !\n\n '):'')  
		   		  ))
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=../../account_admin/client_projects/actions/client_project_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=DELETE'+
								'&accountProjectID='+encodeURIComponent(projectID), 
					onComplete:function(response){dcs.switchTab(1, 'SHOW_PRJ', dcs.currentTruqueID);}
				});
		}
	}
	
	
	this.confirmUpdateAccountProject = function(truqueID, accountProjectID)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.updateAccountProject('"+truqueID+"', "+accountProjectID+");";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update Project settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	this.updateAccountProject = function(truqueID, accountProjectID)
	{
		wdg('updateCPButtonContent').innerHTML = "Update &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/client_project_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=UPDATE_ACCESS_SETTINGS'+
								'&accountProjectID='+accountProjectID+
								'&'+Form.serialize('ProjectAccessSettingsForm_'+truqueID),
					onComplete:function(r){
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('updateCPButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
							}
							else
							{
								wdg('updateCPButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
					}
				});
	}
	
	
	this.resetAccountProjectSettings = function(truque_id, ref_type, ref_id, accountProjectID)
	{
		dcs.switchTab(1, 'PRJ_DETAIL', truque_id, ref_type, ref_id, accountProjectID);
	}
	
	this.resetAccountProjectCDS = function(truque_id, ref_type, ref_id, accountProjectID)
	{
		dcs.switchTab(1, 'PRJ_DETAIL', truque_id, ref_type, ref_id, accountProjectID);
	}
	
	this.confirmUpdateAccountProjectDisplaySettings = function(truqueID, accountProjectID)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.updateAccountProjectDisplaySettings('"+truqueID+"', "+accountProjectID+");";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update the Project Display Settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	this.updateAccountProjectDisplaySettings = function(truqueID, accountProjectID)
	{
		wdg('updateCDSButtonContent').innerHTML = "Update &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/client_project_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=UPDATE_DISPLAY_SETTINGS'+
								'&accountProjectID='+accountProjectID+
								'&'+Form.serialize('CPDisplaySettingsForm_'+truqueID),
					onComplete:function(r){
						 	
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('updateCDSButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
							}
							else
							{
								wdg('updateCDSButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
					}
				});
		
	}
	
	
	this.confirmDeleteAccountProject = function(accountProjectID, truqueID, ref_type, ref_id)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.deleteAccountProject("+accountProjectID+", '"+truqueID+"', '"+ref_type+"', '"+ref_id+"');";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Delete the client project?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	this.deleteAccountProject = function(accountProjectID, truqueID, ref_type, ref_id)
	{
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/client_project_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=DELETE'+
								'&accountProjectID='+accountProjectID,
					onComplete:function(r){dcs.switchTab(1, '', truqueID, ref_type, ref_id);}
				});
	}
	
	this.addPackage = function(accountProjectID, tabAction)
	{
		var newPackage = $('packageName').value;
		if(newPackage!='')
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/account_package_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=ADD'+
								'&label='+encodeURIComponent(newPackage)+
								'&accountProjectID='+encodeURIComponent(accountProjectID), 
					onComplete:function(response){dcs.switchTab(1, 'PRJ_DETAIL', dcs.currentTruqueID, accountProjectID);}
				});
		} 
	}
	
	this.quickAddPackage = function(accountProjectID, truqueID, ref_type, ref_id, new_div_id)
	{
		var packageName = wdg('new_client_project_room_name_'+accountProjectID+'_'+truqueID).value;
		if(packageName != '')
		{
			new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
				{
					parameters:	'script=actions/account_package_save.php'+
								'&dsp_host='+dcs.dsp_host+
								'&action=QUICK_ADD'+
								'&label='+encodeURIComponent(packageName)+
								'&accountProjectID='+encodeURIComponent(accountProjectID)+
								'&truque_id='+truqueID+
								'&ref_type='+ref_type+
								'&ref_id='+ref_id+
								'&third_party='+dcs.third_party, 
					onComplete:function(r){
						//remove the default message which appears if there were no rooms so far
						if (wdg('noAccountPackageRow_'+accountProjectID+'_'+truqueID))
						{
							wdg('table_project_rooms_'+accountProjectID+'_'+truqueID).deleteRow(0);
						}
						
						var tr = wdg('table_project_rooms_'+accountProjectID+'_'+truqueID).insertRow(0);
						var td = tr.insertCell(0);
						td.innerHTML = r.responseText;
						
						wdg('new_client_project_room_name_'+accountProjectID+'_'+truqueID).value = "";
						wdg(new_div_id).style.display = 'none';
					}
				});
		} 
	}
	
	
	this.confirmDeleteAccountPackage = function(accountProjectID, accountPackageID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.deleteAccountPackage("+accountProjectID+", "+accountPackageID+", '"+tabAction+"', '"+truqueID+"', '"+ref_type+"', '"+ref_id+"');";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Delete room?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	this.deleteAccountPackage = function(accountProjectID, accountPackageID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('deleteCPSButtonContent_'+truqueID).innerHTML = "Delete &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/account_package_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=DELETE'+
							'&accountPackageID='+accountPackageID, 
				onComplete:function(r){
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('deleteCPSButtonContent_'+truqueID).innerHTML = "Delete &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
								dcs.switchTab(1, tabAction, truqueID, ref_type, ref_id, accountProjectID);
							}
							else
							{
								wdg('deleteCPSButtonContent_'+truqueID).innerHTML = "Delete &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
						
					}
			});
	}
	
	this.confirmUpdateAccountPackage = function(accountProjectID, accountPackageID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.updateAccountPackage("+accountProjectID+", "+accountPackageID+", '"+tabAction+"', '"+truqueID+"', '"+ref_type+"', '"+ref_id+"');";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update Room settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	
	this.updateAccountPackage = function(accountProjectID, accountPackageID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('updateCPSButtonContent').innerHTML = "Update &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/account_package_save.php'+	
							'&dsp_host='+dcs.dsp_host+
							'&action=UPDATE'+
							'&accountPackageID='+accountPackageID+
							'&label='+encodeURIComponent(wdg('accountPackageLabel_'+truqueID).value),
				onComplete:function(response){
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('updateCPSButtonContent_'+truqueID).innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
//								dcs.switchTab(1, tabAction, truqueID, ref_type, ref_id, accountProjectID);
							}
							else
							{
								wdg('updateCPSButtonContent_'+truqueID).innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
						
					}
			});
	}
	
	
	this.confirmDelPackage = function(accountPackageID, accountProjectID)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.delPackage("+accountPackageID+", "+accountProjectID+");";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Delete the room from the project?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	
	this.delPackage = function(accountPackageID, accountProjectID)
	{
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=../../account_admin/client_projects/actions/account_package_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=DELETE'+
							'&accountPackageID='+accountPackageID, 
				onComplete:function(response){dcs.switchTab(1, 'PRJ_DETAIL', dcs.currentTruqueID, accountProjectID);}
			});
	}
	
	
	
	/**
	 *	Design library functionality
	 *
	 */
	 
	this.confirmUpdateDesignLibrary = function(designLibraryID)
	{
		//first collapse to closed the access rights div, so there would be no scrollbar on the screen
		if (wdg('library_restricted_access_div').style.display == 'block')
			dcs.collapse('img_library_restricted_access', 'library_restricted_access_div');
		
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.updateDesignLibrary("+designLibraryID+");";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update Design Library settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	this.updateDesignLibrary = function(designLibraryID)
	{
		wdg('updateDLButtonContent').innerHTML = "Update &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
	 	var accountProjects = "";
	 	var i = 0;
	 	while (wdg("accountProject_"+i))
	 	{
	 		if (wdg("accountProject_"+i).checked)
		 		accountProjects += wdg("accountProject_"+i).value+"_";
		 	i++;
	 	}
	 	
	 	
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=UPDATE_ACCESS_SETTINGS'+
							'&designLibraryID='+designLibraryID+
							'&enabled='+encodeURIComponent(wdg('enable_dl_y').checked ? 'Y' : 'N')+
							'&account_projects='+accountProjects, 
				onComplete:function(r){
					//dcs.switchTab(1, 'SHOW_DL', dcs.currentTruqueID);
					
							//update hidden fields with new values
							var i = 0;
						 	while (wdg("account_project_add_library_"+i))
						 	{
						 		wdg("account_project_add_library_"+i).value = (wdg("accountProject_"+i).checked ? 'yes' : 'no');
						 		i++;
						 	}
						 	
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('updateDLButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
							}
							else
							{
								wdg('updateDLButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
				}
			});
	}
	
	
	this.resetLibrarySettings = function(truque_id, ref_type, ref_id)
	{
		dcs.switchTab(1, 'SHOW_DL', truque_id, ref_type, ref_id);
	}
	
	this.dlAccessChanged = function()
	{
		if ($('enable_dl_y').checked)
		{
			var i = 0;
			while ($('accountProject_'+i))
			{
				$('accountProject_'+i).disabled = true;
				i++;
			}
		}
		else
		{
			var i = 0;
			while ($('accountProject_'+i))
			{
				$('accountProject_'+i).disabled = false;
				i++;
			}
		}
	}
	 
	this.confirmDeleteDesignLibrarySection = function(designLibrarySectionID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.deleteDesignLibrarySection("+designLibrarySectionID+", '"+tabAction+"', '"+truqueID+"', '"+ref_type+"', '"+ref_id+"');";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Delete Tab?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	} 
	
	this.deleteDesignLibrarySection = function(designLibrarySectionID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('deleteDLSectionButtonContent').innerHTML = "Delete &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
	 	new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_section_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=DELETE'+
							'&designLibrarySectionID='+designLibrarySectionID, 
				onComplete:function(r){
//							dcs.switchTab(1, tabAction, truqueID, ref_type, ref_id);
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('deleteDLSectionButtonContent').innerHTML = "Delete &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
								//if everything went ok, go back
								dcs.switchTab(1, tabAction, truqueID, ref_type, ref_id);
							}
							else
							{
								wdg('deleteDLSectionButtonContent').innerHTML = "Delete &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
				}
			});
	}
	
	
	this.confirmUpdateDesignLibrarySection = function(designLibrarySectionID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.updateDesignLibrarySection("+designLibrarySectionID+", '"+tabAction+"', '"+truqueID+"', '"+ref_type+"', '"+ref_id+"');";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update Tab settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	
	this.updateDesignLibrarySection = function(designLibrarySectionID, tabAction, truqueID, ref_type, ref_id)
	{
		wdg('updateDLSectionButtonContent').innerHTML = "Update &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
	 	new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_section_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=UPDATE'+
							'&designLibrarySectionID='+designLibrarySectionID+
							'&name='+wdg('truque_tab_name_'+truqueID).value, 
				onComplete:function(r){
//							dcs.switchTab(1, tabAction, truqueID, ref_type, ref_id);
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('updateDLSectionButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
								//if everything went ok, go back
								dcs.switchTab(1, tabAction, truqueID, ref_type, ref_id);
							}
							else
							{
								wdg('updateDLSectionButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
				}
			});
	}
	
	
	this.saveDesignLibrarySection = function(designLibraryID)
	{
	 	new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_section_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=SAVE'+
							'&designLibraryID='+designLibraryID+
							'&name='+wdg('truque_tab_name').value,
				onComplete:function(response){dcs.switchTab(1, 'SHOW_DL', dcs.currentTruqueID);}
			});
	}
	
	
	this.addDesignLibrarySection = function(designLibraryID, truqueID, ref_type, ref_id, new_div_id)
	{
	 	new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_section_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=SAVE'+
							'&designLibraryID='+designLibraryID+
							'&name='+wdg('new_design_library_tab_name_'+truqueID).value+
							'&truque_id='+truqueID+
							'&ref_type='+ref_type+
							'&ref_id='+ref_id+
							'&third_party='+dcs.third_party, 
				onComplete:function(r){
					//var designLibrarySectionID = r.responseText;
					
					var tr = $('table_library_tabs_'+truqueID).insertRow(0);
					var td = tr.insertCell(0);

					td.innerHTML = r.responseText;//"<input id='check_design_library_tab_"+designLibrarySectionID+"' type='checkbox' onchange='dcs.toggleDesignLibraryItemAccess("+designLibrarySectionID+", "+truqueID+");' /> "+wdg('new_design_library_tab_name').value;
					
					$(new_div_id).style.display = 'none';
					$('new_design_library_tab_name_'+truqueID).value = '';
					//dcs.switchTab(1, 'SHOW_DL', dcs.currentTruqueID);
				}
			});
	}
	
	
	this.confirmDelDesignLibrarySection = function(designLibrarySectionID, designLibrarySectionName)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.delDesignLibrarySection("+designLibrarySectionID+");";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Delete the '" + designLibrarySectionName + "' section?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	
	this.delDesignLibrarySection = function(designLibrarySectionID)
	{
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_section_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=DELETE'+
							'&designLibrarySectionID='+designLibrarySectionID, 
				onComplete:function(response){dcs.switchTab(1, 'SHOW_DL', dcs.currentTruqueID);}
			});
	}
	
	this.toggleDisplayDiv = function(div_name)
	{
		if ($(div_name).style.display == 'none')
			$(div_name).style.display = 'block';
		else
			$(div_name).style.display = 'none';
	}
	
	
	
	
	/********** CDS FUNCTIONS ***********/
	
	
	this.confirmSaveGlobalCDS = function()
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.saveClientDS();";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update Client Display Settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	this.saveClientDS = function()
	{
		wdg('updateCDSButtonContent').innerHTML = "Update CDS &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/cds_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=SAVE'+
							'&own_logo='+(wdg('check_own_logo').checked ? 'Y' : 'N') +
							'&dealer_info='+(wdg('check_dealer_info').checked ? 'Y' : 'N') +
							'&price='+(wdg('check_price').checked ? 'Y' : 'N') +
							'&title='+(wdg('check_title').checked ? 'Y' : 'N') +
							'&description='+(wdg('check_description').checked ? 'Y' : 'N') +
							'&images='+(wdg('radio_all_images').checked ? 'ALL' : 'MAIN'), 
							onComplete:function(r){
								//update hidden fields with new values
								wdg('cds_own_logo').value = (wdg('check_own_logo').checked ? 'Y' : 'N');
								wdg('cds_dealer_info').value = (wdg('check_dealer_info').checked ? 'Y' : 'N');
								wdg('cds_price').value = (wdg('check_price').checked ? 'Y' : 'N');
								wdg('cds_title').value = (wdg('check_title').checked ? 'Y' : 'N');
								wdg('cds_description').value = (wdg('check_description').checked ? 'Y' : 'N');
								wdg('cds_images').value = (wdg('radio_all_images').checked ? 'ALL' : 'MAIN');
								
								//put a green check on the button if everything went well, or a red cross otherwise
								if (r.responseText == '')
								{
									wdg('updateCDSButtonContent').innerHTML = "Update CDS &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
								}
								else
								{
									wdg('updateCDSButtonContent').innerHTML = "Update CDS &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
								}
							}
			});
	}
	
	
	this.confirmUpdateLibraryDisplaySettings = function(designLibraryID)
	{
		wdg('dcs_confirm_popup_yes_'+truqueID).href = "javascript:dcs.updateLibraryDisplaySettings("+designLibraryID+");";
		wdg('dcs_confirm_popup_text_'+truqueID).innerHTML = "Update Client Display Settings?";
		wdg('dcs_confirm_popup_'+truqueID).style.display="block";
	}
	
	
	this.displaySettingsTypeChanged = function(truqueID)
	{
		if ($('dealer_display_'+truqueID).checked)
		{
			$('show_own_logo_'+truqueID).disabled = true;
			$('show_titles_'+truqueID).disabled = true;
			$('show_descriptions_'+truqueID).disabled = true;
			$('show_special_notes_'+truqueID).disabled = true;
			$('show_prices_'+truqueID).disabled = true;
			$('show_measurements_'+truqueID).disabled = true;
			$('show_textiles_titles_'+truqueID).disabled = true;
			$('show_textiles_descriptions_'+truqueID).disabled = true;
			$('show_textiles_origin_'+truqueID).disabled = true;
			$('show_textiles_materials_'+truqueID).disabled = true;
			$('show_textiles_measurements_'+truqueID).disabled = true;
			$('show_textiles_care_'+truqueID).disabled = true;
		}
		else if ($('designer_display_'+truqueID).checked)
		{
			$('show_own_logo_'+truqueID).disabled = false;
			$('show_titles_'+truqueID).disabled = false;
			$('show_descriptions_'+truqueID).disabled = false;
			$('show_special_notes_'+truqueID).disabled = false;
			$('show_prices_'+truqueID).disabled = false;
			$('show_measurements_'+truqueID).disabled = false;
			$('show_textiles_titles_'+truqueID).disabled = false;
			$('show_textiles_descriptions_'+truqueID).disabled = false;
			$('show_textiles_origin_'+truqueID).disabled = false;
			$('show_textiles_materials_'+truqueID).disabled = false;
			$('show_textiles_measurements_'+truqueID).disabled = false;
			$('show_textiles_care_'+truqueID).disabled = false;
			
		}
	}
	
	 
	this.updateLibraryDisplaySettings = function(designLibraryID)
	{
		wdg('updateCDSButtonContent').innerHTML = "Update &nbsp <img width='10px' src='"+dcs.artwork_path+"/artwork/indicator.gif' border='0'/>";
		
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/design_library_save.php'+
							'&dsp_host='+dcs.dsp_host+
							'&action=UPDATE_DISPLAY_SETTINGS'+
							'&designLibraryID='+designLibraryID+
							'&'+Form.serialize('DLDisplaySettingsForm'), 
				onComplete:function(r){
							
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == '')
							{
								wdg('updateCDSButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/yes.gif' border='0'/>";
							}
							else
							{
								wdg('updateCDSButtonContent').innerHTML = "Update &nbsp <img src='"+dcs.artwork_path+"/artwork/no.gif' border='0'/>";
							}
				}
			});
	}
	
	
	this.switchDCSDisplay = function()
	{
		if (wdg('dcs_options_img').src.indexOf("/artwork/arrow_ASC.gif") != -1)
		{
			wdg('dcs_options_img').src = "/artwork/arrow_DESC.gif";
			wdg('cds_options').style.display = "block";
		}
		else
		{
			wdg('dcs_options_img').src = "/artwork/arrow_ASC.gif";
			wdg('cds_options').style.display = "none";
		}
	}
	
	
	this.resetDLCDS = function(truque_id, ref_type, ref_id)
	{
		dcs.switchTab(1, 'SHOW_DL', truque_id, ref_type, ref_id);
	}
	
	this.generateCDSURIComponent = function()
	{
		var uri = '&own_logo='+(wdg('check_own_logo').checked ? 'Y' : 'N')+
					'&dealer_info='+(wdg('check_dealer_info').checked ? 'Y' : 'N')+
					'&price='+(wdg('check_price').checked ? 'Y' : 'N')+
					'&title='+(wdg('check_title').checked ? 'Y' : 'N')+
					'&description='+(wdg('check_description').checked ? 'Y' : 'N')+
					'&images='+(wdg('radio_all_images').checked ? 'ALL' : 'MAIN');
		return uri;
	}
	
	
	this.collapse = function(img_id, div_id, new_div_id)
	{
		if (wdg(img_id).src.indexOf("/artwork/arrow_ASC.gif") != -1)
		{
			wdg(img_id).src = "http://images1.designcentersearch.com/artwork/arrow_DESC.gif";
			wdg(div_id).style.display = "block";
		}
		else
		{
			wdg(img_id).src = "http://images1.designcentersearch.com/artwork/arrow_ASC.gif";
			wdg(div_id).style.display = "none";
			if (wdg(new_div_id))
				wdg(new_div_id).style.display = "none";
		}
		
	}
	
	this.collapseWithNew = function(img_id, div_id, new_div_id, new_img_id)
	{
		if (wdg(img_id).src.indexOf("http://images1.designcentersearch.com/artwork/arrow_ASC.gif") != -1)
		{
			wdg(img_id).src = "http://images1.designcentersearch.com/artwork/arrow_DESC.gif";
			wdg(div_id).style.display = "block";
			wdg(new_div_id).style.display = "block";
		}
		else
		{
			wdg(new_div_id).style.display = "block";
		}
	}
	
	this.showHelpNotes = function(helpCode)
	{
		new Ajax.Updater('dcs_info_popup_text', 
					dcs.dsp_path+'/dsp/client/actions/index.php', 
					{
						parameters:	'script=actions/help_notes.php'+
									'&dsp_host='+dcs.dsp_host+
									'&helpCode='+helpCode, 
						onComplete:function(r){
							wdg('dcs_info_popup').style.display = "block";
						}
					});
	}
	
	
	
	
	this.showRequestMessage = function()
	{
		if (wdg('dcs_requestMessageDiv').style.display == 'none')
			wdg('dcs_requestMessageDiv').style.display = 'block';
		else
			wdg('dcs_requestMessageDiv').style.display = 'none';
	}


	this.sendForgottenPassword = function()
	{
		new Ajax.Request(dcs.dsp_path+'/dsp/client/actions/index.php', 
			{
				parameters:	'script=actions/forgot_password_do.php'+
							'&dsp_host='+dcs.dsp_host+
							'&email='+wdg('dcs_email').value+
							'&truque_client='+dcs.truque_client, 
				onComplete:function(r){
							
							//put a green check on the button if everything went well, or a red cross otherwise
							if (r.responseText == 'OK')
							{
								wdg('DCSForgotPasswordResultContainer').innerHTML = "Email sent to "+wdg('dcs_email').value;
								wdg('DCSForgotPasswordResultContainer').style.color = '#108CDA';
							}
							else
							{
								wdg('DCSForgotPasswordResultContainer').innerHTML = r.responseText;
								wdg('DCSForgotPasswordResultContainer').style.color = '#FF0000';
							}
				}
			});
	}
	
}


	//collapsing categories tree functionality
	function collapse_controler1(obj_){
		if(obj_){
			var treeC1 = obj_.id.replace('1tree','1treeC');
			if($(treeC1)){
				if($(treeC1).style.display=='none'){
					if(Effect){
						new Effect.SlideDown(treeC1,{scaleX:false,scaleY:true,duration:0.4});
					}else{
						$(treeC1).style.display='block';
					}
					obj_.className='tree_collapse txt_11';
				}else{
					if(Effect){
						new Effect.SlideUp(treeC1,{scaleX:false,scaleY:true,duration:0.4});
					}else{
						$(treeC1).style.display='none';
					}	
					obj_.className='tree_uncollapse txt_11';
				}
			}
		}
	}

	function wdg(id){return window.document.getElementById(id);};
	
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
	
	
	function OpenPopup(url,name,windowWidth,windowHeight,option) 
	{
		var wOpen 		= "";
		if(windowWidth==''&&windowHeight=='') 
		{
			if ( navigator.userAgent.indexOf('Mac') != -1 )  	windowWidth 	= 1024; 	
			else if (navigator.appName=="Netscape") 			windowWidth 	= 1024; 	
			else  												windowWidth 	= screen.availWidth; 
		}
		var xposition 	= 0;
		var yposition 	= 0;
			xposition 	= (screen.width - windowWidth) / 2;
			yposition 	= (screen.height - windowHeight) / 3;
		sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes,channelmode=no,directories=no,location=yes,titlebar=yes'+option;
		sOptions = sOptions + ',width=' + windowWidth;
		sOptions = sOptions + ',height=' + windowHeight;
		sOptions = sOptions + ',screenX=' + xposition;
		sOptions = sOptions + ',screenY=' + yposition;
		sOptions = sOptions + 'left=0,top=0';
		wOpen = window.open(url, name, sOptions);
		wOpen.moveTo(xposition, yposition);
		return wOpen;
	}
// ]]>