function gettrade(pars) {
	$('placeholder').update('<br><br><br><br><br><br><center>Loading...<br><img src="/img/32-0.gif"></center>');
	var url = '/trade.php';
	var myAjax = new Ajax.Updater(
		{success: 'placeholder'}, 
		url, 
		{method: 'get', parameters: pars, onFailure: reportError});
}

function getaffiliates(pars) {
	$('affiliates').update('<br><br><br><br><br><br><center>Loading...<br><img src="/img/32-0.gif"></center>');
	var url = '/sponsors.php';
	var myAjax = new Ajax.Updater(
		{success: 'affiliates'}, 
		url, 
		{method: 'get', parameters: pars, onFailure: reportError});
}

function getrules(site) {
	if (site == '') return;
	$('rules').update('<br><br><br><br><br><br><center>Loading...<br><img src="/img/32-0.gif"></center>');
	var url = '/manage/rules.php';
	pars = 'site=' + site;
	var myAjax = new Ajax.Updater(
		{success: 'rules'}, 
		url,
		{method: 'get', parameters: pars});
}

function contactform(pars) {
	var url = '/contact.php';
	if (pars == 'send') {
		reqpars = $('contact_form').getElements('contact_form');
		var params = new Array ('Name', 'E-mail', 'Subject', 'Message');
		var patterns = new Array (/^(.*)$/i, /^\w+[\.\w\-]*\w+@\w+[\.\w\-]*\w+\.\w{2,4}$/i, /^(.*)$/i, /^(.*)$/im);
		var freq = false;
//		for (j=3; j>=0; j--) $(params[j]).update('&nbsp;');
		/*/^[a-zA-Z0-9](([a-z0-9\-_\+\&]?)+[a-z0-9])?\@((\w([a-zA-Z0-9\-_]+\w)?\.[a-z]{2,4})|(([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d |2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5]))|(localhost))$/*/
		for (j=3; j>=0; j--) {
			if (!reqpars[j].present()) {
				reqpars[j].focus();
				$(params[j]).update(params[j]+' not entered!');
				freq = true;
			} else
			if (!patterns[j].test(reqpars[j].value)) {
				reqpars[j].focus();
				reqpars[j].select();
				$(params[j]).update('Invalid '+params[j]);
				freq = true;
			} else $(params[j]).update('&nbsp;');
		}
		if (freq) return false;
		pars = $('contact_form').serialize();
	}
	$('contactholder').update('<br><center>Loading...<br><img src="/img/32-0.gif"></center>');
	var myAjax = new Ajax.Updater(
		{success: 'contactholder'}, 
		url, 
		{method: 'get', parameters: pars, onFailure: reportError});
}

function settrade() {
	var url='/trade.php';
	pars = $('RegFormContent').serialize();
	var myAjax = new Ajax.Updater(
		{success: 'placeholder'}, 
		url, 
		{method: 'get', parameters: pars, onFailure: reportError});
}

function reportError(request) {
		alert('Sorry. There was an error.');
}
function pnt(x, y){
        this.x=x;
        this.y=y;
        return this;
}
/* reg form animation */

function RegFormClass(sID){
        this.Init(sID);
}

RegFormClass.prototype.Init=function(sID){
        this.oPtr=document.getElementById(sID);
        this.oFrame=document.getElementById(sID+'Frame');
        this.oContent=document.getElementById(sID+'Content');
        this.x=this.oFrame.offsetLeft;
        this.y=this.oFrame.offsetTop;
        this.bVisible=false;
}

RegFormClass.prototype.onAnimationOver=function(){
        delete this.onAnimate;
}

RegFormClass.prototype.InitResize=function(oSPnt, oTPnt, iDecay, oSnapPoint){
        this.sW=oSPnt.x;
        this.sH=oSPnt.y;
        this.tW=oTPnt.x;
        this.tH=oTPnt.y;
        this.d=iDecay;

        this.x=this.oFrame.offsetLeft;
        this.y=this.oFrame.offsetTop;

        this.iBodyWidth=document.body.clientWidth;
        this.bWide=(oSPnt.x < oTPnt.x);

        this.oSnapInit=new pnt(this.sW, this.sH);
        this.oSnapPoint=new pnt(this.sW/2, this.sH/2);

        this.onAnimate=this.Resize;
}

