// Common JavaScript code for web site
//
// 01.00 - 06/09/2005 - Mark Davies - 1st Version
// 01.01 - 06/08/2007 - Mark Davies - add Board demo & contact_us stuff
// 01.02 - 05/02/2010 - Mark Davies - telephone number

function checkwindowlinklarge(strURL,strName,intReqWidth,intReqHeight,intReqBorder) {

var strcurrloc;
var iskipcheck = 0;

 strcurrloc = window.location.href;
 //if there is a 'skipcheck' parameter, then we skip the OS, browser & .Net check
 if (strcurrloc.indexOf("skipcheck") != -1) {
 	iskipcheck = 1
 	window.alert("Skipping OS, browser & .Net check...");
 	};

 if ((navigator.userAgent.indexOf("Windows NT") == -1 || navigator.userAgent.indexOf("Windows NT 4") != -1) && (iskipcheck == 0)) {
	openwindowlinklarge("smart/db_demo/xp2000reqd.htm","xp200reqd",800,350,50,'no');
	}
 else if ((navigator.userAgent.indexOf("MSIE") == -1 || navigator.userAgent.indexOf("MSIE 4") != -1) && (iskipcheck == 0)) {
	openwindowlinklarge("smart/db_demo/iereqd.htm","iereqd",800,350,50,'no');
	}
 else if ((navigator.userAgent.indexOf(".NET CLR") == -1 || navigator.userAgent.indexOf(".NET CLR 1.0") != -1) && (iskipcheck == 0)) {
	openwindowlinklarge("smart/db_demo/dotnetreqd.htm","dotnetreqd",800,350,50,'no');
	}
 else {
 	openwindowlinklarge(strURL,strName,intReqWidth,intReqHeight,intReqBorder,'no');
 	};
 }

function openwindowlinklarge(strURL,strName,intReqWidth,intReqHeight,intReqBorder,strToolbarYesNo) {
 var intWindowLeft;
 var intWindowTop;
 var intWindowHeight;
 var intWindowWidth;
 var strYesNo;
 var strDebugYesNo;

 strYesNo = "yes";
 strDebugYesNo = "no";
 if (screen.availHeight > intReqHeight+intReqBorder) {intWindowHeight = intReqHeight} else {intWindowHeight = screen.availHeight - intReqBorder;};
 if (screen.availWidth > intReqWidth+intReqBorder) {intWindowWidth = intReqWidth} else {intWindowWidth = screen.availWidth - intReqBorder;};
 intWindowTop = (screen.availHeight - intWindowHeight) / 2; 
 intWindowLeft = (screen.availWidth - intWindowWidth) / 2;
 //window.alert ("h=" + screen.availHeight + ";w=" + screen.availWidth + ';width=' + intWindowWidth + ',height=' + intWindowHeight + ',left=' + intWindowLeft + ',top=' + intWindowTop);
 //window.alert(strURL+" "+strName+'scrollbars=' + strYesNo +',resizable=' + strYesNo + ',menubar=' + strDebugYesNo + ',toolbar=' + strToolbarYesNo + ',status=' + strDebugYesNo + ',width=' + intWindowWidth + ',height=' + intWindowHeight + ',left=' + intWindowLeft + ',top=' + intWindowTop); 
 window.open(strURL,strName,'scrollbars=' + strYesNo +',resizable=' + strYesNo + ',menubar=' + strDebugYesNo + ',toolbar=' + strToolbarYesNo + ',status=' + strDebugYesNo + ',location=' + strYesNo + ',width=' + intWindowWidth + ',height=' + intWindowHeight + ',left=' + intWindowLeft + ',top=' + intWindowTop); 
}

// Board demo specific routines

function WriteBoardHREF() {

// Build the HREF 
strDemoHREF=
	"<a href=" + 
	'"' + 
	"javascript:openwindowlinklarge('boarddemo/solutions_boardmit_demo.htm','BoardDemo',1024,768,50,'yes')" + 
	'"' + 
	">Board Demo</a>";

//window.alert(strDemoHREF);
document.write(strDemoHREF);

}

function WriteBoardHREFImage() {

// Build the HREF 
strDemoHREF=
	"<a href=" + 
	'"' + 
	"javascript:openwindowlinklarge('boarddemo/solutions_boardmit_demo.htm','BoardDemo',1024,768,50,'yes')" +
	'"><img src="images/affiniteeu/demo1_100x100.gif" width="100" height="100" alt="See Board Demo" class="pic-rightbar"></a>';

//window.alert(strDemoHREF);
document.write(strDemoHREF);

}

