function validateEmail(emailAddress) {
   var match = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/.test(emailAddress);
   return match;
}

function isEmail(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1) {
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;					
	}


function CheckRegisterForm(RegisterForm)
{
        if (RegisterForm.username.value == "" ) { alert( "Please choose a User ID. Use characters and numbers" );
        RegisterForm.username.focus();
        return false; }
        
        if (RegisterForm.password.value == "" ) { alert( "Please choose a password. Use characters and numbers" );
        RegisterForm.password.focus();
        return false; }
        
        if (RegisterForm.email.value == "" ) { alert( "Please enter a valid email address." );
        RegisterForm.email.focus();
        return false; }

        checkEmail = RegisterForm.email.value

		if ((checkEmail.indexOf('@') < 0) && checkEmail.indexOf('.'))
		{
			alert("Please enter a valid email address.");
			RegisterForm.email.focus();
			return false; 
		}

    return true;
}


function CheckTellForm(tellform)
    {
        if (tellform.name.value == "" ) { alert( "This is an alert in CheckTellForm 1" );
        tellform.name.focus();
        return false; }

        if (tellform.email.value == "" ) { alert( "This is an alert in CheckTellForm 2" );
        tellform.email.focus();
        return false; }

        checkEmail = tellform.email.value
	if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
	{alert("This is an alert in CheckTellForm 3");
	tellform.email.focus();
	return false; }


        if (tellform.fname.value == "" ) { alert( "This is an alert in CheckTellForm 4" );
        tellform.fname.focus();
        return false; }



         if (tellform.femail.value == "" ) { alert( "This is an alert in CheckTellForm 5" );
        tellform.femail.focus();
        return false; }

        checkEmail = tellform.femail.value
	if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
	{alert("This is an alert");
	tellform.femail.focus();
	return false; }



   // return true;
}


