var win = null;

function forceframe(pIndex)
{
	var pageLoc = self.location; 											// Store location of this page
	
	if (pageLoc == top.location) 	
	{			// if the location of the page and container is the same then it has been opened directly
		var pagestr = pageLoc.toString()		// convert page location object to a string so we can manipulate it.
		var i = pagestr.lastIndexOf("/")+1; 		// find the position of the final occurance of the forwardslash '/' and add one
		contentSrc = escape(pagestr.substr(i));		// strip off the text after the final forwardslash (ie: the page name), escape encode it and stick it in contentSrc
		top.location.href = pIndex + '?' + contentSrc 	// set the location of the top page to the toppagename + page wanted
	}
}

function NewWindow(mypage,myname,w,h,scroll,pos)
{
	var lFull = false;
	
	if (w==0) w = screen.width - 50;							// If Width or height passed as zero set to screen width / height
	if (h==0) 
	{
		h = screen.height - 50;				// cater for the title bar
		lFull = true;
	}

	if (pos=="random")
	{
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos=="left")
	{
		LeftPosition=1;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos=="center")
	{
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null)
	{
		LeftPosition=0;
		TopPosition=20
	}
	
	if (lFull) TopPosition=0;
 	
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	
	if (win !== null) {win.close()}
	
	win = window.open(mypage,myname,settings);
}

function NewWindowResize(mypage,myname,w,h,scroll,pos)
{
	var lFull = false;
	
	if (w==0) w = screen.width - 50;							// If Width or height passed as zero set to screen width / height
	if (h==0) 
	{
		h = screen.height - 95;				// cater for the address & title bar
		lFull = true;
	}

	if (pos=="random")
	{
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos=="left")
	{
		LeftPosition=1;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos=="center")
	{
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null)
	{
		LeftPosition=0;
		TopPosition=20
	}
	
	if (lFull) TopPosition=0;
	
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=yes,resizable=yes';

	if (win !== null) {win.close()}
	
	win = window.open(mypage,myname,settings);
}

function CentreMe(vw, vh)
{
	// determine max screen height / width 
	var w = screen.width;
	var h = screen.height;
	
	// if desired with or height not specified (or specified too large) then set to screen dimensions.
	vw = (vw == 0 || vw > w) ? w : vw;
	vh = (vh == 0 || vh > h) ? h : vh;
	
	var nleft = (w/2) - (vw/2);
	var ntop = (h/2) - (vh/2);
	
	parent.window.moveTo(nleft,ntop);
	parent.window.resizeTo(vw,vh);	
}

function javaresize()
{
	var w = screen.width;
	var h = screen.height;
	alert("w : h : "+w+" : "+h);
	

	var myWidth = 0, myHeight = 0;
	
	if (typeof(window.innerWidth) == 'number')
	{
		alert("Non IE");
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		alert("IE6+");
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		alert("IE4 Compat");
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	window.alert( 'Width = ' + myWidth );
	window.alert( 'Height = ' + myHeight );
	
	parent.window.moveTo(0,0);
	parent.window.resizeTo(w,h);
	
	alert("Post Set");
	
}

function check_email_form()
{
	var cName, cEmail, cEnquiry;
	var cError, lReturn;

	lReturn = true;
	cError = 'The following fields are mandatory :';

    with(window.document.email_form)
    {
		cName = Name;
 		cEmail = Email;
 		cEnquiry = Enquiry;
   }

	// Name Validation
	if(trim(cName.value) == '')
	{
		cError = cError + 'Name, ';
//		cName.focus();
		change('Name','badbox');
		lReturn = false;
	}
	else
	{
		change('Name','goodbox');
	}

	if(trim(cEnquiry.value) == '')
	{
		cError = cError + 'Enquiry, ';
//		cEnquiry.focus();
		change('Enquiry','badbox');
		lReturn = false;
	}
	else
	{
		change('Enquiry','goodbox');
	}

	if(trim(cEmail.value) == '')
	{
		cError = cError + 'E-Mail, ';
		change('Email','badbox');
		lReturn = false;
	}
	else if(!isEmail(trim(cEmail.value)))
	{
		alert('Invalid e-mail');
		change('Email','badbox');
		lReturn = false;
	}
	else
	{
		change('Email','goodbox');
	}
	
	if (!lReturn) alert(cError);

    return lReturn;
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

function change(id, newClass)
{
	identity=document.getElementById(id);
	identity.className=newClass;
}

function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}
