/* JavaScript Document */
/* Global Functions */
var has_submitted_order=false;
var rules = new Array;
rules['customer.email'] = /(\w+)\@(\w+)\.(\w+)/;
rules['customer.zip'] = /\d{5,5}/;

function submit_order() {
	if (!checkform()) return false;
    if(!has_submitted_order) {
		toggle('edit'); 
		toggleOff('editText');
        has_submitted_order=true;
        document.forms[0].submit();    
    } 
	return false;
} 
function btn () {
	document.getElementById('textEdit').style.display = "none"
}
function popup(url,name) {
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no,height=400,width=730,scrollbars=yes";
	var popupbox = window.open(url, name, opts);
	popupbox.focus();
}
function formFocus() {
	for(i=0; i<document.forms[0].elements.length; i++) {
		if(document.forms[0].elements[i].value == null || document.forms[0].elements[i].value == "") {
			document.forms[0].elements[i].focus();
			break;
		}
	}
}
/* End of Global Functions */

/* PopUps */

function popUpSmall(url,name) {
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=yes,height=400,width=620,scrollbars=yes";
	var popupbox = window.open(url, name, opts);
	popupbox.focus();
}

function popUpLarge(url,name) {
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=yes,height=550,width=800,scrollbars=yes";
	var popupbox = window.open(url, name, opts);
	popupbox.focus();
}

function popUpVerSign(url,name) {
	var opts = "toolbar=no,status=no,location=no,menubar=no,resizable=no,height=442,width=515,scrollbars=no";
	var popupbox = window.open(url, name, opts);
	popupbox.focus();
}
/* End of PopUps */

/* Toggle Code */
function toggle (it) {
	if (!document.getElementById(it)) return false;
	if (document.getElementById(it).style.display == "block") { 
		document.getElementById(it).style.display = "none"; 
	} else { 
		document.getElementById(it).style.display = "block"; 
	}
}

function toggleOff (it) {
	if (!document.getElementById(it)) return false;
	if (document.getElementById(it).style.display == "none") { 
		document.getElementById(it).style.display = "block"; 
	} else { 
		document.getElementById(it).style.display = "none"; 
	}
}

/* End of Toggle Code */
/* ExitPop */

function popMain(event,sid)
{
	x = event.clientX;
	y = event.clientY;
	if(y <= 0 && x >=0)
	{
		window.open('exitPop.html?sid=' + sid,
					'exitPop',
					'toolbar=no,status=no,location=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,directories=no,width=425,height=600,top=0,left=0'
					);
		window.focus();
	}
}

var sid = '';
	
function popExit() 
{
	var query = window.location.href;
	var index = query.indexOf("sid=");

	if(index != -1)
	{
		var startIndex = index + 4;
		var endIndex = query.indexOf('&', startIndex);
		if(endIndex = -1)
		{
			sid = query.substring(startIndex);
		}
		else
		{
			sid = query.substring(startIndex, endIndex);
		}
	}
}

function popClose()
{
	window.open(
				'https://www.dermitage.com/index.html?p=8a8488cd1139add0011139adf48d0004&r=8aa081ca14828a8b011485b470ff1859&SID=' + sid,
				'exitPopCreative',
				'toolbar=yes,status=yes,location=yes,menubar=yes,resizable=yes,copyhistory=yes,scrollbars=yes,directories=yes'
				);
	window.focus();
	self.close();
	return false;
}


function checkform () {
	var a = document.forms[0];
	if (!a) return false;
	var flag = 0;
	for (var i=0;i<a.elements.length;i++) {
		if (!a.elements[i].value||(a.elements[i].value&&rules[a.elements[i].name]&&!a.elements[i].value.match(rules[a.elements[i].name]))) {
			var b = a.elements[i].nextSibling;
			while (b&&!b.tagName&&b.nextSibling) {b = b.nextSibling}
			if (b.className == 'error') { 
				b.style.display = "block";
				flag++;
				var c = b.nextSibling;
				while (c&&!c.tagName&&c.nextSibling) {c = c.nextSibling}
				if (c&&c.className&&c.className.match(/errormessage/i)) c.style.display = 'none'
			}
		} else {
			var b = a.elements[i].nextSibling;
			while (b&&!b.tagName&&b.nextSibling) {b = b.nextSibling}
			if (b.className == 'error') { 
				b.style.display = "none";
			}
		}
	}
	if (flag) return false;
	return true;
}