var newwindow;
function pop(url)
{
        newwindow=window.open(url,'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=1, menubars=0, resizable=1, width=960, height=700');
        if (window.focus) {newwindow.focus()}
}

     function popimg(url)
    {
        newwindow=window.open(url,'name','height=500,width=650,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
	if (window.focus) {newwindow.focus()}
    }



<!-- ; 
var newwindow; 
var wheight = 0, wwidth = 0; 
function viewimg(url, title, iwidth, iheight, colour) { 
var pwidth, pheight; 

if ( !newwindow || newwindow.closed ) { 
pwidth=iwidth+30; 
pheight=iheight+30; 
newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10'); 
wheight=iheight; 
wwidth=iwidth; 
} 

if (wheight!=iheight || wwidth!=iwidth ) { 
pwidth=iwidth+30; 
pheight=iheight+60; 
newwindow.resizeTo(pwidth, pheight); 
wheight=iheight; 
wwidth=iwidth; 
} 

newwindow.document.clear(); 
newwindow.focus(); 
newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>'); 
newwindow.document.writeln('<a title="This is the Title" href="javascript:window.close();"><img src=' + url + ' border=0></a>'); 
newwindow.document.writeln('<\/center> <\/body> <\/html>'); 
newwindow.document.close(); 
newwindow.focus(); 
} 

// Routines to tidy up popup windows when page is left 
// Call with an onUnload="tidy5()" in body tag 


function tidy5() { 
if (newwindow && !newwindow.closed) { newwindow.close(); } 
} 

function textFocus() {
	this.style.color = "#000";
	this.value = '';
}
function MultiSelector( list_target, max ){

	// Where to write the list
	this.list_target = list_target;
	// How many elements?
	this.count = 0;
	// How many elements?
	this.id = 0;
	// Is there a maximum?
	if( max ){
		this.max = max;
	} else {
		this.max = -1;
	};
	
	/**
	 * Add a new file input element
	 */
	this.addElement = function( element ){

		// Make sure it's a file input element
		if( element.tagName == 'INPUT' && element.type == 'file' ){

			// Element name -- what number am I?
			//element.name = 'file_' + this.id++;
			element.name = 'files[]';

			// Add reference to this object
			element.multi_selector = this;

			// What to do when a file is selected
			element.onchange = function(){

				// New file input
				var new_element = document.createElement( 'input' );
				new_element.type = 'file';

				// Add new element
				//this.parentNode.insertBefore( new_element, this );
				this.parentNode.appendChild( new_element, this );

				// Apply 'update' to element
				this.multi_selector.addElement( new_element );
				this.multi_selector.addListRow( this );

				// Hide this: we can't use display:none because Safari doesn't like it
				this.style.position = 'absolute';
				this.style.left = '-1000px';

			};
			// If we've reached maximum number, disable input element
			if( this.max != -1 && this.count >= this.max ){
				element.disabled = true;
			};

			// File element counter
			this.count++;
			// Most recent element
			this.current_element = element;
			
		} else {
			// This can only be applied to file input elements!
			alert( 'Error: not a file input element' );
		};

	};

	/**
	 * Add a new row to the list of files
	 */
	this.addListRow = function( element ){

		// Row div
		var new_row = document.createElement( 'div' );
		new_row.className = "PhotoDiv";

		// Delete button
		var new_row_button = document.createElement( 'input' );
		new_row_button.type = 'button';
		new_row_button.value = 'Remove';
		new_row_button.className = 'but';

		//caption box
		var new_row_text = document.createElement( 'input' );
		new_row_text.name = 'pixTxt[]';
		new_row_text.value = 'Photo description (*optional)';
		new_row_text.style.color = '#aaa';
		new_row_text.className = 'captext';
		new_row_text.onfocus = textFocus;

		// References
		new_row.element = element;

		// Delete function
		new_row_button.onclick= function(){

			// Remove element from form
			this.parentNode.element.parentNode.removeChild( this.parentNode.element );

			// Remove this row from the list
			this.parentNode.parentNode.removeChild( this.parentNode );

			// Decrement counter
			this.parentNode.element.multi_selector.count--;

			// Re-enable input element (if it's disabled)
			this.parentNode.element.multi_selector.current_element.disabled = false;

			// Appease Safari
			//    without it Safari wants to reload the browser window
			//    which nixes your already queued uploads
			return false;
		};

		var seperator = document.createElement( 'div' );
      seperator.className = 'seperator';

		// Set row value
		var new_row_file = document.createElement( 'div' );
		new_row_file.className = 'file';
		new_row_file.innerHTML = element.value;


		new_row.appendChild( seperator );
		new_row.appendChild( new_row_button );
		new_row.appendChild( new_row_file );
		new_row.appendChild( new_row_text );
		new_row.appendChild( seperator );

		// Add it to the list
		this.list_target.appendChild( new_row );
		
	};

};
var ajaxObjects = new Array();
function fetchListing(action, elementId) {
 document.getElementById(elementId).innerHTML = 'In Progress';
 var ct = document.getElementById('selectCity').value;
 var lc = document.getElementById('selectArea').value;
 var ty = document.getElementById('selectCat').value;
 var so = document.getElementById('sortSelect').value;
 var co = document.getElementById('countSelect').value;
 var nm = document.getElementById('lname').value;
 var nk = document.getElementById('nkey').checked;
 var url = action + '&type=' + ty + '&city=' + ct + '&area=' + lc + '&count=' + co + '&sort=' + so + '&name=' + nm + '&nkey=' + nk + '&ra=xyz';
 var ajaxIndex = ajaxObjects.length;
 ajaxObjects[ajaxIndex] = new ew();
 ajaxObjects[ajaxIndex].yp = url;
 ajaxObjects[ajaxIndex].method = 'GET';
 ajaxObjects[ajaxIndex].onCompletion = function(){ document.getElementById(elementId).innerHTML = this.yd; };
 ajaxObjects[ajaxIndex].yx();
}

function fetchLog(action, elementId) {
 document.getElementById(elementId).innerHTML = 'In Progress';
 var ui = document.getElementById('selectName').value;
 var ti = document.getElementById('selectTime').value;
 var vr = document.getElementById('selectVer').value;
 var url = action + '&time=' + ti + '&user=' + ui + '&ver=' + vr + '&ra=xyz';
 var ajaxIndex = ajaxObjects.length;
 ajaxObjects[ajaxIndex] = new ew();
 ajaxObjects[ajaxIndex].yp = url;
 ajaxObjects[ajaxIndex].method = 'GET';
 ajaxObjects[ajaxIndex].onCompletion = function(){ document.getElementById(elementId).innerHTML = this.yd; };
 ajaxObjects[ajaxIndex].yx();
}

function checkExistingCatLoc(action, elementId) {
 document.getElementById(elementId).innerHTML = 'In Progress';
 var id = document.getElementById('id').value;
 var tp = document.getElementById('tp').value;
 var url = action + '&id=' + id + '&tp=' + tp + '&ra=xyz';
 var ajaxIndex = ajaxObjects.length;
 ajaxObjects[ajaxIndex] = new ew();
 ajaxObjects[ajaxIndex].yp = url;
 ajaxObjects[ajaxIndex].method = 'GET';
 ajaxObjects[ajaxIndex].onCompletion = function(){ document.getElementById(elementId).innerHTML = this.yd; };
 ajaxObjects[ajaxIndex].yx();
}     

function fetchOrder(action, elementId) {
 document.getElementById(elementId).innerHTML = 'In Progress';
 var ty = document.getElementById('selectCat').value;
 var id = document.getElementById('id').value;
 var url = action + '&type=' + ty + '&id=' + id + '&ra=xyz';
 var ajaxIndex = ajaxObjects.length;
 ajaxObjects[ajaxIndex] = new ew();
 ajaxObjects[ajaxIndex].yp = url;
 ajaxObjects[ajaxIndex].method = 'GET';
 ajaxObjects[ajaxIndex].onCompletion = function(){ document.getElementById(elementId).innerHTML = this.yd; };
 ajaxObjects[ajaxIndex].yx();
}

function checkCategoryLocation(action, elementId) {

new Ajax.Request(action, { 
			method: 'get',
			onSuccess: function(transport) {document.getElementById(elementId).innerHTML = transport.responseText; }
});
 document.getElementById(elementId).innerHTML = 'In Progress';

return;
}

function addCategLocationElement(addItems, blist, txt, divId) {

var itemBox=document.getElementById(addItems);
var tr = itemBox.insertRow(-1);
var td1 = tr.insertCell(-1);
var inp = document.createElement('input');
inp.setAttribute("type", "hidden");
inp.setAttribute("name", "codes[]");
inp.setAttribute("value", divId); 
var prodName = document.createTextNode(txt);
td1.appendChild(prodName);
td1.appendChild(inp); 
var al=document.getElementById(blist); 
al.innerHTML = '';
}

function updateValuesAndCheck(categError, checkOrder, checkAction, availList) {
 var cE = document.getElementById(categError); 
 cE.innerHTML = ''; 
 var url = $(checkOrder).zX();
 checkCategoryLocation(checkAction + url, availList);
}

function checkCategoryKeywords(action, elementId) {

   $.ajax({ 
      url: action,
      cache: false,
      success: function(data) {
         document.getElementById(elementId).innerHTML = data;
      }
   });
 	document.getElementById(elementId).innerHTML = 'In Progress';

	return;
}

function updateKeywordsAndCheck(keywords, categories, getAction) {
 	var cE = document.getElementById(keywords);
 	cE.innerHTML = '';
 	var url = $(categories).zX();
 	checkCategoryKeywords(getAction + url, keywords);
}

function queryAndUpdate(action, elementId, buttonId) {

new Ajax.Request(action, {
         method: 'get',
         onSuccess: function(transport) {document.getElementById(elementId).innerHTML = transport.responseText; 
   			var bE = document.getElementById(buttonId);
				bE.style.visibility = 'visible';
			}
});
 document.getElementById(elementId).innerHTML = "In Progress" + document.getElementById(elementId).innerHTML;

   return;
}

function updateProductandCheck(productDiv, productForm, buttonId, getAction) {
   var cE = document.getElementById(productDiv);
   var bE = document.getElementById(buttonId);
	bE.style.visibility = 'hidden';
   var url = $(productForm).zX();
   queryAndUpdate(getAction + '&' + url, productDiv, buttonId);
}

function getFormContent(fVar) {
	return fVar;
}

function editProduct(buttonId, productDiv, content) {
   var bE = document.getElementById(buttonId);
	bE.style.visibility = 'hidden';
	var cE = document.getElementById(productDiv);
	cE.innerHTML = content;
}

function deleteProduct(buttonId, productDiv, getAction) {
   var bE = document.getElementById(buttonId);
	bE.style.visibility = 'hidden';
	document.getElementById(productDiv).style.height = "40px";
   queryAndAdd(getAction, productDiv);
}

function queryAndAdd(action, elementId) {

new Ajax.Request(action, {
         method: 'get',
         onSuccess: function(transport) {document.getElementById(elementId).innerHTML = transport.responseText;
         }
});
 document.getElementById(elementId).innerHTML = "In Progress" + document.getElementById(elementId).innerHTML;
 
   return;
}


function addProductandCheck(productDiv, productForm, getAction) {
   var url = $(productForm).zX();
   queryAndAdd(getAction + '&' + url, productDiv);
}

function insertAfter( referenceNode, newNode ) {
    referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}

function addProduct(newdiv, newid, content) {
   var nD = document.getElementById(newdiv);
	var divN=document.createElement('div');
	divN.id = newid;
	divN.innerHTML = content;
	insertAfter(nD, divN);
}