RegFormClass.prototype.Resize=function(){
        this.sW+=(this.tW-this.sW)*this.d;
        this.sH+=(this.tH-this.sH)*this.d;

        if(Math.abs(this.tW-this.sW) < 2 && Math.abs(this.tH-this.sH) < 2){
                this.sW=this.tW;
                this.sH=this.tH;
                this.onAnimationOver();
        }

        //~ this.oPtr.style.fontSize=(this.bWide) ? Math.round(this.sW/this.tW * 100)+'%' : Math.round(this.sW/this.oSnapInit.x * 100)+'%';
        this.oPtr.style.width=this.sW+'px';
        this.oPtr.style.height=this.sH+'px';
        this.Snap();
}
RegFormClass.prototype.Snap=function(){
        var dx=this.oSnapPoint.x*(1 - this.sW/this.oSnapInit.x);
        var dy=this.oSnapPoint.y*(1 - this.sH/this.oSnapInit.y);
        this.MoveTo(this.x + dx, this.y + dy);
}

RegFormClass.prototype.MoveTo=function(x, y){
        this.oFrame.style.left=x+'px';
        this.oFrame.style.top=y+'px';
}

RegFormClass.prototype.Show=function(){
        this.bVisible=true;
        this.oFrame.style.visibility="visible";
        this.oContent.style.display="none";
        this.InitResize(new pnt(50, 50), new pnt(650, 450),.4);
        this.onAnimationOver=function(){
                delete this.onAnimate;
                this.oContent.style.display="block";
        }
        return false;
}

RegFormClass.prototype.Hide=function(){
        this.bVisible=false;
        this.InitResize(new pnt(650, 450), new pnt(50, 50),.4);
        this.oContent.style.display="none";
        this.onAnimationOver=function(){
                this.oFrame.style.visibility="hidden";
                delete this.onAnimate;
        }
        return false;

}

RegFormClass.prototype.Switch=function(site){
	getrules(site);
	$('rules').show();
	$('tradeform').hide();
	$('FixedElement').show();
	if(this.bVisible) {
		$('rules').update('');
                return this.Hide();
		}
        else {
	        return this.Show();
	}
}

function RegFormAnimate(){
        if(oRegForm.onAnimate)
                oRegForm.onAnimate();
}

function dalert(str){
        document.getElementById('debug').innerHTML+=str+'<br />';
}

function setdomain(str1,str2,str3){
        document.getElementById('RegFormContent').tradesite.value=str1;
        document.getElementById('RegFormContent').trademail.value=str2;
        document.getElementById('RegFormContent').tradenick.value=str3;
}

required = new Array("domain", "url", "title", "description", "nickname", "email", "icq");

function SendForm() {
	reqpars = $('RegFormContent').getElements('RegFormContent');
	var params = new Array ('er_domain', 'er_url', 'er_title', 'er_description', 'er_nick', 'er_e-mail', 'er_icq');
	var paramsname = new Array ('Domain', 'Url', 'Title', 'Description', 'Nick', 'E-mail', 'Icq');
	var patterns = new Array ((/^([^\.]*\.(?!info|biz)[^\.]{2,3})$/i), 
				(/^(https?:\/\/[^\.]*\..*)$/i), 
				(/^(.*)$/i), 
				(/^(.*)$/i), 
				(/^(.*)$/i), 
				(/^\w+[\.\w\-]*\w+@\w+[\.\w\-]*\w+\.\w{2,4}$/i), 
				(/^(\d{5,9})$/i));
	var freq = false;
//	for (j=6; j>=0; j--) $(params[j]).update('&nbsp;');
	for (j=6; j>=0; j--) {
		if (!reqpars[j].present()) {
			reqpars[j].focus();
			$(params[j]).update(paramsname[j]+' not entered!');
			freq = true;
		} else
		if (!patterns[j].test(reqpars[j].value)) {
			reqpars[j].focus();
			reqpars[j].select();
			$(params[j]).update('Invalid '+paramsname[j]);
			freq = true;
		} else
		if (j == 0 && reqpars[1].value.indexOf(reqpars[0].value) < 0) {
			reqpars[0].focus();
			reqpars[0].select();
			$(params[0]).update('The domain doesn\'t appear in the url');
			freq = true;
		} else $(params[j]).update('&nbsp;');
	}
	if (freq) return false;
	$('placeholder').update('<br><br><br><br><br><br><center>Loading...<br><img src="/img/32-0.gif"></center>');
	settrade();
	setdomain('','',''); if(oRegForm) return oRegForm.Switch('');
	return true;
}

function acceptrule() {
$('rules').hide();
$('rules').update('');
$('tradeform').show();
}

