﻿function toggleFeedback()
{
	var feedbackcontainer = $("#FeedbackContainer");
	var animating = feedbackcontainer.attr("animating");
	if (!animating || animating == "in")
	{
		feedbackcontainer.stop().attr("animating", "out").animate({ "marginLeft": "-1px" }, 500);
	}
	else
	{
		feedbackcontainer.stop().attr("animating", "in").animate({ "marginLeft": "-202px" }, 500);
	}
}

function checkForSearch(event)
{
	if (event.keyCode == '13' || event.which === 13)
	{
		SearchMethod();
	}
}

function SearchMethod()
{
	var searchInput = document.getElementById("SearchText");

	location.href = "/Search.aspx?search=" + escape(searchInput.value);
	return false;
}

function toggleCollapse(divId) {
	if (document.getElementById(divId).style.display == 'none') {
		document.getElementById(divId).style.display = 'block';
	}
	else {
		document.getElementById(divId).style.display = 'none';
	}
}


function isIE() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		return true;
	} else {
		return false;
	}
}
function isIE6() {
	if (isIE()) {
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
			var version = new Number(RegExp.$1) // capture x.x portion and store as a number
			if (version < 7) {
				return true;
			} else {
				return false;
			}
		} else { return false; }
	} else {
		return false;
	}
}


function photoSubmitClear(idname, strtoclear) {
	if (document.getElementById(idname)) {
		if (document.getElementById(idname).value == strtoclear) {
			document.getElementById(idname).value = "";
		}
	}
}
function photoSubmitSetDefault(idname, defaultstr) {
	if (document.getElementById(idname)) {
		if (document.getElementById(idname).value == "") {
			document.getElementById(idname).value = defaultstr;
		}
	}
}
function photoSubmitShowUploaded(imgname) {
	var div = createTag("div");
	div.setAttribute("id", "uploaded-photo-" + imgname);
	div.setAttribute("style", "display: none");
	setClass(div, "uploaded-photo");

	var img = createTag("img");
	img.setAttribute("src", "/temp-gallery/" + imgname + ".jpg");
	img.setAttribute("width", 75);
	img.render;

	imagediv = createTag("div");
	setClass(imagediv, "uploaded-photo-image");
	imagediv.appendChild(img);
	div.appendChild(imagediv);

	infodiv = createTag("div");
	setClass(infodiv, "uploaded-photo-info");


	var tbx = createInput("textbox");
	tbx.setAttribute("name", "title-" + imgname);
	tbx.setAttribute("id", "title-" + imgname);
	tbx.setAttribute("value", "Title");
	if (!isIE()) {
		tbx.addEventListener("focus", function () { photoSubmitClear('title-' + imgname, 'Title'); }, true);
		tbx.addEventListener("blur", function () { photoSubmitSetDefault('title-' + imgname, 'Title'); }, true);
	} else {
		tbx.attachEvent("onfocus", function () { photoSubmitClear('title-' + imgname, 'Title'); });
		tbx.attachEvent("onblur", function () { photoSubmitSetDefault('title-' + imgname, 'Title'); });
	}
	infodiv.appendChild(tbx);
	var br = createTag("br");
	infodiv.appendChild(br);


	var slt = createTag("select");
	slt.setAttribute("id", "region-" + imgname);
	slt.setAttribute("name", "region-" + imgname);
	if (!isIE()) {
		slt.addEventListener("change", function () { photoSubmitGetCities(imgname); }, true);
	} else {
		slt.attachEvent("onchange", function () { photoSubmitGetCities(imgname); });
	}
	for (var i = 0; i < regions.length; i++) {
		var opt = createTag("option");
		opt.setAttribute("value", regions[i][0]);
		opt.innerHTML = regions[i][1];
		slt.appendChild(opt);
	}
	infodiv.appendChild(slt);

	var br = createTag("br");
	infodiv.appendChild(br);

	var slt = createTag("select");
	slt.setAttribute("id", "city-" + imgname);
	slt.setAttribute("name", "city-" + imgname);
	var opt = createTag("option");
	opt.setAttribute("value", "0");
	opt.innerHTML = "--Select City--";
	slt.appendChild(opt);
	infodiv.appendChild(slt);

	br = createTag("br");
	infodiv.appendChild(br);

	var txa = createTag("textarea");
	txa.setAttribute("name", "description-" + imgname);
	txa.setAttribute("id", "description-" + imgname);
	txa.innerHTML = "Description";
	if (!isIE()) {
		txa.addEventListener("focus", function () { photoSubmitClear('description-' + imgname, 'Description'); }, true);
		txa.addEventListener("blur", function () { setdefault('description-' + imgname, 'Description'); }, true);
	} else {
		txa.attachEvent("onfocus", function () { photoSubmitClear('description-' + imgname, 'Description'); });
		txa.attachEvent("onblur", function () { setdefault('description-' + imgname, 'Description'); });
	}
	infodiv.appendChild(txa);
	var br = createTag("br");
	infodiv.appendChild(br);

	div.appendChild(infodiv);

	infodiv = createTag("div");
	setClass(infodiv, "uploaded-photo-remove");

	var anc = createTag("a");
	anc.setAttribute("href", "javascript:void(0)");
	if (!isIE()) {
		anc.addEventListener("click", function () { removeImage(imgname); }, true);
	} else {
		anc.attachEvent("onclick", function () { removeImage(imgname); });
	}

	var img = createTag("img");
	img.setAttribute("src", "/images/gallery/remove-photo-gray.jpg");
	img.render;

	anc.appendChild(img);
	infodiv.appendChild(anc);
	div.appendChild(infodiv);

	var clrdiv = createTag("div");
	setClass(clrdiv, "clear");

	div.appendChild(clrdiv);

	document.getElementById('uploaded-photos').appendChild(div);
	document.getElementById("uploaded-photo-" + imgname).style.display = "block";
}
function photoSubmitGetCities(imgname) {
	for (var i = 0; i < regions.length; i++) {
		if (document.getElementById('region-' + imgname).value == regions[i][0]) {
			document.getElementById('city-' + imgname).options.length = 0;
			if (regions[i][2].length > 0) {
				for (var j = 0; j < regions[i][2].length; j++) {
					var opt = createTag("option");
					opt.setAttribute("value", regions[i][2][j][0]);
					opt.innerHTML = regions[i][2][j][1];
					document.getElementById('city-' + imgname).appendChild(opt);
				}
				document.getElementById('city-' + imgname).style.display = "block";
			} else {
				document.getElementById('city-' + imgname).style.display = "none";
			}
			break;
		}
	}
}

function createTag(tagtype) {
	if (isIE()) {
		return document.createElement('<' + tagtype + ' />');
	} else {
		var elem = document.createElement(tagtype);
		return elem;
	}
}
function createInput(inputtype) {
	if (isIE()) {
		return document.createElement('<input type="' + inputtype + '" />');
	} else {
		var elem = document.createElement("input");
		elem.setAttribute("type", inputtype);
		return elem;
	}
}
function setClass(elem, myclass) {
	if (isIE()) {
		elem.className = myclass;
	} else {
		elem.setAttribute("class", myclass);
	}
}

function systemIE6PopUpOpened(v) {
}

function systemIE6PopUpClosed(v) {
}
