// (c) dMOTION.com - dMS, the direct management system

d 				= document;
FormType		= new Array();
FormTxt     	= new Array();
FormColor     	= new Array();

/////////////////////////////////////////////////////////////////////////////////////
//	ALL THE VARIABLES
/////////////////////////////////////////////////////////////////////////////////////

	/* SEE FUNCTIONS.PHP FOR THESE VALUES */

/////////////////////////////////////////////////////////////////////////////////////
//	CHECK FIELDS FOR MINIMUM INPUT
/////////////////////////////////////////////////////////////////////////////////////

function CheckFields()
    {
for (i=1; i<RequiredFields+1; i++) 
	{
Field = d.getElementById('Required_'+i);

	if((Field.value == '') || (Field.value.length < MinimumInput) || (Field.value == 'null'))
		{
	alert(FormTxt[3]+' '+FormType[i]+' '+FormTxt[4]);
	if(Field.value != 'null')ErrorField('Error','Required_'+i);
	return false;
		}
	}

return CheckMail();
    }

/////////////////////////////////////////////////////////////////////////////////////
//	CHECK MAILFIELD-SYNTAX
/////////////////////////////////////////////////////////////////////////////////////

function CheckMail()
    {
Field = d.getElementById(MailField);

ValidChr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@.-_;';

	for (x=0; x<Field.value.length; x++) 
    	{
	TempValue = '' + Field.value.substring(x, x+1);
	if (ValidChr.indexOf(TempValue) == '-1')
	    {
	alert(FormTxt[1]);
	ErrorField('Error',MailField);
	return false;
	    }
    	}

	if ((Field.value.indexOf('@') == -1) || (Field.value.indexOf('.') == -1))
        {
    alert(FormTxt[2]);
    ErrorField('Error',MailField);
    return false;
        }

	MailConfirm = confirm(FormTxt[5]+Field.value+FormTxt[6]);

	if(MailConfirm)
		{
	d.getElementById('FormButt').value 				= FormTxt[9];
	d.getElementById('FormButt').title 				= FormTxt[10];
	d.getElementById('FormButt').style.background 	= FormColor[5];
	d.getElementById('FormButt').style.color		= FormColor[6];
	return true;
		}
	else
		{
	d.getElementById(MailField).focus();
	return false;
		}
	}

/////////////////////////////////////////////////////////////////////////////////////
//	SET ATTENTION TO WRONG FIELDS
/////////////////////////////////////////////////////////////////////////////////////

function ErrorField(ActionType,Field)
    {
if(ActionType == 'Error')
    {
d.getElementById(Field).style.background	= FormColor[3];
d.getElementById(Field).style.color			= FormColor[4];
d.getElementById(Field).focus();
    }
else if(ActionType == 'ResetButt')
    {
d.getElementById('FormButt').value 			= FormTxt[7];
d.getElementById('FormButt').title 			= FormTxt[8];
	}
else
    {
d.getElementById(Field).style.background	= FormColor[1];
d.getElementById(Field).style.color			= FormColor[2];
    }
    }
	
/////////////////////////////////////////////////////////////////////////////////////
//	UPDATE DUMMY FIELDS FOR REQUIRED PULL-DOWN MENUS
/////////////////////////////////////////////////////////////////////////////////////

function UpdateDummy(TheValue,TheDummy)
	{
d.getElementById('Required_'+TheDummy).value = TheValue;
	}

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//	DETAILS-FORM
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

checkcss = '';

/////////////////////////////////////////////////////
//	OPERATING SYSTEM
/////////////////////////////////////////////////////

var ua = navigator.userAgent.toLowerCase();

if (ua.indexOf("win") != -1)
    {
TheOS = "Windows";
    }
else if (ua.indexOf("mac") != -1)
    {
TheOS = "Macintosh";
    }
else if (ua.indexOf("linux") != -1)
    {
TheOS = "Linux";
    }
else if (ua.indexOf("x11") != -1)
    {
TheOS = "Unix";
    }
else
    {
TheOS = "Computers";
    }

/////////////////////////////////////////////////////
//	JAVA ON or OFF
/////////////////////////////////////////////////////
    
if (!(navigator.javaEnabled()))
    {
java = "Java Enabled";
    }
else
    {
java = "Java Disabled";
    }

/////////////////////////////////////////////////////
//	STYLESHEET SUPPORT
/////////////////////////////////////////////////////

function CheckCSS()
    {
SheetYES    = "Sheets Enabled";
SheetNO     = "Sheets Disabled";
checktype   = document.layers ? document.checkcss : checkcss;
d.getElementById('stylesheets').value = ((checktype) ? SheetYES : SheetNO);
    }

/////////////////////////////////////////////////////
//	COLOR AND SCREEN
/////////////////////////////////////////////////////

Colors      = window.screen.colorDepth;
ColorTotal  = Math.pow (2, Colors);
Aliasing    = 'Aliasing Disabled';
if (window.screen.fontSmoothingEnabled == true)Aliasing = "Aliasing Enabled";

/////////////////////////////////////////////////////
//	TIMER
/////////////////////////////////////////////////////

TimeSeconds = 0;
TimeMinutes = 0;
TimeHours   = 0;

function Timer()
    {
if(TimeSeconds == 60){TimeMinutes++;TimeSeconds = 0;}
if(TimeMinutes == 60){TimeHours++;TimeMinutes = 0;}
d.getElementById('timer').value = TimeHours+' hours : '+TimeMinutes+' minutes : '+TimeSeconds+' seconds';
TimeSeconds++;
setTimeout('Timer()',1000);
    }

/////////////////////////////////////////////////////
//	LANGUAGE
/////////////////////////////////////////////////////

