/****************************************
*
*	functions for connection requests
*
****************************************/

function initConnectionRequest(qp,lnk,act){
	
	/*
	*	@lnk = the id of the originating link
	*	@act = what to do with the link = you send in either hide or update
	*
	*/
	
	var pars = 'qp=' + qp + '&lnk=' + lnk + '&act=' + act;
	var crh = $('connectionRequestForm');
	
	new Ajax.Request('/index.cfm?event=qp.connection.AjaxGetConnectionRequestForm',{
		method:'post',
		parameters:pars,
		onSuccess: function(transport){
				
			var rtn = transport.responseText;
				
			if (rtn == '' || rtn == -1){
					location.reload();
			}else{		
				$('connectionRequestConfirm').hide();
				crh.update(rtn);
				crh.innerHTML;
				crh.show();
				openGenWin('connectionRequest');
			}	
			
		}
	});

	
	
}


function submitConnectionRequest(lnk,act){
	
	/*
	*	@lnk = the id of the originating link
	*	@act = what to do with the link = you send in either delete or update
	*
	*/
	
	var frm = $('crFrm');
	var pars = frm.serialize();
	var msg = '';
	
	if (frm.qp.value == 0){
		msg	= msg + ' You must choose a Profile to make the request from.\n';
	}
	
	if (frm.connectionType.value == 0){
		msg	= msg + ' You must choose a Connection Type.\n';
	}
	
	if (msg != ''){
		// show alert
		alert('The following errors have occured:\n' + msg);
	}else{
		
		
		new Ajax.Request('/index.cfm?event=qp.connection.AjaxDoCreateRequest',{
			method:'post',
			parameters:pars,
			onCreate: function(){				
			}
			,onSuccess:function(transport){
				
				var rtn = transport.responseText;
				
				if (rtn == '' || rtn == -1){
					location.reload();
				}else{
					
					Effect.BlindUp('connectionRequestForm', { duration: .25 });

					$('connectionRequestConfirm').update(rtn);
					$('connectionRequestConfirm').innerHTML;
				
					Effect.BlindDown('connectionRequestConfirm', { duration: .25, queue: 'end'});
					
					if (act == 'delete'){
						theLinks = $$('input.'+lnk);
						theLinks.each(function(e){$(e).remove();});							
					}else{
						$(lnk).className = 'industryPendingApproval';
						$(lnk).onclick = function(){return false;}; 
					}
				}			
				
			}
			
		});	
	
	}	
	
}


/****************************************
*
*	functions for connection pages
*
****************************************/

function editType(hid,cid,qp){
	
	var h = $('cth'+hid);
	var d = $('ctd'+hid);
	
	var pars = 'hid=' + hid +'&cid=' + cid + '&qp=' + qp ;
							
	new Ajax.Request('/index.cfm?event=qp.connection.AjaxGetEditor',{
						method:'post',
						parameters:pars,
						onSuccess : function(transport){
							d.hide();
							h.insert(transport.responseText);
						}
					 });
	
}

function killEdit(hid){
	
	var h = $('cth'+hid);
	var d = $('ctd'+hid);
	var f = $('frmHolder'+hid);
	
	f.remove();
	d.show();
	
}

function submitChange(hid){
	
	var frm = $('frm'+hid);
	var t = $('ctv'+hid);
	var pars = frm.serialize();
	var children = $$('span.connection'+frm.connectionID.value);
	
	
	// only do update if change
	if (frm.oldConnectionType.value != frm.connectionType.value){
	
		new Ajax.Request('/index.cfm?event=qp.connection.AjaxDoSave',{
			method:'post',
			parameters:pars,
			onCreate: function(){
		
				$('frmCancel'+hid).hide();
				frm.action.value = 'Saving ...';
				frm.action.disable();
				
			}
			,onSuccess:function(transport){
				
				var rtn = transport.responseText;
				// update type value
				if (rtn != ''){
					children.each(function(e){
						e.update(rtn);		
						e.innerHTML
					});
				}
				// kill this form
				killEdit(hid);
				
			}
			
		});	
		
	}else{
		// kill this form
		killEdit(hid);
	}
}
