

/* ------------------- MAIN JAVASCRIPT ------------------------------- */

var section;
var popup;

browsver = navigator.appVersion.toLowerCase();
browsvernum = parseInt(navigator.appVersion);
browsname = navigator.appName;
browsagt = navigator.userAgent.toLowerCase();


function view_img(id,type) {
	url = "http://www.mohonkimages.com/cgi-bin/shop/view_img.cgi?id=" + id;
	if (type == "land") {
		var winw = 500;
		var winh = 339;
	}
	if (type == "port") {
		var winw = 339;
		var winh = 500;
	}
	if (type == "mland") {
		var winw = 500;
		var winh = 379;
	}
	if (type == "mport") {
		var winw = 379;
		var winh = 500;
	}
	if (type == "pland") {
		var winw = 500;
		var winh = 190;
	}
	if (type == "pport") {
		var winw = 190;
		var winh = 500;
	}

	imgwin = open(url, "remote", "width="+winw+",height="+winh+",scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no");
}

function viewsearchtips() {
	tipsdiv = document.getElementById('searchtips');
	tipslink = document.getElementById('searchtipslink');
	if (tipsdiv.style.display == "block") {
		tipsdiv.style.display = "none";
		tipslink.innerHTML = "tips";
	}
	else {
		tipsdiv.style.display = "block";
		tipslink.innerHTML = "hide tips";
	}
}

function addtocart() {
	frame_menu = document.getElementById('frame');
	if (frame_menu && (frame_menu.disabled == false && frame_menu.value == "")) {
		alert("Please choose a frame for your selected print.");
		return;
	}

	print_menu = document.getElementById('printoptions');
	//print_menu_s = document.getElementById('printoptions_standard');
	//print_menu_p = document.getElementById('printoptions_panoramic');
	if (
		(print_menu && (print_menu.disabled == false && print_menu.value == "")) /*||
		(print_menu_s && (print_menu_s.disabled == false && print_menu_s.value == "")) ||
		(print_menu_p && (print_menu_p.disabled == false && print_menu_p.value == ""))*/
		) {
		alert("Please choose a size for your print.");
		return;
	}
	document.shop.submit();
}

function chooseprint(el) {
	var thisel = document.getElementById(el);
	if (thisel) {
		var selindex = thisel.selectedIndex;
		var seloption = thisel.options[selindex];

		/*if (seloption.disabled == true) {
			return false;
		}*/

		var selvalue = thisel.options[selindex].value;
		if (selvalue.search(/frame/i) == -1) {
			document.getElementById("frame").disabled = true;
			chooseframe(null,0);
		}
		else {
			document.getElementById("frame").disabled = false;
			chooseframe("frame");
		}
	}
}

function chooseframe(el,type) {
	var frametype = type;
	var framestyle;
	var framebg;
	var thisframe = document.getElementById("imgframe");
	var thisel = document.getElementById(el);

	if (!thisel && frametype == null) {
		return;
	}

	if (thisel) {
		var selindex = thisel.selectedIndex;
		var selvalue = thisel.options[selindex].value;
		if (selvalue == 0) {
			frametype = 0;
		}
		else if (selvalue.search(/silver/i) != -1) {
			frametype = 1;
		}
		else if (selvalue.search(/gold/i) != -1) {
			frametype = 2;
		}
		else if (selvalue.search(/mahogany/i) != -1) {
			frametype = 3;
		}
		else if (selvalue.search(/black/i) != -1) {
			frametype = 4;
		}
		else if (selvalue.search(/brown/i) != -1) {
			frametype = 5;
		}
		else {
			frametype = 0;
		}
	}

	if (thisframe) {
		if (thisframe.className.indexOf("galimg_md_blank") >= 0) {
			//bg_lightgray.jpg
			return;
		}
		else if (thisframe.className.indexOf("galimg_md_none") >= 0) {
			//bg_img_md_missing.jpg
			return;
		}
		else if (thisframe.className.indexOf("galimg_md_land") >= 0) {
			framestyle = "land";
		}
		else if (thisframe.className.indexOf("galimg_md_port") >= 0) {
			framestyle = "port";
		}
		else if (thisframe.className.indexOf("galimg_md_mland") >= 0) {
			framestyle = "mland";
		}
		else if (thisframe.className.indexOf("galimg_md_mport") >= 0) {
			framestyle = "mport";
		}
		else if (thisframe.className.indexOf("galimg_md_pland") >= 0) {
			framestyle = "pland";
		}
		else if (thisframe.className.indexOf("galimg_md_pport") >= 0) {
			framestyle = "pport";
		}

		if (frametype == 0) {
			thisframe.style.background = "url(http://www.mohonkimages.com/images/portfolio/bg_img_md_"+framestyle+".jpg)";
		}
		else {
			thisframe.style.background = "url(http://www.mohonkimages.com/images/portfolio/frame"+frametype+"_img_md_"+framestyle+".jpg)";
			//thisframe.style.backgroundRepeat = "no-repeat";
			//thisframe.style.backgroundPosition = "left top";
		}
		/*if (thisframe.currentStyle) { // IE, Opera
			thisframebg = thisframe.currentStyle.background;
		}
		else { // Firefox, Safari
			thisframebg = getComputedStyle(thisframe,null).getPropertyValue('background');
		}*/
	}
}