if (navigator.appName == 'Netscape')BrowserLanguage = navigator.language;
else {BrowserLanguage = navigator.browserLanguage;}

/////////////////////////////////////////////////////
//	COOKIES
/////////////////////////////////////////////////////
Cookie = "Cookies Disabled";
if (navigator.cookieEnabled == true)Cookie = "Cookies Enabled";

/////////////////////////////////////////////////////
//	CLICK COUNTER
/////////////////////////////////////////////////////

MouseClicks = 0;

function recordClick()
	{
MouseClicks++;
d.getElementById('clickcounter').value = MouseClicks;
	}

/////////////////////////////////////////////////////
//	ACTIVATE
/////////////////////////////////////////////////////

function GetDetails()
    {
d.getElementById('OS1').value				= TheOS;
d.getElementById('OS2').value				= navigator.platform
d.getElementById('history').value			= history.length;
d.getElementById('browser1').value			= navigator.appName;
d.getElementById('browser2').value			= navigator.userAgent;
d.getElementById('browser3').value			= navigator.appCodeName
d.getElementById('width').value				= screen.width;
d.getElementById('height').value			= screen.height;
d.getElementById('java').value				= java;
d.getElementById('colordepth').value		= Colors+' bits';
d.getElementById('colortotal').value		= ColorTotal;
d.getElementById('aliasing').value			= Aliasing;
d.getElementById('browserlanguage').value	= BrowserLanguage;
d.getElementById('cookie').value			= Cookie;
    }
	
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//	CAPTCHA'S
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

CaptchaCount 	= 1;	// default
CaptchaQuakeNr	= 1;	// default
CaptchaRounds	= 11;	// captchas to show before the final one
CaptchaSpeed	= 200;	// speed of animation, in milliseconds [1000 = 1 second]
CaptchaLiftOff	= 2000;	// time to wait before real animation starts

// get captcha code

function GetCaptchaCode(CodeID)
    {
CaptchaCodeID	= "";
KeyCode			= "";

	for(q = 0; q < CodeID.length; q += 2)
		{
	CaptchaCodeID = parseInt(CodeID.substr(q,[2])) + 23;
	CaptchaCodeID = unescape('%' + CaptchaCodeID.toString(16));
	KeyCode += CaptchaCodeID;
		}

CaptchaCodeID = unescape(KeyCode);
return CaptchaCodeID;
	}

CaptchaCode = GetCaptchaCode('7786922497939174247988918624727774937424767489937681749223');

// basic x/y offset for the quake-effect

CaptchaQuake	= new Array();
CaptchaQuake[1]	= '-1px 0 0 -1px';
CaptchaQuake[2]	= '1px 0 0 1px';
CaptchaQuake[3]	= '1px 0 0 -1px';
CaptchaQuake[4]	= '-1px 0 0 1px';

// show captcha's - animated style [or not... clients choise...]

function Captcha(CaptchaTotal,CaptchaHeight,CaptchaID,CaptchaQuaked,CaptchaExt)
	{
if(CaptchaCount != CaptchaRounds)
		{
	if(CaptchaCount == 1)CaptchaOffset = CaptchaID+1;
	if(CaptchaOffset > CaptchaTotal)CaptchaOffset = 1;
	CaptchaBackground = CaptchaOffset*CaptchaHeight;
	d.getElementById("TheCaptcha").style.backgroundPosition = '0 -'+CaptchaBackground+'px';
	if(CaptchaQuaked)d.getElementById("TheCaptcha").style.margin = CaptchaQuake[CaptchaQuakeNr];
	CaptchaOffset++;CaptchaCount++;CaptchaQuakeNr++;if(CaptchaQuakeNr == 5)CaptchaQuakeNr = 1;
	CaptchaTotalNew = CaptchaTotal;CaptchaHeightNew = CaptchaHeight;CaptchaIDnew = CaptchaID;CaptchaQuakedNew = CaptchaQuaked;CaptchaExtNew = CaptchaExt;
	setTimeout("Captcha(CaptchaTotalNew,CaptchaHeightNew,CaptchaIDnew,CaptchaQuakedNew,CaptchaExtNew)",CaptchaSpeed);
		}
	else
		{
	CaptchaBackground = (CaptchaID+1)*CaptchaHeight;
	d.getElementById("TheCaptcha").style.backgroundPosition = '0 -'+CaptchaBackground+'px';
	if(CaptchaQuaked)d.getElementById("TheCaptcha").style.margin = '0';
		}
	}

// write down the preload the captcha-image

function CaptchaLoad(CaptchaTotal,CaptchaHeight,CaptchaID,CaptchaQuaked,CaptchaExt)
	{
d.getElementById("TheCaptcha").style.backgroundImage = 'url("'+CaptchaCode+CaptchaExt+'")';
CaptchaTotalNew = CaptchaTotal;CaptchaHeightNew = CaptchaHeight;CaptchaIDnew = CaptchaID;CaptchaQuakedNew = CaptchaQuaked;CaptchaExtNew = CaptchaExt;
d.write ('<img src="'+CaptchaCode+CaptchaExt+'" width="1" height="1" alt="" id="CaptchaPreloader" onload="setTimeout(\'Captcha(CaptchaTotalNew,CaptchaHeightNew,CaptchaIDnew,CaptchaQuakedNew,CaptchaExtNew)\','+CaptchaLiftOff+');" />');
	}
	
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//	CLEAR DEFAULT INPUT FROM TEXT-FIELDS
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

function ResetField(TheField,TheText)
	{
			FieldValue = d.getElementById(TheField).value;
if(FieldValue == TheText)d.getElementById(TheField).value = '';
else if(FieldValue == '')d.getElementById(TheField).value = TheText;
	}
