function validate(value,type,minSize,maxSize,selectIndex){
	// validate as number
	if(type<2){
		if(type==0){
			for(var i=0;i<value.length;i++){
				if(isNaN(value.charAt(i))) return false;
				};
			};
		if(value.length<minSize||value.length>maxSize) return false;
		return true;
		};
	if(type==2){
		posAt = value.indexOf("@");
		posDt = value.lastIndexOf(".");
		if(!(posAt>0&&posAt<posDt&&posDt<value.length-1)) return false
		else return true;
		};
	if(type==3){
		if(selectIndex==minSize) return false;
		else return true;
		};
	};
		
function checkElement(aFormInfo,anElement){
	if(aFormInfo.type==3){
		var aValue = anElement.options[anElement.selectedIndex].text
		var selectIndex = anElement.selectedIndex;
		}
	else{
		var aValue = anElement.value
		var selectIndex = null;
		};
	// is required?
	if(aFormInfo.required){
		// is empty
		if(aValue==""){
			alert(aFormInfo.valErrMsg);
			anElement.focus();
			return false
			}
		else{
			if(aFormInfo.validate){
				if(!validate(aValue,aFormInfo.type,aFormInfo.minSize,aFormInfo.maxSize,selectIndex)){
					alert(aFormInfo.valErrMsg);
					anElement.focus();
					return false;
					};
				};
			};
		}
	// not required
	else{
		if(!(aValue=="")){
			if(aFormInfo.validate){
				if(!validate(aValue,aFormInfo.type,aFormInfo.minSize,aFormInfo.maxSize,selectIndex)){
					alert(aFormInfo.valErrMsg);
					anElement.focus();
					return false;
					};
				};
			};
		};
	return true;
	};

function setupDialogueMessage(){
	var seperator = '';
	for(var i=0;i<41;i++) seperator += "=";
	seperator += "\n"
	var DialogueMessage = "Subject: " + document.Dialogue.DialogueSubject.options[document.Dialogue.DialogueSubject.selectedIndex].text + "\n"
		+ seperator
		+ "Last Name: " + document.Dialogue.LastName.value + "\n"
		+ "First Name: " + document.Dialogue.FirstName.value + "\n" 
		+ "Street: " + document.Dialogue.Street.value + "\n" 
		+ "Zip Code: " + document.Dialogue.Zip.value + "\n" 
		+ "City: " + document.Dialogue.City.value + "\n" 
		+ "Country: " + document.Dialogue.Country.value + "\n"
		+ seperator
		+ "Telephone with Area Code: " + document.Dialogue.Phone.value + "\n" 
		+ "E-mail: " + document.Dialogue.Email.value + "\n"
		+ seperator
		+ "Your Message:\n\n" + document.Dialogue.Comment.value;
	document.Dialogue.SenderName.value = document.Dialogue.FirstName.value + " " + document.Dialogue.LastName.value;
	document.Dialogue.From.value = document.Dialogue.Email.value;
	document.Dialogue.Message.value = DialogueMessage;
	document.Dialogue.MerchantID.value = merchantID;
	document.Dialogue.Build.value = replace(build,".","");
	document.Dialogue.SiteDirectory.value = unescape(location.href.substring(0,location.href.indexOf("dialogue.htm")));
	return true;
	};
	
	
function checkForm(){
	for(var i=0;i<dialogueInfo.length;i++){
		for(var j=0;j<document.Dialogue.elements.length;j++){
			if(dialogueInfo[i].id==document.Dialogue.elements[j].name){
				if(!(checkElement(dialogueInfo[i],document.Dialogue.elements[j]))){
					return false
					};
				};
			};
		};
	return setupDialogueMessage();
	};


var dialogueInfo = new Array()


dialogueInfo[dialogueInfo.length] = new TFormInfo("DialogueSubject",3,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("LastName",1,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("FirstName",1,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("Street",1,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("Zip",0,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("City",1,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("Country",1,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("Phone",1,false,false,0,0,"","")

dialogueInfo[dialogueInfo.length] = new TFormInfo("Email",2,true,true,0,0,"","The form is incomplete. Please enter a valid 'E-mail Address'.")

dialogueInfo[dialogueInfo.length] = new TFormInfo("Comment",1,true,false,0,0,"","The form is incomplete. Please write your message.")




function TFormInfo(id,type,required,validate,minSize,maxSize,reqErrMsg,valErrMsg){
	// type
	// ==> 0: number
	// ==> 1: string
	// ==> 2: email
	// ==> 3: select ( minSize = invalid Index || null )
	this.id = id;
	this.type = type;
	this.required = required;
	this.validate = validate;
	this.minSize = minSize;
	this.maxSize = maxSize;
	this.reqErrMsg = reqErrMsg;
	this.valErrMsg = valErrMsg;
	};