function WriteBoardHREFSentence() {

// Build the HREF 
strDemoHREF=
	"<a href=" + 
	'"' + 
	"javascript:openwindowlinklarge('boarddemo/solutions_boardmit_demo.htm','BoardDemo',1024,768,50,'yes')" + 
	'"' + 
	">Board Demo</a>";

//window.alert(strDemoHREF);
document.write("<p>If you want to see a working Board example, then please click on " + strDemoHREF + "</p>\n");

}

// contact_us specific routines

//Left trim method: strltrim

        function strltrim() {
            //Match spaces at beginning of text and replace with a null string
            return this.replace(/^\s+/,'');
        }
    
//Right trim method: strrtrim

        function strrtrim() {
            //Match spaces at end of text and replace with a null string
            return this.replace(/\s+$/,'');
        }
   
//Trim method: strtrim

        function strtrim() {
            //Match spaces at beginning and end of text and replace
            //with null strings
            return this.replace(/^\s+/,'').replace(/\s+$/,'');
        }

//In using the keyword this in each of these methods, we are anticipating the fact that 
//the method will be added to the String object, in which case this represents the object.
//To complete our solution, all we need to do is to add the methods to the String object
//via the prototype property as follows:

        String.prototype.ltrim = strltrim;
        String.prototype.rtrim = strrtrim;
        String.prototype.trim = strtrim;

function validate() {

var strcategory;
var strname;
var strjob;
var strcompany;
var straddress1;
var straddress2;
var strcountry;
var strtel;
var strfax;
var stremail;
var strcomments;

	if (document.form1.category.selectedIndex == 0) {
	    window.alert("Please select a category.");
		return false;
	};
//  We need to check length to match what we do in the perl script
//	strcategory = document.form1.category.value.trim();
//    if (strcategory.length < 1) {
//	    window.alert("Category too short.");
//		return false;
//	};
//    if (strcategory.length > 50) {
//	    window.alert("Category too long - maximum 50 characters.");
//		return false;
//	};
	strname = document.form1.name.value.trim();
    if (strname.length < 1) {
	    window.alert("Please enter your name.");
		return false;
	};
    if (strname.length > 50) {
	    window.alert("Name too long - maximum 50 characters.");
		return false;
	};
	strjob = document.form1.job.value.trim();
    if (strjob.length > 50) {
	    window.alert("Job Title too long - maximum 50 characters.");
		return false;
	};
	strcompany = document.form1.company.value.trim();
    if (strcompany.length < 1) {
	    window.alert("Please enter your Company Name.");
		return false;
	};
    if (strcompany.length > 50) {
	    window.alert("Company Name too long - maximum 50 characters.");
		return false;
	};
	straddress1 = document.form1.address1.value.trim();
    if (straddress1.length > 50) {
	    window.alert("Address1 too long - maximum 50 characters.");
		return false;
	};
	straddress2 = document.form1.address2.value.trim();
    if (straddress2.length > 50) {
	    window.alert("Address2 too long - maximum 50 characters.");
		return false;
	};
	strcountry = document.form1.country.value.trim();
    if (strcountry.length > 50) {
	    window.alert("Country too long - maximum 50 characters.");
		return false;
	};
	strtel = document.form1.telephone.value.trim();
    if (strtel.length < 1 || strtel == '000-000-0000' || strtel == '0000000000') {
	    window.alert("Please enter a valid Telephone Number.");
		return false;
	};
    if (strtel.length > 50) {
	    window.alert("Telephone Number too long - maximum 50 characters.");
		return false;
	};
	strfax = document.form1.fax.value.trim();
    if (strfax.length > 50) {
	    window.alert("Fax Number too long - maximum 50 characters.");
		return false;
	};
	stremail = document.form1.email.value.trim();
    if (stremail.length < 5 || stremail.indexOf('@') == -1 || stremail.indexOf('.') == -1) { // at least 5 chars, containing an @ and a . e.g. a@b.c
	    window.alert("Please enter a valid Email Address.");
		return false;
	};
    if (stremail.length > 50) {
	    window.alert("Email Address too long - maximum 50 characters.");
		return false;
	};
	strcomments = document.form1.comments.value.trim();
    if (strcomments.length > 500) {
	    window.alert("Comments too long - maximum 500 characters.");
		return false;
	};
    if (strcomments.indexOf("<a>") != -1 || strcomments.indexOf("</a>") != -1) {
	    window.alert("Sorry, comments cannot contain html tags.");
		return false;
	};
    if (strcomments.indexOf("Привет") != -1) {
	    window.alert("Sorry, comments cannot contain the phrase 'Привет'.");
		return false;
	};	

	return true;
};

function validate2() {
	return true;
};

