
var loaded = false;
function loadImages() {
	if (document.images) {
		//back1 = loadImage("images/back1.gif");
		//title1 = loadImage("images/title1.gif");
		//title2 = loadImage("images/title2.gif");
		//nav1a = loadImage("images/nav1a.gif");
		//nav1b = loadImage("images/nav1b.gif");
		//nav2a = loadImage("images/nav2a.gif");
		//nav2b = loadImage("images/nav2b.gif");
		//nav3a = loadImage("images/nav3a.gif");
		//nav3b = loadImage("images/nav3b.gif");
		//nav4a = loadImage("images/nav4a.gif");
		//nav4b = loadImage("images/nav4b.gif");
		//nav5a = loadImage("images/nav5a.gif");
		//nav5b = loadImage("images/nav5b.gif");
		//nav6a = loadImage("images/nav6a.gif");
		//nav6b = loadImage("images/nav6b.gif");
		
		//expanded = loadImage('http://www.oldtownphoto.com/versions/version7/arrow6.gif');
		//collapsed = loadImage('http://www.oldtownphoto.com/versions/version7/arrow8.gif');
		blank = loadImage("http://www.oldtownphoto.com/versions/version6/blank.gif");
		arrow = loadImage("http://www.oldtownphoto.com/versions/version6/arrow-on.gif");
		arrow2 = loadImage("http://www.oldtownphoto.com/versions/version6/checkmark.gif");
		off = loadImage("http://www.oldtownphoto.com/versions/version6/blank.gif");
		on = loadImage("http://www.oldtownphoto.com/versions/version6/arrow77.gif");
		//offsub = loadImage("http://www.oldtownphoto.com/images/arrow9.gif");
		//onsub = loadImage("http://www.oldtownphoto.com/images/arrow10.gif");
		loaded = true;
	}
}

function loadImage(img) {
		temp = new Image();
		temp.src = img;
		return temp;
}

function roll(imgid,imgnew) {
	if (document.images && loaded) {
		document.images[imgid].src=eval(imgnew + ".src");
	}
}

function playSound() {
		document.sound1.play();
}

//-------------------------------------------------------------------

var delay = 1000 * 3;
var fade = 5;
var t;
var images = new Array();
//images[0] = 'images/columbus.jpg';
//images[1] = 'images/prague.gif';
//images[2] = 'images/a1000.gif';

var s = images.length;
var index = 0;
//var onImage = new Image();
//onImage.src = images[index];

var loadedSlide = new Array();
for (i = 0; i < s; i++) {
	loadedSlide[i] = new Image();
	loadedSlide[i].src = images[i];
}

function doAutoSlide() {
	if (document.all) {
		document.images.slide.style.filter="blendTrans(duration=fade)";
		document.images.slide.filters.blendTrans.Apply();
	}
	document.images.slide.src = loadedSlide[index].src;
	if (document.all) {
		document.images.slide.filters.blendTrans.Play();
	}
	index++;
	if (index == s ) index = 0;
	t = setTimeout('doAutoSlide()', delay);
}

//-------------------------------------------------------------------

function fadeOut(time) {
    photo.style.filter="blendTrans(duration=time)";
    // Make sure the filter is not playing.
    if (photo.filters.blendTrans.status != 2) {
        photo.filters.blendTrans.apply();
        photo.style.visibility="hidden";
        photo.filters.blendTrans.play();
    }
}
function fadeIn(time) {
    photo.style.filter="blendTrans(duration=time)";
    // Make sure the filter is not playing.
    if (photo.filters.blendTrans.status != 2) {
        photo.filters.blendTrans.apply();
        photo.style.visibility="visible";
        photo.filters.blendTrans.play();
    }
}


