function trim ( s ) {
	s = s.replace( /^\s*/, "" );
	s = s.replace( /\s*$/, "" );
	return s;
}

function openimages() {
	//leftPosition = (screen.width) ? (screen.width - 300) / 2:100;
	//topPosition = (screen.height) ? (screen.height - 285) / 2:100;

	leftPosition = (window.screenLeft) ? (window.screenLeft + 100) / 2:100;
	topPosition = (window.screenTop) ? (window.screenTop + 100) / 2:100;

	msg = open("","imgWindow","dependent=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=690,height=650,top=" + topPosition + ",left=" + leftPosition);

	msg.location = 'images.php';
	msg.focus();
}

function openhelp() {
	leftPosition = (window.screenLeft) ? (window.screenLeft + 100) / 2:100;
	topPosition = (window.screenTop) ? (window.screenTop + 100) / 2:100;

	msg = open("","hlpWindow","dependent=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=690,height=650,top=" + topPosition + ",left=" + leftPosition);

	msg.location = 'instructions/instructions.html';
	msg.focus();
}

function cartviewPreview(orderdetailID) {

	leftPosition = (window.screenLeft) ? (window.screenLeft + 100) / 2:100;
	topPosition = (window.screenTop) ? (window.screenTop + 100) / 2:100;

	msg = open("","viewPreviewWindow","dependent=yes,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=660,height=620,top=" + topPosition + ",left=" + leftPosition);

	msg.location = 'viewpreview.php?OrderDetailID='+orderdetailID;
	msg.focus();
}

function getElement(element) {
	if (document.getElementById) {
		return document.getElementById(element);
	}	
	else if (document.all) {
		return document.all(element);
	}
	else if (document.layers){
		return document.layers[element];
	}
	else {
		return null;
	}
}

function changeCountry(akey, aval, theform, prefix) {
	var elname = "document." + theform.name + "." + prefix + "state";
	var selobj = eval(elname);

	for(j=selobj.length; j >= 0; j--) {
		selobj.options[j] = null;
	}

	selobj.options.length = 0;
	for(i=0; i < akey.length; i++) {
		selobj.options[i] = new Option( aval[i], akey[i] );
	}

}

function confirmDeleteAccountDesign(ctemplateid, thename) {
	rs = confirm('Are you sure you want to delete ' + thename + '?');
	if(rs) {
		document.location.href = 'accountdesigns.php?del=' + ctemplateid;
	}
}

