/**
function sample () 
{
	var $url    = 'sample.php';
	var $pars   = 'x=x';
	var myAjax = new Ajax.Request( $url, {method: 'get', parameters: $pars, onComplete: sample} );
}
**/

function submitRegistration()
{
	jj_loading_show();
	
	$('registration_form').request({onComplete: responseRegistration});
}

function responseRegistration($originalRequest)
{
	jj_loading_hide();
	$errors = $originalRequest.responseText;
	$errors = $errors.split("-");
	if( $errors[0] != "success" )
	{
		//alert('a');
		clearRegistrationForm();
		$error_message = "<strong>" + $errors[1] + "</strong>";
		$ctr = eval($errors[0]);
		
		for( $x = 2; $x <= $ctr + 1; $x++ )
		{
			$error_msg = $errors[$x].split(".");
			$("registration_" + $error_msg[0]).style.backgroundColor  = "#ff7777";
			$error_message = $error_message + " <br/> &nbsp;&nbsp;&nbsp;&nbsp;" + $error_msg[1];
		}
		jj_alert($error_message);
		//$('registration_firstname').focus();
	}
	else if($errors[0] == "success")
	{
		window.location = "./?p=registration_welcome";
	}
}

function clearRegistrationForm()
{
	$('registration_firstname').style.backgroundColor  = "#ffffff";
	$('registration_lastname').style.backgroundColor   = "#ffffff";
	$('registration_phone').style.backgroundColor      = "#ffffff";
	$('registration_country').style.backgroundColor    = "#ffffff";
	$('registration_username').style.backgroundColor   = "#ffffff";
	$('registration_password').style.backgroundColor   = "#ffffff";
	$('registration_repassword').style.backgroundColor = "#ffffff";
}

function submitContactUs()
{
	$name     = $('contact_us_name').value;
	$phone    = $('contact_us_phone').value;
	$email    = $('contact_us_email').value;
	$comments = $('contact_us_comments').value;
	
	$errors   = false;
	$message  = "";
	
	if( trim($name) == "" )
		$errors = true;
	else if( trim($phone) == "" )
		$errors = true;
	else if( trim($comments) == "" )
		$errors = true;

	if( $errors == true )
	{
		alert("Please complete the form");
	}
	else
	{
		if( isEmailValid($email) )
		{
			$('contact_us_form').request({onComplete: function(){ alert('Form data saved!') }});
		}
		else
		{
			alert("Please enter a valid email address");
		}
	}
}

/**
* For Collection Items
**/


/****************************************************
     Author: Eric King
     Url: http://redrival.com/eak/index.shtml
     This script is free to use as long as this info is left in
     Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,'',settings);
}

function isEmailValid(elem)
{
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.match(emailExp)){
		return true;
	}else{
		return false;
	}
}

function trim(str)
{
	var trimmed = str.replace(/^\s+|\s+$/g, '');
	return trimmed;
}