// replace image 'id' with srcFile
function ppfMouseOver(id, srcFile) {
	el = document.getElementById(id);
	el.src = srcFile;
}

// shows 'id' element
function expand(id) {
	document.getElementById(id).style.display = "";
}

// hides 'id' element
function contract(id) {
	document.getElementById(id).style.display = "none";
}

// shows or hides 'id' element depending on current status
function toggle(id) {
	if (document.getElementById(id).style.display == "none") {
		expand(id);
	} else {
		contract(id);
	}
}

// preload array of images
var myimages = new Array()
function preloadimages() {
	for (i = 0; i < preloadimages.arguments.length; i++) {
		myimages[i] = new Image()
		myimages[i].src = preloadimages.arguments[i]
	}
}

//open tamardi.php from this directory
function tamardi() {
	window.open("tamardi.php","tamardi","toolbar=no,top="+((screen.height/2)-208)+",left="+((screen.width/2)-301)+",width=602,height=416");
}

//open tamardi.php from child directory
function tamardi_2() {
	window.open("../tamardi.php","tamardi","toolbar=no,top="+((screen.height/2)-208)+",left="+((screen.width/2)-301)+",width=602,height=416");
}

//open gallery.php from this directory
function artGallery(id) {

	if (window.innerHeight) {
		posTop = (window.innerHeight/2)-275;
	} else if (document.body.clientHeight) {
		posTop = (document.body.clientHeight/2)-255;
	} else {
		posTop = 10;
	}
	posTop = (posTop < 0) ? posTop = 10 : posTop = posTop;

	if (window.innerWidth) {
		posLeft = (window.innerWidth/2)-325;
	} else if (document.body.clientWidth) {
		posLeft = (document.body.clientWidth/2)-325;
	} else {
		posLeft = 10;
	}

	document.getElementById("gallery").style.top = posTop+"px";
	document.getElementById("gallery").style.left = posLeft+"px";
	document.getElementById("gallery").style.display = "";
	id = (id == 0) ? eval(galleryImages.length) - 1 : eval(id) - 1;
	document.getElementById('img01').src = galleryImages[id];
	document.getElementById('text').innerHTML = galleryText[id];
	document.getElementById('prevImage').href = "javascript:prev("+id+")";
	document.getElementById('nextImage').href = "javascript:next("+id+")";
}

//close Gallery
function closeDiv(id) {
	document.getElementById(id).style.display = "none";
}

//open gallery.php from child directory
function illustrationGallery(id) {
	window.open("../gallery.php?i="+id+"&t=i","designGallery","toolbar=no,top="+((screen.height/2)-282)+",left="+((screen.width/2)-350)+",width=700,height=584");
}

//open design_gallery.php
function design(id) {
/*
	if (window.innerHeight) {
		posTop = (window.innerHeight/2)-190;
	} else if (document.body.clientHeight) {
		posTop = (document.body.clientHeight/2)-370;
	} else {
		posTop = 10;
	}
	posTop = (posTop < 0) ? posTop = 10 : posTop = posTop;

	if (window.innerWidth) {
		posLeft = (window.innerWidth/2)-235;
	} else if (document.body.clientWidth) {
		posLeft = (document.body.clientWidth/2)-235;
	} else {
		posLeft = 10;
	}

	document.getElementById("gallery").style.top = posTop+"px";
	document.getElementById("gallery").style.left = posLeft+"px";
	document.getElementById("gallery").style.display = "";*/
	id = (id == 0) ? eval(galleryImages.length) - 1 : eval(id) - 1;
	document.getElementById('img01').src = galleryImages[id];
	//document.getElementById('text').innerHTML = galleryText[id];
	document.getElementById('prevImage').href = "javascript:prev("+id+")";
	document.getElementById('nextImage').href = "javascript:next("+id+")";
}

// show Century image
function showCentury(id) {
	document.getElementById('content_inner').innerHTML = "<img src=\"../century/"+id+"\" alt=\""+id+"\">";
}

// show Tshirt image
function showTshirts(id) {
	document.getElementById('content_inner').innerHTML = "<img src=\"../tshirts/"+id+"\" alt=\""+id+"\">";
}