function showEditor(sid, tempurl) {
	document.write('<object border="1" bordercolor="#000000" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="650" height="500" id="editor" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="editor.swf?sid=' + sid + '&' + tempurl + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#DCDDE1" />');
	document.write('<embed border="1" bordercolor="#000000" src="editor.swf?sid=' + sid + '&' + tempurl + '" quality="high" bgcolor="#DCDDE1" width="650" height="500" name="editor" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object><br><br>');
}

function showGallery() {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="102" id="gallery" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="gallery.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="gallery.swf" quality="high" bgcolor="#ffffff" width="600" height="102" name="gallery" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function hidetip() {
	objTip = getElement('tooltip');
	if(objTip != null) {
		//objTip.style.display = "none";
		objTip.style.visibility = "hidden";
	}
}

function showtip(tip) {
	objTip = getElement('tooltip');
	if(objTip != null) {
		//objTip.style.display = "";
		objTip.style.visibility = "visible";

		shtml = '<table width="652" height="55" cellpadding="0" cellspacing="2" border="0" style="border: 1px solid black;"><tr><td>';
		ehtml = '</td></tr></table>';
		objTip.innerHTML = '';

		if(tip == 'SelectTool') {
			//objTip.innerHTML = shtml + '<b>Pointer Tool:</b> Use this to select and move items around on the screen. One left click of the mouse selects the item. Selected items will have small black boxes in all four corners. Holding down the left mouse button will allow you to drag the item to a desired location. Use the pointer to select an image or polygon, then click and hold on one of the four corners of the image to increase or decrease its size.' + ehtml;
		} else if(tip == 'TextTool') {
			//objTip.innerHTML = shtml + '<b>Text Tool:</b> Use this to select and to change text properties. You are unable to move text with this tool, you must use pointer tool to move a text box. When a text box is selected, more options will appear in the top menu to change font, font size, font color, font style (bold, italicize, and underline) drop shadow and shadow color.' + ehtml;
		} else if(tip == 'RectangleTool') {
			//objTip.innerHTML = shtml + '<b>Box Tool:</b> This tool allows you to create a modifiable box on your card. Click tool, and then click on your card design to insert a box. When the box is selected a new menu will open at the top of the screen which will allows you to change the properties of the box. You can change the color, add a border with color option, and control the box transparency.' + ehtml;
		} else if(tip == 'LineTool') {
			//objTip.innerHTML = shtml + '<b>Line Tool:</b> This tool allows you to create a modifiable line on your card. No line will appear until you create one. Place your mouse pointer in a preferred location, click and drag until a desired length and direction is achieved then release your mouse button. Holding down the shift key while dragging will produce a perfect horizontal or vertical line. When the line is selected a menu at the top of the screen allows you to change the properties of the line. You can change the transparency, adjust the thickness of the line, and change the color of the line.' + ehtml;
		} else if(tip == 'RotateTool') {
			//objTip.innerHTML = shtml + '<b>Rotation Tool:</b> Clicking on this will allow you to rotate your text or image. By clicking on the image or text with the pointer tool it opens up a menu at the top of the screen, you can either type in the degree of choice and push enter or use the arrows up and down arrows to select the desired degree.' + ehtml;
		} else if(tip == 'AlignLeft') {
			//objTip.innerHTML = shtml + '<b>Rotation Tool:</b> Clicking on this will allow you to rotate your text or image. By clicking on the image or text with the pointer tool it opens up a menu at the top of the screen, you can either type in the degree of choice and push enter or use the arrows up and down arrows to select the desired degree.' + ehtml;
		} else if(tip == 'AlignCenter') {
			//objTip.innerHTML = shtml + '<b>Rotation Tool:</b> Clicking on this will allow you to rotate your text or image. By clicking on the image or text with the pointer tool it opens up a menu at the top of the screen, you can either type in the degree of choice and push enter or use the arrows up and down arrows to select the desired degree.' + ehtml;
		} else if(tip == 'AlignRight') {
			//objTip.innerHTML = shtml + '<b>Rotation Tool:</b> Clicking on this will allow you to rotate your text or image. By clicking on the image or text with the pointer tool it opens up a menu at the top of the screen, you can either type in the degree of choice and push enter or use the arrows up and down arrows to select the desired degree.' + ehtml;
		}

	}
}

function changePaymentType(el) {
	oPONum = getElement('divponum');
	oCCInfo = getElement('divccinfo');

	if(oPONum != null && oCCInfo != null) {
		if(el.value == 'Credit Card') {
			oPONum.style.display = "none";
			oCCInfo.style.display = "";
		} else if(el.value == 'Purchase Order') {
			oPONum.style.display = "";
			oCCInfo.style.display = "none";
		}
	}

}

function hideVehicleSelect() {
	oVehSelect = getElement('divVehicleSelect');
	if(oVehSelect != null) {
		oVehSelect.style.display = "none";
	}
}

function showVehicleSelect() {
	oVehSelect = getElement('divVehicleSelect');
	if(oVehSelect != null) {
		oVehSelect.style.display = "";
	}
}

function validateAutoDealerForm(tf) {
	qty = trim(tf.Qty.value);

	if(qty == "") {
		alert("Please enter Quantity");
		tf.Qty.focus();
		return false;
	}

	stdCard = tf.ProductID[0].checked;
	adCard = tf.ProductID[1].checked;

	if(stdCard) {
		tf.submit();
		return true;
	}

	var totalVehicles = 0;
	for(i = 0; i < tf.elements.length; i++) {
		if( tf.elements[i].name.substring(0, 10) == 'aMakeModel' ) {
			val = trim(tf.elements[i].value);
			if( val != "" ) {
				totalVehicles += parseInt(val);
			}
		}
	}

	if( qty * 4 != totalVehicles ) {
		alert("Total number of Quantities for vehicles must total " + (qty * 4) );
		return false;	
	}
	
	tf.submit();
	return true;	
}