function submitRegistration(me)
{
    //alert("test..");
	//showLoadingRegistration();
	me.value= "PROCESSING.....";
	me.disabled = true;
	clearErrorMessages();
	hideErrorMsg();
	$('registration_form').request({onComplete: responseRegistration});
}

function responseRegistration($originalRequest)
{
	//$('div_loading_registration').innerHTML = $originalRequest.responseText;
	$errors = $originalRequest.responseText;
	$errors = $errors.split("<");
   	$errors = $errors[0].split("-");
	$ctr = parseInt(eval($errors[0]));
	
	var errormsg = "";
	var $error_msg2 = "";

	if( !isNaN($ctr) || $ctr > 0 )
	{
		for( $x = 1; $x <= $ctr; $x++ )
		{
			$error_msg = $errors[$x].split(".");
			$($error_msg[0] + "_label").style.color="red";
			
			$error_msg2 = $errors[$x].split(",");
			$error_msg2 = $error_msg2[0].split(".");
			
			if($error_msg2[1]!=""){
				showErrorMsg($error_msg2[1]);
				$x = $ctr;
				document.getElementById("btn_submit").value= "Request Login";
				document.getElementById("btn_submit").disabled = false;
				break;
			}
		}	
	}
	else 
	{
		document.getElementById("success_form").submit();
	}
}

function showErrorMsg(txt)
{
	$('Error_message').style.display = "block";
   
    if(txt.match("invalid")=="invalid")
	{	
		$('Error_message').innerHTML = "Email address is in valid format.";
	}		
	else if(txt.match("Already")=="Already")
	{
		$('Error_message').innerHTML =  "Email Already Used.";
	}
	else if(txt.match("Matched")=="Matched")
	{
		$('Error_message').innerHTML =  "Password Not Matched.";
	}
	else
	{
		$('Error_message').innerHTML = "Please fill-in the required field(s) colored in red.";
	}
}

function hideErrorMsg()
{
	$('Error_message').innerHTML = "&nbsp;";
}

function clearErrorMessages()
{
	$('firstname_label').style.color  	= "#000";
	//$('middlename_error').innerHTML        = "";
	$('lastname_label').style.color   	= "#000";
	$('address_label').style.color      = "#000";
	$('country_label').style.color      = "#000";
	$('city_label').style.color       	= "#000";
	$('state_province_label').style.color	= "#000";
	$('zip_code_label').style.color  	= "#000";
	//$('company_error').innerHTML           = "";
	//$('company_position_error').innerHTML  = "";
	$('phone_label').style.color       	= "#000";
	$('mobile_label').style.color       = "#000";
	//$('fax_label').innerHTML               = "";
	//$('shop_code_error').innerHTML         = "";
	$('email_label').style.color       	= "#000";
	//$('username_error').innerHTML          = "";
	$('password_label').style.color    	= "#000";
	$('retype_password_label').style.color 	= "#000";
	//$('hear_about_error').innerHTML        = "";	
	//$('interest_products_error').innerHTML = "";	
	//$('agree_error').innerHTML             = "";	
}

function showLoadingRegistration()
{
	$('country').style.display = "none";
	$('div_loading_registration').style.display = "block";
	clearErrorMessages();
	//$('registration_form').disable();
}

function hideLoadingRegistration()
{
	$('country').style.display = "block";
	$('registration_form').enable();
	$('div_loading_registration').style.display = "none";
}

function submitMyAccount()
{
	showLoadingMyAccount();
	$('my_account_form').request({onComplete: responseMyAccount});
}

function responseMyAccount($originalRequest)
{
	$errors = $originalRequest.responseText;
	$errors = $errors.split("-");
	
	if( $errors[0] == "success" )
	{
		window.location = "?p=my_account";
	}
	else if( $errors[0] == "failed" )
	{
		window.location = "?p=my_account";
	}
	else
	{
		$ctr = eval($errors[0]);
		for( $x = 1; $x <= $ctr; $x++ )
		{
			$error_msg = $errors[$x].split(".");
			$($error_msg[0] + "_error").innerHTML = $error_msg[1];
		}
		hideLoadingMyAccount();
	}
}

function clearErrorMessagesMyAccount()
{
	$('firstname_error').innerHTML        = "";
	$('lastname_error').innerHTML         = "";
	$('address_error').innerHTML          = "";
//	$('country_error').innerHTML          = "";
	$('city_error').innerHTML             = "";
	$('state_province_error').innerHTML   = "";
	$('zip_code_error').innerHTML         = "";
	$('company_error').innerHTML          = "";
	$('website_error').innerHTML          = "";
	$('phone_error').innerHTML            = "";
	$('mobile_error').innerHTML           = "";
	$('fax_error').innerHTML              = "";
}

function showLoadingMyAccount()
{
	$('country').style.display = "none";
	$('div_loading_my_account').style.display = "block";
	clearErrorMessagesMyAccount();
	//$('registration_form').disable();
}

function hideLoadingMyAccount()
{
	$('country').style.display = "block";
	$('my_account_form').enable();
	$('div_loading_my_account').style.display = "none";
}

/**
* For Collection Items
**/

function submitItemAddToCart()
{
	if( parseInt($('add_cart_quantity').value) >= 1 )
		$("add_cart").request({onComplete: responseItemAddToCart});
	else
		alert("Minimum Order is 1");
}

function responseItemAddToCart($originalRequest)
{
	//$("div_quick_shopping_cart").innerHTML = "<div style=\"text-align:center\"><br/><br/><img src=\"images/popup/cart_updating.gif\" alt=\"Cart Updating\" /><br/>Updating Cart</div>";
	//closeLigthBox();
	$alert_message = $originalRequest.responseText;
	alert($alert_message);
	updateQuickCartTop();
}

function updateQuickCartTop()
{
	var $url    = 'quick_cart.php';
	var myAjax = new Ajax.Request( $url, {method: 'get', onComplete: showQuickCartTop} );
}

function showQuickCartTop($originalRequest)
{
	$("div_quick_shopping_cart").innerHTML = $originalRequest.responseText;
}

function popupimage($id)
{
 var $url = $id;
 window.open($url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=415px,height=450px,screenX=150,screenY=150,top=150,left=150')
}


function showCatalogue($url)
{
	if(BrowserDetect.browser=="Explorer")
		NewWindow($url,'Catalogue','985','870','yes','center');
	else
		NewWindow($url,'Catalogue','965','870','yes','center');
	
	return false;
}

function showSizeChart($url)
{
	NewWindow($url,'Size Chart','840','470','no','center');
	return false;
}

function showColorChart($url)
{
	NewWindow($url,'Size Chart','1100','700','no','center');
	return false;
}

/****************************************************
     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 showCollectionBorder($id)
{
	$('image_collection_' + $id).style.border = "1px solid #aaaaaa";
}
	
function hideCollectionBorder($id)
{
	$('image_collection_' + $id).style.border = "0px solid #aaaaaa";
}

function product_search()
{
    document.getElementById("product_search").submit();
}

function submit_selected_courier(me)
{
	var val=0;
	document.getElementById("courier_selection").selected_courier.value=me.value;
	val = document.getElementById("courier_selection").selected_courier.value;
    document.getElementById("courier_selection").submit();
}

