/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function isDocument(formElement, message) {
	var OK = new Array ('csv', 'doc', 'pdf', 'ppt', 'txt', 'xls');  // if you change this element, please change the config.php

	formElement.value = trim(formElement.value);
	if (formElement.value == '') {
		return true;
	}

	var ext = getExt(formElement.value);
	_isDocument = false;

	for (i=0; i<OK.length; i++) {
		if (OK[i] == ext) {
			_isDocument = true; // one of the file extensions found
		} 
	}

	if (!_isDocument) { 
		alert(message);
		formElement.focus();
	}

	return _isDocument;
}

function isImage(formElement, message) {
	var OK = new Array ('jpg', 'gif', 'jpeg', 'png', 'wbmp');  // if you change this element, please change the config.php

	formElement.value = trim(formElement.value);
	if (formElement.value == '') {
		return true;
	}

	var ext = getExt(formElement.value);

	_isImage = false;

	for (i=0; i<OK.length; i++) {
		if (OK[i] == ext) {
			_isImage = true; // one of the file extensions found
		} 
	}

	if (!_isImage) { 
		alert(message);
		formElement.focus();
	}

	return _isImage;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}

function isDecimalKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode

	if (charCode == 46) // Decimal Period
		return true;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}

function isQuantityKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode

	if (charCode == 43 || charCode == 45) // + or - key
		return true;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
}

function open_window(url) {
	var NEW_WIN = null;
	NEW_WIN = window.open ("", "RecordViewer", "toolbar=1,width=550,height=550,directories=0,status=0,scrollbars=1,resize=1,menubar=0");
	NEW_WIN.location.href = url;
}

function wopen(url, name, w, h) {
	// Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
	w += 32;
	h += 54;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
		name,
		'width=' + w + ', height=' + h + ', ' +
		'left=' + wleft + ', top=' + wtop + ', ' +
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=no, resizable=yes');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}

function goodState(fld) {
	var StateName = new Array("AK","AL","AR", "AS","AZ","CA","CO","CT","DC","DE","FL","FM","GA","GU","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MH","MI","MN","MO","MP","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","PR","PW","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY");

	for (i in StateName) {
		if(fld.toUpperCase() == StateName[i]) return true;
	}

	return false;
}

function viewAddressBook() {
	with (window.document.frmCheckout) {
		if (cboAddressBook.selectedIndex == 0) {
			window.location.href = 'checkout.php?step=1';
		} else {
			window.location.href = 'checkout.php?step=1&adId=' + cboAddressBook.options[cboAddressBook.selectedIndex].value;
		}
	}
}

function getAddressBook() {
	with (window.document.frmCheckout) {
		if (cboAddressBook.selectedIndex == 0) {
			window.location.href = 'myaccount.php?view=Book';
		} else {
			window.location.href = 'myaccount.php?view=Book&adId=' + cboAddressBook.options[cboAddressBook.selectedIndex].value;
		}
	}
}

function startUpload() {
	document.getElementById('f1_upload_process').style.visibility = 'visible';
	return true;
}

function stopUpload(success) {
	var result = '';

	if (success == 1){
		document.getElementById('f1_result').innerHTML = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
	} else {
		document.getElementById('f1_result').innerHTML = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
	}

	document.getElementById('f1_upload_process').style.visibility = 'hidden';
	return true;
}

var xmlHttp

function GetXmlHttpObject() {
	var xmlHttp=null;

	try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
			//Internet Explorer
			try {
					xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
	}

	return xmlHttp;
}

function gotoTechnologo(prod, img) {
	window.open("http://www.technologo.com/techno.OnDemand?&email=EODjeff@EODimagepointe.com&sku=0000&name=" + prod + "&imageCount=1&imagelocation_0=http://www.imagepointe.com" + img + "&whiteout=true&orientation=square&removelogo=true&eid=123456");
}

/*
Combo Box Image Selector:
*/

function showimage(formName) {
	if (!document.images)	return;
	if (formName.ipDesign.options[formName.ipDesign.selectedIndex].value == "") {
		formName.pictures.src = "/images/spacer.gif";
	} else {
		formName.pictures.src = formName.ipDesign.options[formName.ipDesign.selectedIndex].value
	}
}

<!--
var FiltersEnabled = 0; // if your not going to use transitions or filters in any of the tips set this to 0
Style[0]=["white","black","#666666","#ffffff","","","","","","","","","","",75,"",1,1,10,10,"","","","",""];
applyCssFilter();
//-->