function RollPhoto(id) {
	var fade = 1;
	window.status = id; 
	if (document.all && ie55up) {
		roll('photo','blank');
		fadeIn(0.5);
		//setTimeout("fadeOut(0.5);", 2000);
		//fadeIn(0.5);
		//document.images.photo.style.filter="blendTrans(duration=fade)";
		//document.images.photo.filters.blendTrans.Apply();
	}	
	if (document.images) {
		thisPhoto = "photo" + id;
		document.photo.src=eval(thisPhoto + ".src");
		getObject("description").innerHTML = "";
		if (description[id]){
			getObject("description").innerHTML = description[id];
		}
	}
	if (document.all && ie55up) {
		//setTimeout("fadeOut(0.5);", 2000);
		fadeOut(0.5);
	}	
	//setTimeout("fadeIn(0.5);", 2000);
}

function RandomPhoto() {
	if(document.images.photo){
		//alert ("here");
    		var rn = Math.round(Math.random()*3) +1;
    		//alert(rn)
		RollPhoto(rn);
	}
}


function initialize() {
	loadImages();
	RandomPhoto();
}

//----------------
var warn = " Invalid Opperation !";
function click(e) {
  if (document.all) {
    if (event.button == 2) {
      //alert(warn);
      return false;
    }
  } else {
    if (e.which == 3) {
      //alert(warn);
      return false;
    }
  }
}
if (document.layers) {
  document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

//function BrowserDetect() {
	var agent = navigator.userAgent.toLowerCase(); 
	
	// Browser version
	var versionMajor = parseInt(navigator.appVersion); 
	var versionMinor = parseFloat(navigator.appVersion); 
    
	// Browser name
	var ns    = (agent.indexOf('mozilla')!=-1 && agent.indexOf('spoofer')==-1 && agent.indexOf('compatible') == -1 && agent.indexOf('opera')==-1 && agent.indexOf('webtv')==-1); 
	var ns2   = (ns && versionMajor == 2); 
	var ns3   = (ns && versionMajor == 3); 
	var ns4   = (ns && versionMajor == 4); 
	var ns4up = (ns && versionMajor >= 4); 
	var ns6   = (ns && versionMajor == 5); 
	var ns6up = (ns && versionMajor >= 5); 
	var ie    = (agent.indexOf("msie") != -1); 
	var ie3   = (ie && versionMajor < 4); 
	var ie4   = (ie && versionMajor == 4 && agent.indexOf("msie 4.0") != -1); 
	var ie4up = (ie && versionMajor >= 4); 
	var ie5   = (ie && versionMajor == 4 && agent.indexOf("msie 5.0") != -1); 
	var ie55  = (ie && versionMajor == 4 && agent.indexOf("msie 5.5") != -1);
	var ie5up = (ie && !ie3 && !ie4); 
	var ie55up = (ie && !ie3 && !ie4 && !ie5); 
	var ie6   = (ie && versionMajor == 4 && agent.indexOf("msie 6.0") != -1);
	var ie6up = (ie && !ie3 && !ie4 && !ie5 && !ie55); 
	var opera = (agent.indexOf("opera") != -1); 
	var webtv = (agent.indexOf("webtv") != -1); 
	var aol   = (agent.indexOf("aol") != -1);   
//}

//BrowserDetect();
if (!ns6up && !ie5up){
	var msg = "\n\nIncompatible Browser Detected. - "+versionMinor + "\n"+
	"Minimal browser requirements for this Web site is\nIE 5.0 or higher, or Netscape Navigator 6.0 higher\nYou browser will not display this Web-site properly.\nPlease update your browser by downloading the latest version.\n";
	alert(msg);
}

function PrintThis() {
	if (window.print) {
		setTimeout('window.print();',200);
	} else if (agent.indexOf("mac") != -1) {
		alert("Press 'Cmd+p' on your keyboard to print article.");
	} else {
		alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}

function PrePrint(page) {
	showWin = window.open(page,'viewer','height=300,width=600,status,left=10,screenX=10,top=200,screenY=200,z-lock,scrollbars=yes');
}

function sendIt (){
	if (document.forms.length > 0){
		document.forms[0].submit();
	}
}

function LoadImage(img) {
		temp = new Image();
		temp.src = img;
		return temp;
}

//--

function IsAlphanum(text, maxLength) {
  if ((text.length<maxLength)||(text.indexOf(" ")!=-1)){
    return false;
  }
  return true;
}

function IsValidEmail(text) {
  if ((text.length<6)||(text.indexOf(" ")!=-1)||(text.indexOf("@")==-1)||(text.indexOf(".")==-1)){
    return false;
  }
  return true;
}

function ValidateRetrieveForm() {
  if (! IsValidEmail(document.Retrieve.email.value)){
    document.Retrieve.email.focus();
    alert("Please enter your e-mail address.");
    return false;
  }
  return true;
}

function ValidatePrintorderForm() {
  if (! IsValidEmail(document.Printorder.email.value)){
    document.Printorder.email.focus();
    alert("Please enter your e-mail address.");
    return false;
  }
  if (document.Printorder.ship.selectedIndex < 2){
    document.Printorder.ship.focus();
    alert("Please select Shipping Option");
    return false;
  }
  return true;
}

function ValidateLoginForm() {
/*
  if (document.Login.month.selectedIndex == 0){
    document.Login.month.focus();
    alert("Please select Month for Session Date");
    return false;
  }
  if (document.Login.day.selectedIndex == 0){
    document.Login.day.focus();
    alert("Please select Day for Session Date");
    return false;
  }
  if (document.Login.code.value.length()<3){
    document.Login.code.focus();
    alert("Please enter Password.");
    return false;
  }
  */
  return true;
}

function ValidateContactForm() {
  if (document.ContactForm.name.value.length()< 3){
    document.ContactForm.name.focus();
    alert("Please enter your name.");
    return false;
  }
  if (! IsValidEmail(document.ContactForm.email.value)){
    document.ContactForm.email.focus();
    alert("Please enter your e-mail address.");
    return false;
  }
  if (document.ContactForm.detail.value.length()<5){
    document.ContactForm.detail.focus();
    alert("Please enter your message.");
    return false;
  }
  return true;
}

function ValidateFeedbackForm() {

  return true;
}

function ValidateShowOrderForm() {
  if (document.ShowOrder.invnum.value.length()<5){
    document.ShowOrder.invnum.focus();
    alert("Please enter Order Reference Number.");
    return false;
  }
  return true;
}

function ValidateWeddingQuoteForm() {
  if (document.WeddingQuote.month.selectedIndex == 0){
    document.WeddingQuote.month.focus();
    alert("Please select Month");
    return false;
  }
  if (document.WeddingQuote.day.selectedIndex == 0){
    document.WeddingQuote.day.focus();
    alert("Please select Day");
    return false;
  }
  if (document.WeddingQuote.startHour.selectedIndex == 0){
    document.WeddingQuote.startHour.focus();
    alert("Please select Start Hour");
    return false;
  }  
  if (document.WeddingQuote.startMinute.selectedIndex == 0){
    document.WeddingQuote.startMinute.focus();
    alert("Please select Start Minute");
    return false;
  }
  if (document.WeddingQuote.startampm.selectedIndex == 0){
    document.WeddingQuote.startampm.focus();
    alert("Please select AM or PM");
    return false;
  }  
  if (document.WeddingQuote.endHour.selectedIndex == 0){
    document.WeddingQuote.endHour.focus();
    alert("Please select End Hour");
    return false;
  }  
  if (document.WeddingQuote.endMinute.selectedIndex == 0){
    document.WeddingQuote.endMinute.focus();
    alert("Please select End Minute");
    return false;
  }
  if (document.WeddingQuote.endampm.selectedIndex == 0){
    document.WeddingQuote.endampm.focus();
    alert("Please select AM or PM");
    return false;
  }
  if (!IsValidEmail(document.WeddingQuote.email.value)){
    document.WeddingQuote.email.focus();
    alert("Please enter Valid Email Address");
    return false;
  }
  
  
  
  return true;
}









function ShowHideTime() {
//PhotographyTime.position='absolute';
PhotographyTime.visibility='hide';
  if (document.Contact.type.selectedIndex == 1){
  alert(PhotographyTime.visibility);
    PhotographyTime.visibility='show';
    alert(PhotographyTime.visibility);
  }
  return true;
}
//--------------------------------------------------
var description = new Array();

function RollPhoto_old(id) {
  if (document.images) {
    thisPhoto = "photo" + id;
    document.photo.src=eval(thisPhoto + ".src");
    getObject("description").innerHTML = "";
    if (description[id]){
       getObject("description").innerHTML = description[id];
    }
  }
}

function focus (){
  if (document.forms.length > 0){
    document.forms[0].elements[0].focus();
  }
}

function getObject(obj) {
	if (document.getElementById)
		return document.getElementById(obj)
	else if (document.all)
		return document.all[obj]
}


//----------------------------------

function expandimg(imgid,flag) {
	imgcontain=document.getElementById('imgcontain');
	bufferimg=document.getElementById('bufferimg');
	photo=document.getElementById('photo');
	//imgicon=document.getElementById('iconimg'+imgid);

	if(flag==2)	if(imgcontain.style.position=='absolute') { flag=0 } else { flag=1 };
	if(flag==3)	if(imgcontain.style.position=='absolute') { flag=1 } else { flag=0 };
	
	
	imgwid=photo.width;
	imghei=photo.height;

	if(imgwid>0) {
		if(flag==1) {
			if(imgwid>300) {
				midpoint=410-Math.round(imgwid/2);
				if(midpoint<10)  midpoint=10;

				imgcontain.style.width=imgwid+4;
				imgcontain.style.left=midpoint;
				imgcontain.style.position='absolute';
				imgcontain.style.borderStyle='solid';
				imgcontain.style.borderColor='#333333';
				imgcontain.style.borderWidth=2;
				bufferimg.style.height=imghei+1;
				//if(imgicon.width==22) imgicon.src="/images/imgexpand1.gif";
			} else {
				imgcontain.style.width=300;
				bufferimg.style.height=1;
				imgcontain.style.borderStyle='none';
				imgcontain.style.position='static';
				//if(imgicon.width==22) imgicon.src="/images/imgexpand0.gif";
			}
		} else {
			imgcontain.style.width=300;
			bufferimg.style.height=1;
			imgcontain.style.borderStyle='none';
			imgcontain.style.position='static';
			//if(imgicon.width==22) imgicon.src="/images/imgexpand0.gif";
		}
	}
}

//-------------------------------------------------------------------
function changecase(cstr) {
	var changestr = cstr.value;
	var newStr='';
	for( var i = 0; i < changestr.length; ++i ) { // make sure the number is all digits..
		var c = changestr.charAt(i);
		if( i == 0 ) {
			newStr=newStr+c.toUpperCase();
		} else {
			if ( changestr.charAt(i-1) == ' ' || changestr.charAt(i-1) == ',' || changestr.charAt(i-1) == ', ') {
				newStr=newStr+c.toUpperCase();
			} else {
				if ( (i + 1 < changestr.length ) && (changestr.charAt(i-2) == ' ' || changestr.charAt(i-2) == ',') && (changestr.charAt(i+1) == ' ' || changestr.charAt(i+1) == ',' || changestr.charAt(i+1) == ', ')){
					newStr=newStr+c.toUpperCase();
				} else {
					newStr=newStr+c.toLowerCase();
				}
			}
		}
	}
	cstr.value=newStr;
}
// -------------------------------
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
if(isNN)
	document.captureEvents(Event.KEYPRESS);
function autoTab(input,len, e){
	var keyCode = (isNN)?e.which:e.keyCode; 
	var filter = (isNN)?[0,8,9]:[0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)){
		input.value = input.value.slice(0,len);
		input.form[(getIndex(input)+1)%input.form.length].focus();
		input.form[(getIndex(input)+1)%input.form.length].select();
	}
	function containsElement(arr, ele){
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index]==ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input){
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index==-1)
			if (input.form[i] == input)index = i;
			else i++;
			//alert (index)
		return index;
	} 
	return true;
}

// -------------------------------

