
var boxv = Array();

var targets = Array();

targets[1] = 'cs_pocketit.php';
targets[2] = 'cs_rateitem.php';
targets[3] = 'cs_login.php';
targets[4] = 'cs_recommend.php';
targets[5] = 'cs_addopinion.php';
targets[6] = 'cs_checkavail.php';
targets[7] = 'cs_blogopinion.php';
targets[8] = 'cs_picturecopy.php';
targets[9] = 'cs_addressimporter.php';
targets[10] = 'cs_checkusergroup.php';
targets[11] = 'cs_purchasecontent.php';

function threadSubmitContent(targetid,callcode,formid,params) {
	var f;
	var b;

	if (params == undefined) {
		params = '';
	}
		
	if (f = $(formid)) {
		if (params) {
			params = params + '&' + f.serialize();
		} else {
			params = f.serialize();	
		}
		f.disable();
	}

	if (b = $(targetid)) {
		Element.update(b,'<div align="center"><img src="images/wait.gif" border="0" width="33" height="33" alt="Please wait..." /><br />Please wait...</div>');

		if (targets[callcode] !== undefined) {
			var myAjax = new Ajax.Request(server + targets[callcode], {
				method: 'get',
				parameters: params,
				onComplete:	function(request) {
					if (request.status >= 400) {
						Element.update(contentid,'<p>An error occured during the connection (code: ' + request.status + ').</br>Please try again...</p>');
					} else {
						request.responseText.evalScripts();
						Element.update(b,request.responseText);
					}
				}
			});
		}
	}

	if (f) {
		f.enable();
	}
}

function threadSubmit(targetid,contentid,movetoid,callcode,formid,params) {
	
	var f;
	var a;
	var b;
	
	if (params == undefined) {
		params = '';
	}
		
	if (f = $(formid)) {

		if (params) {
			params = params + '&' + f.serialize();
		} else {
			params = f.serialize();	
		}
		f.disable();
	}
	
	params = params + '&movetoid=' + movetoid;

	//$(targetid).hide();
	//openThread(targetid,contentid,movetoid,callcode,params);

	if ((a = $(movetoid)) && (b = $(targetid))) {
		
		Element.update(contentid,'<img src="images/wait.gif" border="0" width="33" height="33" alt="Please wait..." />');

		//alert(Position.cumulativeOffset(a));
		Position.clone(a,b,{offsetLeft: boxv[callcode][1], offsetTop: boxv[callcode][2]});

		Element.show(b);

		if ((b.visible()) && (targets[callcode] !== undefined)) {

			var myAjax = new Ajax.Request(server + targets[callcode], {
				method: 'get',
				parameters: params,
				onComplete:	function(request) {
					if (request.status >= 400) {
						Element.update(contentid,'<p><div>An error occured during the connection (code: ' + request.status + ').</div><div>Please try again...</div></p><p style="margin-top: 5px;"><div style="font-size: 11px;"><a href="javascript:nop();" onClick="javascript:Element.hide(\'' + targetid + '\');">close this window</a></div></p>');
					} else {
						request.responseText.evalScripts();
						Element.update(contentid,request.responseText);
					}
				}
			});
		}
	}

	if (f) {
		f.enable();
	}	
}

var lastid;

function openThread(targetid,contentid,movetoid,callcode,params,offl,offt,width) {

	var a;
	var b;

	var v;

	if ((a = $(movetoid)) && (b = $(targetid))) {

		if (boxv[callcode] == undefined) {
			
			boxv[callcode] = Array();
			
			if (width = parseInt(width)) {
				boxv[callcode].push(width);
			} else {
				boxv[callcode].push(180);
			}
	
			if (v = parseInt(offl)) {
				boxv[callcode].push(offl);			
			} else {
				boxv[callcode].push(10);
			}
	
			if (offt = parseInt(offt)) {
				boxv[callcode].push(offt);			
			} else {
				boxv[callcode].push(20);
			}
			
		}

		params = params + '&movetoid=' + movetoid;
		
		$('add_itin_header').setStyle({width: boxv[callcode][0] + 'px'});
			
		width = boxv[callcode].width - 40;
	
		$('add_itin_content').setStyle({width: boxv[callcode][0] + 'px'});
			//Element.hide(b);
			
		if ((lastid == movetoid) && b.visible()) {
			Element.hide(b);
		} else {
			lastid = movetoid;
			Element.update(contentid,'<img src="images/wait.gif" border="0" width="33" height="33" alt="Please wait..." />');
			
			var p = Element.cumulativeOffset(a);
			//Element.clonePosition(b,a,{offsetLeft: boxv[callcode][1], offsetTop: boxv[callcode][2],setWidth: false, setHeight: false});
			b.setStyle({left: p[0] + boxv[callcode][1] + 'px',top: p[1] + boxv[callcode][2] + 'px'});
			Element.show(b);
			
					if ((b.visible()) && (targets[callcode] !== undefined)) {

						var myAjax = new Ajax.Request(server + targets[callcode], {
							method: 'get',
							parameters: params,
							onComplete:	function(request) {
		
								if (request.status >= 400) {
									Element.update(contentid,'<p><div>An error occured during the connection (code: ' + request.status + ').</div><div>Please try again...</div></p><p style="margin-top: 5px;"><div style="font-size: 11px;"><a href="javascript:nop();" onClick="javascript:Element.hide(\'' + targetid + '\');">close this window</a></div></p>');
								} else {
									request.responseText.evalScripts();
									Element.update(contentid,request.responseText);
								}
							}
				});
			}
		}
	}
}