//open LEO37 home page
function leo37_open() {
	window.open("home.php","winLeo37","toolbar=no,scrollbars=yes,top="+((screen.height/2)-280)+",left="+((screen.width/2)-233)+",width=466,height=560");
}

//open LEO37 lyrics page
function lyrics(filename,width,height) {
	window.open(filename,"winLyrics","toolbar=no,scrollbars=yes,top="+((screen.height/2)-(height/2))+",left="+((screen.width/2)-(width/2))+",width="+width+",height="+height);
}

//open admin editor
function edit(group,type,id,ed) {
	window.open("edit.php?g="+group+"&t="+type+"&id="+id+"&ed="+ed,"winEdit","status=yes,resizable=yes,scrollbars=yes,toolbar=no,top="+((screen.height/2)-188)+",left="+((screen.width/2)-230)+",width=480,height=375");
}
//open admin editor
function videocode() {
	window.open("video.php","winVideoCode","status=yes,resizable=yes,scrollbars=yes,toolbar=no,top="+((screen.height/2)-182)+",left="+((screen.width/2)-235)+",width=470,height=384");
}

//open admin Art Sort
function ppfSort(tbl) {
	window.open("sortArt.php?t="+tbl,"winPPFSort","scrollbars=yes,toolbar=no,top="+((screen.height/2)-188)+",left="+((screen.width/2)-210)+",width=420,height=375");
}

//open admin mailing list editor
function mailingEdit(id) {
	window.open("mailingedit.php?id="+id,"winMailingEdit","toolbar=no,scrollbars=yes,top="+((screen.height/2)-80)+",left="+((screen.width/2)-210)+",width=420,height=166");
}

//open j4j_video.php from this directory
function video() {
	window.open("j4j_video.php","j4jVideo","toolbar=no,top="+((screen.height/2)-88)+",left="+((screen.width/2)-120)+",width=240,height=176");
}

//open audio_clip.php from 'audio' directory
function audio_root(id,name) {
	window.open("audio/audio_clip.php?id="+id+"&name="+name,"ppfAudio","toolbar=no,status=no,top="+((screen.height/2)-46)+",left="+((screen.width/2)-150)+",width=300,height=92");
}

//open audio_clip.php from 'audio' directory
function audio(id,name) {
	window.open("../audio/audio_clip.php?id="+id+"&name="+name,"ppfAudio","toolbar=no,status=no,top="+((screen.height/2)-46)+",left="+((screen.width/2)-150)+",width=300,height=92");
}

//open details.php
function openDetails() {
	window.open("details.php","mailingDetails","toolbar=no,top="+((screen.height/2)-80)+",left="+((screen.width/2)-180)+",width=360,height=160");
}

//open wpbe/index.php
function wpbe() {
	window.open("../wpbe/index.php","wpbe","toolbar=no,resizable=yes,scrollbars=yes,top=25,left="+((screen.width/2)-233)+",width=466,height=701");
}

//open flutter/index.php
function flutter() {
	window.open("../flutter/home.php","flutter","toolbar=no,resizable=yes,scrollbars=no,top="+((screen.height/2)-270)+",left="+((screen.width/2)-425)+",width=850,height=540");
}

//open flutter/index.php
function flutter2008() {
	window.open("http://www.ppfhouse.com/flutter/home.php","flutter","toolbar=no,resizable=yes,scrollbars=no,top="+((screen.height/2)-270)+",left="+((screen.width/2)-425)+",width=850,height=540");
}

function openImg(img,w,h) {
	ww = w+4;
	wh = h+4;
	window.open("img.php?img="+img+"&w="+w+"&h="+h,"","toolbar=no,top="+((screen.height/2)-(wh/2))+",left="+((screen.width/2)-(ww/2))+",width="+ww+",height="+wh);
}