/*function selectStates() {
	var state = "[req_state]";
	var shipping_state = "[shipping_state]";
	for (var i=0;i<document.main.req_state.length;i++) {
		if (document.main.req_state.options[i].value == state) {
			document.main.req_state.options[i].selected = true;
		}
	}

	for (var i=0;i<document.main.shipping_state.length;i++) {
		if (document.main.shipping_state.options[i].value == shipping_state) {
			document.main.shipping_state.options[i].selected = true;
		}
	}

	var country = "[req_country]";
	var shipping_country = "[shipping_country]";
	if (document.main.req_country) {
		for (var i=0;i<document.main.req_country.length;i++) {
			if (document.main.req_country.options[i].value == country) {
				document.main.req_country.options[i].selected = true;
			}
		}

		for (var i=0;i<document.main.shipping_country.length;i++) {
			if (document.main.shipping_country.options[i].value == shipping_country) {
				document.main.shipping_country.options[i].selected = true;
			}
		}
	}
}*/



function quickorder_vars() {
	el_print_gal = document.getElementById('print_gal');
	el_print_id = document.getElementById('print_id');
	el_print_title = document.getElementById('print_title');
	el_print_link = document.getElementById('print_link');
	el_print_imgframe = document.getElementById('imgframe');
	el_print_img = document.getElementById('print_img');
	el_print_qty = document.getElementById('print_qty');
	el_printoptions_default = document.getElementById('printoptions_default');
	el_printoptions_panoramic = document.getElementById('printoptions_panoramic');
	el_printoptions_standard = document.getElementById('printoptions_standard');
	el_print_frame = document.getElementById('frame');
	el_print_result = document.getElementById('print_result');
	el_add_print = document.getElementById('add_print');
	el_add_cal = document.getElementById('add_calendar');
	//el_add_book = document.getElementById('add_book');
	//el_add_ss = document.getElementById('add_screensaver');
	el_add_note = document.getElementById('add_notecards');
	el_submit_msg = document.getElementById('submit_message');
}


function quickorder_cart(form) {
	var thisform = document.getElementById(form);
	//submit_msg = document.getElementById('submit_message');
	el_submit_msg.innerHTML = "";

	document.getElementById('allitems').value = "";
	var thisitems = "";

	if (el_add_cal.checked) {
		thisitems += el_add_cal.value;
	}

	/*if (el_add_book.checked == true) {
		thisitems += el_add_book.value;
	}*/

	/*if (el_add_ss.checked == true) {
		thisitems += el_add_ss.value;
	}*/

	/*if (el_add_note.checked == true) {
		thisitems += el_add_note.value;
	}*/

	if (el_add_print.checked == true) {
		thisprint = "";

		thisprint += el_print_id.value + ":";
		thisprint += el_print_qty.value + ":";

		if (el_printoptions_panoramic.disabled == false) {
			if (el_printoptions_panoramic.value != "") {
				thisprint += el_printoptions_panoramic.value + ":";
			}
			else {
				el_submit_msg.innerHTML = "Please choose a size for your print.";
				return;
			}
		}
		else if (el_printoptions_standard.disabled == false) {
			if (el_printoptions_standard.value != "") {
				thisprint += el_printoptions_standard.value + ":";
			}
			else {
				el_submit_msg.innerHTML = "Please choose a size for your print.";
				return;
			}
		}
		else {
			return;
		}

		if (el_print_frame.disabled == false) {
			thisprint += el_print_frame.value;
		}

		thisprint += "||";

		thisitems += thisprint;
	}

	if (thisitems != "") {
		document.getElementById('allitems').value = thisitems;
		thisform.action = "http://www.mohonkimages.com/cgi-bin/shop/quickorder_cart.cgi";
		thisform.submit();
		return true;
	}
	else {
		el_submit_msg.innerHTML = "Please click the checkboxes next to the above items that you'd like to add to your cart.";
	}
}


function quickorder_reset(form) {
	document.getElementById(form).reset();
	if (form == "quickorder_print_form") {
		el_printoptions_default.disabled = true;
		el_printoptions_default.style.display = "";
		el_printoptions_panoramic.disabled = true;
		el_printoptions_panoramic.style.display = "none";
		//el_printoptions_panoramic.selectedIndex = 0;
		el_printoptions_standard.disabled = true;
		el_printoptions_standard.style.display = "none";
		//el_printoptions_standard.selectedIndex = 0;
		el_print_frame.disabled = true;
		el_add_print.disabled = true;
		el_add_print.checked = false;
		el_print_imgframe.style.backgroundImage = "";
		el_submit_msg.innerHTML = "";
	}
}


