// JavaScript Document
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


function changeImageOn(current)
{
	if (document.images && (preloadFlag == true))
	{
		thisSrc = current.src;
		if(thisSrc.indexOf("-over.png") < 0)
		{
			newSrc = thisSrc.substring(0, (thisSrc.length -4))+"-over.png";
			current.src = newSrc;
		}
	}
}

function changeImageOff(current)
{
	if (document.images && (preloadFlag == true))
	{
		thisSrc = current.src;
		if(thisSrc.indexOf("-over.png") > 0)
		{
			newSrc = thisSrc.substring(0, thisSrc.indexOf("-over.png"))+".png";
			current.src = newSrc;
		}
	}
}
function popupH(url) {
	newwindow=window.open(url,'name','height=250,width=330');
	if (window.focus) {newwindow.focus()}
	return false;
}
function popupV(url) {
	newwindow=window.open(url,'name','height=436,width=330');
	if (window.focus) {newwindow.focus()}
	return false;
}



/* Kill dinosaur style roll over stuff

function changeImages(current, over) {
	if (document.images && (preloadFlag == true)) {
		current.src = "images/"+over+".png";
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
*/

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		home_but_over = newImage("images/home_but-over.png");
		about_but_over = newImage("images/about_but-over.png");
		exhibitions_but_over = newImage("images/exhibitions_but-over.png");
		news_but_over = newImage("images/news_but-over.png");
		designers_but_over = newImage("images/designers_but-over.png");
		press_but_over = newImage("images/press_but-over.png");
		contact_but_over = newImage("images/contact_but-over.png");
		sitemap_but_over = newImage("images/sitemap_but-over.png");
		
		preloadFlag = true;
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addBookmark(url, desc)
{
	var ver = navigator.appName;
	var num = parseInt(navigator.appVersion);
	
	if ((ver == "Microsoft Internet Explorer")&&(num >= 4))
	{
		javascript:window.external.AddFavorite(url, desc);
	}
	else
	{
		alert("To add a bookmark, please press Control-D.");
	} 
}

function validEmail(email) {
	invalidChars = " /:,;"

	if (email == "") {						// cannot be empty
		return false
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	domainName = email.substring(atPos+1, periodPos)
	if (domainName.length < 2) {			// Cannot have a domain less than 2 characters long
		return false
	}
	return true
}

function sendEmail(id)
{	
	url = "/mailPopup.htm?a="+id;
	window.open(url, 'email_window','width=335, height=193, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0');
}



function checkMailForm(formy)
{
	if(formy.yourname.value == "" || formy.yourname.value == null)
	{
		alert("Please enter your name.");
		formy.yourname.focus();
		formy.yourname.style.border = "1px solid #cc0000";
		return false;
	}
	else
	{
		formy.yourname.style.border = "1px solid #000000";
	}
	
	if(formy.name.value == "" || formy.name.value == null)
	{
		alert("Please enter your friend's name.");
		formy.name.focus();
		formy.name.style.border = "1px solid #cc0000";
		return false;
	}
	else
	{
		formy.name.style.border = "1px solid #000000";
	}
	
	if(!validEmail(formy.email.value))
	{
		alert("Please enter a valid email address.");
		formy.email.select();
		formy.email.style.border = "1px solid #cc0000";
		return false;
	}
	else
	{
		formy.email.style.border = "1px solid #000000";
	}
	
	return true;
}