//add new rows to Add Names to the mailing list
function addmore() {
	var tbl = document.getElementById("addnames")
	nextRow = tbl.rows.length-2;
	var oRow = tbl.insertRow(nextRow);
	var oCell = oRow.insertCell(0);
	var el = document.createElement("input");
	el.setAttribute("type", "text");
	el.setAttribute("name", "name_"+nextRow);
	el.setAttribute("size", "26");
	oCell.appendChild(el);
	var oCell = oRow.insertCell(1);
	var el = document.createElement("input");
	el.setAttribute("type", "text");
	el.setAttribute("name", "email_"+nextRow); 
	el.setAttribute("size", "29");
	oCell.appendChild(el);
	document.getElementById("hdname").innerHTML = "names";
	document.forms['mailingEdit'].add.value=eval(document.forms['mailingEdit'].add.value)+1;
}

//open Store page
function store() {
	var isNav4, isIE4, top, left;
	if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
		isNav4 = (navigator.appName == "Netscape") ? 1 : 0;
		isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
	}

	if (screen.availHeight > 892) {
		if (isNav4) {
			width = 554;
			height = 892;
			height_2 = 892;
		} else {
			width = 570;
			height = 892;
			height_2 = 892;
		}
	} else {
		width = 570;
		height = screen.availHeight-26;
		height_2 = screen.availHeight;
	}

	window.open("store.php","winStore","toolbar=no,scrollbars=yes,top="+((screen.availHeight/2)-(height_2/2))+",left="+((screen.width/2)-(width/2))+",width="+width+",height="+height);
}

//open Store page from child directory
function store_2() {
	var isNav4, isIE4, top, left;
	if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
		isNav4 = (navigator.appName == "Netscape") ? 1 : 0;
		isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
	}

	if (screen.availHeight > 892) {
		if (isNav4) {
			width = 554;
			height = 892;
			height_2 = 892;
		} else {
			width = 570;
			height = 892;
			height_2 = 892;
		}
	} else {
		width = 570;
		height = screen.availHeight-26;
		height_2 = screen.availHeight;
	}

	window.open("../store.php","winStore","toolbar=no,scrollbars=yes,top="+((screen.availHeight/2)-(height_2/2))+",left="+((screen.width/2)-(width/2))+",width="+width+",height="+height);
}

//submit Store item
function fctSubmit(id) {
	window.open("","paypal","toolbar=no,scrollbars=yes,resizable=yes,top="+((screen.availHeight/2)-300)+",left="+((screen.width/2)-400)+",width=800,height=600");
	document.forms[id].submit();
}

//validate email address
//function from http://www.webreference.com/js/tips/990928.html
//Is That Really an Email Address?
//Yehuda Shiran, Ph.D.
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

//form validation for mandatory fields
function mandatory() { //params must be form, element, message text, field type (text or email)
	var msg = '';
	frm = mandatory.arguments[0];
	for (i = 1; i < mandatory.arguments.length; i = i + 3) {
		elem = mandatory.arguments[i];
		text = mandatory.arguments[i+1];
		fldType = mandatory.arguments[i+2];
		if (frm.elements[elem].value == '') {
			msg += text + ' is not complete\n';
		} else if (fldType == 'email') {
			if (!isEmail(frm.elements[elem].value)) {
				msg += text + ' is not a valid email address\n';
			}
		}
	}
	if (msg != '') {
		alert('The following errors occurred:\n' + msg);
		return false
	} else {
		return true
	}
}

//form validation for mandatory fields WITH NO ERROR MESSAGE
function mandatory_nomsg() { //params must be form, element, message text, field type (text or email)
	var msg = '';
	frm = mandatory_nomsg.arguments[0];
	for (i = 1; i < mandatory_nomsg.arguments.length; i = i + 3) {
		elem = mandatory_nomsg.arguments[i];
		text = mandatory_nomsg.arguments[i+1];
		fldType = mandatory_nomsg.arguments[i+2];
		if (frm.elements[elem].value == '') {
			msg += text + ' is not complete\n';
		} else if (fldType == 'email') {
			if (!isEmail(frm.elements[elem].value)) {
				msg += text + ' is not a valid email address\n';
			}
		}
	}
	if (msg != '') {
		//alert('The following errors occurred:\n' + msg);
		return false
	} else {
		return true
	}
}

// add OnLoad event
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
	} else { 
		window.onload = function() { 
			if (oldonload) { 
				oldonload(); 
			} 
			func(); 
		} 
	} 
}