function createRequest() {
	var request = null;
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return request;
	if (request == null) {
		alert("Browser does not support HTTP Request.");
	}
}

function quickorder_print(thisprint) {
	thisprint = document.searchform.keyword.value;
	qo_print = "http://www.mohonkimages.com/lib/quickorder_print.php?print=" + escape(thisprint);

	request = createRequest();
	request.open("GET", qo_print, true);
	request.setRequestHeader('Content-Type', 'text/xml');
	request.onreadystatechange = getprint;
	request.send(null);
}

function getprint() {
	var str_imgstyle = "galimg_md galimg_md_";

	if (request.readyState == 4) {
		var response = request.responseXML.documentElement;

		var thistag = response.getElementsByTagName("galnum")[0];
		var print_gal = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("id")[0];
		var print_id = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("title")[0];
		var print_title = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("src")[0];
		var print_imgsrc = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("style")[0];
		var print_imgstyle = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("type")[0];
		var print_type = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("stock")[0];
		var print_stock = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = response.getElementsByTagName("result")[0];
		var print_result = (thistag.hasChildNodes() ? thistag.childNodes[0].nodeValue : "");

		thistag = "";

		quickorder_reset('quickorder_print_form');

		if (print_gal == "") {
			print_gal = "<i>n/a</i>";
		}
		if (print_id != "" || print_stock == "yes") {
			el_add_print.disabled = false;
			el_printoptions_default.style.display = "none";

			if (print_type == "Panoramic") {
				el_printoptions_panoramic.disabled = false;
				el_printoptions_panoramic.style.display = "";
			}
			else if (print_type == "Standard") {
				el_printoptions_standard.disabled = false;
				el_printoptions_standard.style.display = "";
			}
		}

		if (print_id != "") {
			var thisprintlink = "<a href=\"http://www.mohonkimages.com/cgi-bin/shop/detail.cgi?id=" + print_id /*+ "&ref=qo"*/ + "\"><i>View Larger Image</i></a>";

			if (print_gal != "") {
				thisprintlink += " &nbsp;&nbsp; | &nbsp;&nbsp; <a href=\"http://www.mohonkimages.com/webstore/compare/set.php?action=add&amp;id=" + print_gal + "&amp;v=1\"><i>Compare This Print</i></a>";
			}
		}
		else {
			var thisprintlink = "";
		}

		el_print_title.innerHTML = print_title;
		el_print_link.innerHTML = thisprintlink;
		el_print_gal.innerHTML = print_gal;
		el_print_result.innerHTML = print_result;
		el_print_img.src = print_imgsrc;
		el_print_img.className = str_imgstyle + print_imgstyle;
		el_print_imgframe.className = str_imgstyle + print_imgstyle;
		el_print_id.value = print_id;
	}
}



function add_javascript(file,tag) {
	var thistag = document.getElementsByTagName(tag)[0];
	var thisnew = document.createElement("script");
	thisnew.setAttribute("type","text/javascript");
	thisnew.setAttribute("src",file);
	thistag.appendChild(thisnew);
}
/* EXAMPLE
add_javascript("../lib/script.js","head");
*/


function add_onload(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}
/* EXAMPLES
add_onload(somefunctionname);

add_onload(function(){
	some code;
});
*/


/* ------------------- lightbox/slideshow script ------------------------------- */


//add_javascript("http://www.mohonkimages.com/lib/lightbox.php.js","head");
//add_javascript("../../lib/lightbox.php.js","head");




function open_compare_image(id,zoom) {
	compare_int_count++;
	var thisel = document.getElementById(id);
	if (thisel) {
		if (all_lightbox_sizes[thisel.href]) {
			if (compare_int) {
				clearInterval(compare_int);
			}
			open_lightbox(thisel,zoom);
		}
	}

	if (compare_int && compare_int_count > 15) {
		clearInterval(compare_int);
	}
	return false;
}


/* ------------------------------------------------------------- */

window.onload=function() {
	self.name = "mainwin";
	if (document.getElementById('searchform')) {
		if (document.searchform.keyword) {
			document.searchform.keyword.focus();
		}
	}

	if(section == "webstore") {
		chooseprint('printoptions');
	}
	else if(section == "webstorecheckout") {
		//selectStates();
	}
	else if(section == "webstorequickorder") {
		quickorder_vars();
		quickorder_reset('quickorder_items_form');
		quickorder_reset('searchform');
		quickorder_reset('quickorder_print_form');
		quickorder_reset('quickorder_form');
	}

	get_lightbox_sizes();
	set_lightbox_events();
}




