function openWin( url, theWidth, theHeight )
{
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features= 'height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",scrollbars=yes";

	theWin = window.open( url, '', features );
}

function MM_findObj(n, d)
{ //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers()
{ //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}

////////////////////////////////////////////////////////////////////////////////
// INDEX
////////////////////////////////////////////////////////////////////////////////
function checkKeyword( frm )
{
	if( frm.brand.selectedIndex == 0 && frm.keyword.value == '' )
	{
		alert( "Please type the keyword for search." );

		frm.keyword.focus();
		return false;
	}

	return true;
}

function checkMake( frm )
{
	if( frm.make_select.selectedIndex == 0 )
	{
		alert( "Please choose the make,model,year for search." );

		frm.make_select.focus();
		return false;
	}

	return true;
}

function priceSearch()
{
	var frmSearch = document.forms['search_form'];
	var frmFilter = document.forms['search_filter'];
	
	if( frmFilter.model != undefined ) {
		var model = frmFilter.model.options[frmFilter.model.selectedIndex].value;
	
		if( model.length > 0 )
			frmSearch.model.value = model;
	}

	frmSearch.category.value = frmFilter.category.value;

	if( frmFilter.priceFrom != undefined ) frmSearch.priceFrom.value = frmFilter.priceFrom.value;
	if( frmFilter.priceTo != undefined ) frmSearch.priceTo.value = frmFilter.priceTo.value;
	if( frmFilter.sc_brand != undefined ) frmSearch.sc_brand.value = frmFilter.sc_brand.value;
	if( frmFilter.sc_color != undefined ) frmSearch.sc_color.value = frmFilter.sc_color.value;
	if( frmFilter.sc_size != undefined ) frmSearch.sc_size.value = frmFilter.sc_size.value;

	frmSearch.keyword.value = '';
	frmSearch.submit();
}

function modelSearch()
{
	var frmSearch = document.forms['search_form'];
	var frmFilter = document.forms['search_filter'];
	var model = frmFilter.model.options[frmFilter.model.selectedIndex].value;

	if( model.length > 0 )
	{
		frmSearch.category.value = frmFilter.category.value;
		frmSearch.model.value = model;

		frmSearch.keyword.value = '';
		frmSearch.submit();
	}
}

function sortSearch()
{
	var frmSearch = document.forms['search_form'];
	var frmFilter = document.forms['search_sort'];
	var r_sortBy = frmFilter.r_sortBy.options[frmFilter.r_sortBy.selectedIndex].value;

	frmSearch.category.value = frmFilter.category.value;
	frmSearch.r_sortBy.value = r_sortBy;
	
	if( document.forms['search_filter'] != undefined ) {
		var frmFilter = document.forms['search_filter'];
		if( frmFilter.priceFrom != undefined ) frmSearch.priceFrom.value = frmFilter.priceFrom.value;
		if( frmFilter.priceTo != undefined ) frmSearch.priceTo.value = frmFilter.priceTo.value;
		if( frmFilter.sc_brand != undefined ) frmSearch.sc_brand.value = frmFilter.sc_brand.value;
		if( frmFilter.sc_color != undefined ) frmSearch.sc_color.value = frmFilter.sc_color.value;
		if( frmFilter.sc_size != undefined ) frmSearch.sc_size.value = frmFilter.sc_size.value;
	}
	
	frmSearch.submit();
}

////////////////////////////////////////////////////////////////////////////////
// ITEM VIEW
////////////////////////////////////////////////////////////////////////////////
function changeImage( img )
{
	//var obj = document.getElementById( 'img' );
	//obj.src = img;
	// ONLY WORKS ON IE

	document.images['img'].src = img;
}

function changeImageZoom( img , bigimg , MojoZoom)
{
	//var obj = document.getElementById( 'img' );
	//obj.src = img;
	// ONLY WORKS ON IE

	document.images['img'].src = img;
	if(bigimg.indexOf('noImg')<0){
		document.images['img'].setAttribute("data-zoomsrc",bigimg);
		MojoZoom.init();
	} else {
		document.images['img'].setAttribute("data-zoomsrc",'');
		MojoZoom.init();
	}
	//alert(document.images['img'].getAttribute("data-zoomsrc"));
	//document.images['img'].data-zoomsrc = bigimg;
}

function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
} 

function changeImageByName( name, img )
{
	//var obj = document.getElementById( 'img' );
	//obj.src = img;
	// ONLY WORKS ON IE

	document.images[name].src = img;
}

function enlarge()
{
	//var obj = document.getElementById( 'img' );
	//var img = obj.src;
	// ONLY WORKS ON IE
	var img = document.images['img'].src;

	var large = img.substring( 0, img.length-6 );
	large = large + ".JPG";

	openWin( '/view_enlarge.php?img=' + large, 900, 600 );
}

function submit( f )
{
	if( confirm( "Are you sure you want to delete your review ?" ) )
	{
		f.submit();
	}
}

function IsNumeric(strString)
{
	//var strValidChars = "0123456789.-";
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
	     {
	     blnResult = false;
	     }
	  }
	return blnResult;
}

function sendToFriend( f )
{
	if( !check_email( f.to_email.value ) )
	{
		alert( 'Invalid e-mail address. Please retype e-mail address.' );
	}
	else
	{
		f.submit();
	}
}

////////////////////////////////////////////////////////////////////////////////
// CHECKOUT
////////////////////////////////////////////////////////////////////////////////
function hideshow( id )
{
	if( !document.getElementById )
	{
		return;
	}

	which = document.getElementById( id );
	visible=(which.style.display!="none");

	if( visible )
		which.style.display = "none";
	else
		which.style.display = "block";
}

function confirmMsg( msg, url )
{
	if( confirm( msg ) )
	{
		location.href = url;
	}
}

function hideshowDisplay( id, how )
{
	if( !document.getElementById )
	{
		return;
	}

	which = document.getElementById( id );
	if( which != undefined ) which.style.display = how;
}

////////////////////////////////////////////////////////////////////////////////
// TESTIMONIAL
////////////////////////////////////////////////////////////////////////////////
function validateTesti()
{
	var frm = document.forms['writeForm'];

	if( frm.title.value == '' )
	{
		frm.title.focus();
		alert( "Please fill out title." );
		return false;
	}

	if( frm.body.value == '' )
	{
		frm.body.focus();
		alert( "Please fill out contents." );
		return false;
	}

	return true;
}

////////////////////////////////////////////////////////////////////////////////
// TRACKING
////////////////////////////////////////////////////////////////////////////////
function submitTracking( f )
{
	if( f.email.value=='') {
		alert("Please type e-mail address.");
		f.email.focus();
	} else if( f.yahoo.value=='' && f.mbp.value=='' && f.other.value=='' ) {
		alert("Please type order #");
	} else {
		f.submit();
	}
}

////////////////////////////////////////////////////////////////////////////////
// MY ACCOUNT
////////////////////////////////////////////////////////////////////////////////
function switchState( type )
{
	var frm = document.forms['register'];

	if( type == 'B' )
	{
		if( frm.p_country.options[frm.p_country.selectedIndex].value == 'US' )
		{
			document.getElementById("p_state").style.display = "block";
			document.getElementById("p_state_m").style.display = "none";
		}
		else
		{
			document.getElementById("p_state").style.display = "none";
			document.getElementById("p_state_m").style.display = "block";
		}
	}
	else if( type == 'S' )
	{
		if( frm.p_ship_country.options[frm.p_ship_country.selectedIndex].value == 'US' )
		{
			document.getElementById("p_ship_state").style.display = "block";
			document.getElementById("p_ship_state_m").style.display = "none";
		}
		else
		{
			document.getElementById("p_ship_state").style.display = "none";
			document.getElementById("p_ship_state_m").style.display = "block";
		}
	}
}

function switchStateFromBill()
{
	var frm = document.forms['myprofile'];

	if( frm.p_country.options[frm.p_country.selectedIndex].value == 'US' )
	{
		document.getElementById("p_state").style.display = "block";
		document.getElementById("p_state_m").style.display = "none";
	}
	else
	{
		document.getElementById("p_state").style.display = "none";
		document.getElementById("p_state_m").style.display = "block";
	}
}

function switchStateFromShip( type )
{
	var frm;
	if( type == 'E' )
		frm = document.forms['address'];
	else if( type == 'N' )
		frm = document.forms['newaddr'];

	if( frm.p_ship_country.options[frm.p_ship_country.selectedIndex].value == 'US' )
	{
		frm.p_ship_state.style.display = "block";
		frm.p_ship_state_m.style.display = "none";
	}
	else
	{
		frm.p_ship_state.style.display = "none";
		frm.p_ship_state_m.style.display = "block";
	}
}

function check_email( e )
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
		}	
	} 
	
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
		return (-1);		
		} 
	}
}

function register( f )
{
	var indexUS = -1;
	for( var i=0; i<f.p_country.options.length; i++ )
	{
		if( f.p_country.options[i].value == 'US' )
		{
			indexUS = i;
			break;
		}
	}

	if( f.p_firstname.value=='') {
		alert("Please type first name.");
		f.p_firstname.focus();
	} else if( f.p_lastname.value=='') {
		alert("Please type last name.");
		f.p_lastname.focus();
	} else if( f.p_address1.value=='') {
		alert("Please type street address.");
		f.p_address1.focus();
	} else if( f.p_city.value=='') {
		alert("Please type city !!");
		f.p_city.focus();
	} else if( f.p_country.selectedIndex == indexUS && f.p_state.value == '' ) {
		alert("Please type state.");
		f.p_state.focus();
	} else if( f.p_zip.value=='') {
		alert("Please type zipcode.");
		f.p_zip.focus();
	} else if( f.p_tel1.value=='') {
		alert("Please type day time phone number.");
		f.p_tel1.focus();
	} else if( f.p_email.value=='') {
		alert("Please type e-mail address.");
		f.p_email.focus();
	} else if(!check_email(f.p_email.value)){
		alert("Invalid e-mail address. Please retype e-mail address.");
		f.p_email.focus();
	} else if( f.p_password.value=='' ) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!='' && f.p_password.value.length < 6) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!=f.p_password1.value) {
		alert("Password does not match. Please retype password.");
		f.p_password1.focus();
	} else if( f.p_password.value!='' && (f.p_question.selectedIndex <= 0 || f.p_answer.value == '') ) {
		alert("Please type secret question.");
		f.p_answer.focus();
	} else if( f.security_code.value=='') {
		alert("Please type security code.");
		f.security_code.focus();
	} else {

		if( f.security_code.value.toUpperCase() != (getCookie( 'SECURITYCODE' )).toUpperCase()  )
		{
			alert( "Please type security code correctly" );
			f.security_code.focus();
		}
		else
		{
			if( f.same_as_billing[0].checked == true ) {
				f.submit();
			} else {
				if( f.p_ship_firstname.value=='') {
					alert("Please type first name.");
					f.p_ship_firstname.focus();
				} else if( f.p_ship_lastname.value=='') {
					alert("Please type last name.");
					f.p_ship_lastname.focus();
				} else if( f.p_ship_address1.value=='') {
					alert("Please type street address.");
					f.p_ship_address1.focus();
				} else if( f.p_ship_city.value=='') {
					alert("Please type city.");
					f.p_ship_city.focus();
				} else if( f.p_ship_country.selectedIndex == indexUS && f.p_ship_state.value == '' ) {
					alert("Please type state.");
					f.p_ship_state.focus();
				} else if( f.p_ship_zip.value=='') {
					alert("Please type zipcode.");
					f.p_ship_zip.focus();
				} else if( f.p_ship_tel1.value=='') {
					alert("Please type day time phone number.");
					f.p_ship_tel1.focus();
				} else {
					f.submit();
				}
			}
		}
	}
}

function register_guest( f )
{
	var indexUS = -1;
	for( var i=0; i<f.p_country.options.length; i++ )
	{
		if( f.p_country.options[i].value == 'US' )
		{
			indexUS = i;
			break;
		}
	}

	if( f.p_firstname.value=='') {
		alert("Please type first name.");
		f.p_firstname.focus();
	} else if( f.p_lastname.value=='') {
		alert("Please type last name.");
		f.p_lastname.focus();
	} else if( f.p_address1.value=='') {
		alert("Please type street address.");
		f.p_address1.focus();
	} else if( f.p_city.value=='') {
		alert("Please type city !!");
		f.p_city.focus();
	} else if( f.p_country.selectedIndex == indexUS && f.p_state.value == '' ) {
		alert("Please type state.");
		f.p_state.focus();
	} else if( f.p_zip.value=='') {
		alert("Please type zipcode.");
		f.p_zip.focus();
	} else if( f.p_tel1.value=='') {
		alert("Please type day time phone number.");
		f.p_tel1.focus();
	} else if( f.p_email.value=='') {
		alert("Please type e-mail address.");
		f.p_email.focus();
	} else if(!check_email(f.p_email.value)){
		alert("Invalid e-mail address. Please retype e-mail address.");
		f.p_email.focus();
	//} else if( f.security_code.value=='') {
		//alert("Please type security code.");
		//f.security_code.focus();
	} else {

		//if( f.security_code.value.toUpperCase() != (getCookie( 'SECURITYCODE' )).toUpperCase()  )
		//{
			//alert( "Please type security code correctly" );
			//f.security_code.focus();
		//}
		//else
		//{
			if( f.same_as_billing[0].checked == true ) {
				f.submit();
			} else {
				if( f.p_ship_firstname.value=='') {
					alert("Please type first name.");
					f.p_ship_firstname.focus();
				} else if( f.p_ship_lastname.value=='') {
					alert("Please type last name.");
					f.p_ship_lastname.focus();
				} else if( f.p_ship_address1.value=='') {
					alert("Please type street address.");
					f.p_ship_address1.focus();
				} else if( f.p_ship_city.value=='') {
					alert("Please type city.");
					f.p_ship_city.focus();
				} else if( f.p_ship_country.selectedIndex == indexUS && f.p_ship_state.value == '' ) {
					alert("Please type state.");
					f.p_ship_state.focus();
				} else if( f.p_ship_zip.value=='') {
					alert("Please type zipcode.");
					f.p_ship_zip.focus();
				} else if( f.p_ship_tel1.value=='') {
					alert("Please type day time phone number.");
					f.p_ship_tel1.focus();
				} else {
					f.submit();
				}
			}
		//}
	}
}

function register_wholesale( f ) // for required Company Name
{
	var indexUS = -1;
	for( var i=0; i<f.p_country.options.length; i++ )
	{
		if( f.p_country.options[i].value == 'US' )
		{
			indexUS = i;
			break;
		}
	}

	if( f.p_firstname.value=='') {
		alert("Please type first name.");
		f.p_firstname.focus();
	} else if( f.p_lastname.value=='') {
		alert("Please type last name.");
		f.p_lastname.focus();
	} else if( f.p_company.value=='') {
		alert("Please type Company Name.");
		f.p_company.focus();
	} else if( f.p_address1.value=='') {
		alert("Please type street address.");
		f.p_address1.focus();
	} else if( f.p_city.value=='') {
		alert("Please type city !!");
		f.p_city.focus();
	} else if( f.p_country.selectedIndex == indexUS && f.p_state.value == '' ) {
		alert("Please type state.");
		f.p_state.focus();
	} else if( f.p_zip.value=='') {
		alert("Please type zipcode.");
		f.p_zip.focus();
	} else if( f.p_tel1.value=='') {
		alert("Please type day time phone number.");
		f.p_tel1.focus();
	} else if( f.p_email.value=='') {
		alert("Please type e-mail address.");
		f.p_email.focus();
	} else if(!check_email(f.p_email.value)){
		alert("Invalid e-mail address. Please retype e-mail address.");
		f.p_email.focus();
	} else if( f.p_password.value=='' ) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!='' && f.p_password.value.length < 6) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!=f.p_password1.value) {
		alert("Password does not match. Please retype password.");
		f.p_password1.focus();
	} else if( f.p_password.value!='' && (f.p_question.selectedIndex <= 0 || f.p_answer.value == '') ) {
		alert("Please type secret question.");
		f.p_answer.focus();
	} else if( f.security_code.value=='') {
		alert("Please type security code.");
		f.security_code.focus();
	} else {

		if( f.security_code.value.toUpperCase() != (getCookie( 'SECURITYCODE' )).toUpperCase()  )
		{
			alert( "Please type security code correctly" );
			f.security_code.focus();
		}
		else
		{
			if( f.same_as_billing[0].checked == true ) {
				f.submit();
			} else {
				if( f.p_ship_firstname.value=='') {
					alert("Please type first name.");
					f.p_ship_firstname.focus();
				} else if( f.p_ship_lastname.value=='') {
					alert("Please type last name.");
					f.p_ship_lastname.focus();
				} else if( f.p_ship_address1.value=='') {
					alert("Please type street address.");
					f.p_ship_address1.focus();
				} else if( f.p_ship_city.value=='') {
					alert("Please type city.");
					f.p_ship_city.focus();
				} else if( f.p_ship_country.selectedIndex == indexUS && f.p_ship_state.value == '' ) {
					alert("Please type state.");
					f.p_ship_state.focus();
				} else if( f.p_ship_zip.value=='') {
					alert("Please type zipcode.");
					f.p_ship_zip.focus();
				} else if( f.p_ship_tel1.value=='') {
					alert("Please type day time phone number.");
					f.p_ship_tel1.focus();
				} else {
					f.submit();
				}
			}
		}
	}
}

function register_corp( f ) // for Kgcus
{
	var indexUS = -1;
	for( var i=0; i<f.p_country.options.length; i++ )
	{
		if( f.p_country.options[i].value == 'US' )
		{
			indexUS = i;
			break;
		}
	}

	if( f.p_firstname.value=='') {
		alert("Please type first name.");
		f.p_firstname.focus();
	} else if( f.p_lastname.value=='') {
		alert("Please type last name.");
		f.p_lastname.focus();
	} else if( f.p_company.value=='') {
		alert("Please type Company Name.");
		f.p_company.focus();
	} else if( f.p_address1.value=='') {
		alert("Please type street address.");
		f.p_address1.focus();
	} else if( f.p_city.value=='') {
		alert("Please type city !!");
		f.p_city.focus();
	} else if( f.p_country.selectedIndex == indexUS && f.p_state.value == '' ) {
		alert("Please type state.");
		f.p_state.focus();
	} else if( f.p_zip.value=='') {
		alert("Please type zipcode.");
		f.p_zip.focus();
	} else if( f.p_tel1.value=='') {
		alert("Please type day time phone number.");
		f.p_tel1.focus();
	} else if( f.p_email.value=='') {
		alert("Please type e-mail address.");
		f.p_email.focus();
	} else if(!check_email(f.p_email.value)){
		alert("Invalid e-mail address. Please retype e-mail address.");
		f.p_email.focus();
	} else if( f.p_password.value=='' ) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!='' && f.p_password.value.length < 6) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!=f.p_password1.value) {
		alert("Password does not match. Please retype password.");
		f.p_password1.focus();
	} else if( f.p_password.value!='' && (f.p_question.selectedIndex <= 0 || f.p_answer.value == '') ) {
		alert("Please type secret question.");
		f.p_answer.focus();
	} else if( f.security_code.value=='') {
		alert("Please type security code.");
		f.security_code.focus();
	} else if( !f.agree_check.checked) {
		alert("Please check the agreement");
	} else {

		if( f.security_code.value.toUpperCase() != (getCookie( 'SECURITYCODE' )).toUpperCase()  )
		{
			alert( "Please type security code correctly" );
			f.security_code.focus();
		}
		else
		{
			f.submit();
		}
	}
}

function updateProfile( f )
{
	var indexUS = -1;
	for( var i=0; i<f.p_country.options.length; i++ )
	{
		if( f.p_country.options[i].value == 'US' )
		{
			indexUS = i;
			break;
		}
	}

	if( f.p_firstname.value=='') {
		alert("Please type first name.");
		f.p_firstname.focus();
	} else if( f.p_lastname.value=='') {
		alert("Please type last name.");
		f.p_lastname.focus();
	} else if( f.p_address1.value=='') {
		alert("Please type street address.");
		f.p_address1.focus();
	} else if( f.p_city.value=='') {
		alert("Please type city !!");
		f.p_city.focus();
	} else if( f.p_country.selectedIndex == indexUS && f.p_state.value == '' ) {
		alert("Please type state.");
		f.p_state.focus();
	} else if( f.p_zip.value=='') {
		alert("Please type zipcode.");
		f.p_zip.focus();
	} else if( f.p_tel1.value=='') {
		alert("Please type day time phone number.");
		f.p_tel1.focus();
	} else if( f.p_email.value=='') {
		alert("Please type e-mail address.");
		f.p_email.focus();
	} else if(!check_email(f.p_email.value)){
		alert("Invalid e-mail address. Please retype e-mail address.");
		f.p_email.focus();
	} else if( f.p_password.value=='' ) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!='' && f.p_password.value.length < 6) {
		alert("Password need to be at least 6 characters.");
		f.p_password.focus();
	} else if( f.p_password.value!=f.p_password1.value) {
		alert("Password does not match. Please retype password.");
		f.p_password1.focus();
	} else if( f.p_password.value!='' && (f.p_question.selectedIndex <= 0 || f.p_answer.value == '') ) {
		alert("Please type secret word.");
		f.p_answer.focus();
	} else {
			f.submit();
	}
}

function submitAddr( f )
{
	var indexUS = -1;
	for( var i=0; i<f.p_ship_country.options.length; i++ )
	{
		if( f.p_ship_country.options[i].value == 'US' )
		{
			indexUS = i;
			break;
		}
	}

	if( f.p_ship_firstname.value=='') {
		alert("Please type first name.");
		f.p_ship_firstname.focus();
	} else if( f.p_ship_lastname.value=='') {
		alert("Please type last name.");
		f.p_ship_lastname.focus();
	} else if( f.p_ship_address1.value=='') {
		alert("Please type street address.");
		f.p_ship_address1.focus();
	} else if( f.p_ship_city.value=='') {
		alert("Please type city.");
		f.p_ship_city.focus();
	} else if( f.p_ship_country.selectedIndex == indexUS && f.p_ship_state.value == '' ) {
		alert("Please type state.");
		f.p_ship_state.focus();
	} else if( f.p_ship_zip.value=='') {
		alert("Please type zipcode.");
		f.p_ship_zip.focus();
	} else if( f.p_ship_tel1.value=='') {
		alert("Please type day time phone number.");
		f.p_ship_tel1.focus();
	} else {
		f.submit();
	}
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");

		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);

			if (c_end==-1)
				c_end=document.cookie.length;

			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}

	return "";
}

////////////////////////////////////////////////////////////////////////////////
// RETURN
////////////////////////////////////////////////////////////////////////////////
function ordTrim()
{
	var ords = "";

	ords = document.ret.ordno.value;
	document.ret.ordno.value = ords.toUpperCase();
}

function returnCalculate()
{
   var tot = 0;
   tot += (document.ret.prc1.value * document.ret.qty1.value);
   tot += (document.ret.prc2.value * document.ret.qty2.value);
   tot += (document.ret.prc3.value * document.ret.qty3.value);
   tot += (1.0 * document.ret.tax.value);
   document.ret.total.value = Math.round(tot * 100.0) / 100;

   if (!isBlank(document.ret.item1.value)) document.ret.item1.value = document.ret.item1.value.toUpperCase();
   if (!isBlank(document.ret.item2.value)) document.ret.item2.value = document.ret.item2.value.toUpperCase();
   if (!isBlank(document.ret.item3.value)) document.ret.item3.value = document.ret.item3.value.toUpperCase();
}

function uf_CheckForm(f)
{
	if (isBlank(f.custname.value))
	{
		alert("Please, Enter your name.");
		f.custname.focus();
		return false;
	}

	if (isBlank(f.ordno.value))
	{
		alert("Please, Enter your order number.");
		f.ordno.focus();
		return false;
	}

    if (isBlank(f.email.value))
    {
        alert("Please, Enter your email address.");
        f.email.focus();
        return false;
    }

	if (!checkMail(f.email.value))
	{
        alert("Your email address is not valid.");
        f.email.focus();
        return false;
	}

    if (isBlank(f.orddate.value))
    {
        alert("Please, Enter the order date.");
        f.orddate.focus();
        return false;
    }

	if (isBlank(f.phone.value))
	{
		alert("Please, Enter your telephone number.");
		f.phone.focus();
		return false;
	}

	if (isBlank(f.item1.value))
	{
		alert("Please, Enter item code.");
		f.item1.focus();
		return false;
	}
	else
	{
		if (isBlank(f.qty1.value) && !(parseInt(f.qty1.value) >= 0))
		{
			alert("Please, Enter Quantity.");
			f.qty1.focus();
			return false;
		}

		if (isBlank(f.prc1.value) && !(parseFloat(f.prc1.value) >= 0.0))
		{
			alert("Please, Enter Price.");
			f.prc1.focus();
			return false;
		}
	}

	if (!isBlank(f.item2.value))
	{
		if (isBlank(f.qty2.value) && !(parseInt(f.qty2.value) >= 0))
		{
			alert("Please, Enter Quantity.");
			f.qty2.focus();
			return false;
		}

		if (isBlank(f.prc2.value) && !(parseFloat(f.prc2.value) >= 0.0))
		{
			alert("Please, Enter Price.");
			f.prc2.focus();
			return false;
		}
	}

	if (!isBlank(f.item3.value))
	{
		if (isBlank(f.qty3.value) && !(parseInt(f.qty3.value) >= 0))
		{
			alert("Please, Enter Quantity.");
			f.qty3.focus();
			return false;
		}

		if (isBlank(f.prc3.value) && !(parseFloat(f.prc3.value) >= 0.0))
		{
			alert("Please, Enter Price.");
			f.prc3.focus();
			return false;
		}
	}

}

function uf_CheckSpecialOrderForm(f)
{
	if (isBlank(f.ItemCode.value))
	{
		alert("Please, Enter item code.");
		f.ItemCode.focus();
		return false;
	}

	if (isBlank(f.Name.value))
	{
		alert("Please, Enter your name.");
		f.Name.focus();
		return false;
	}

    if (isBlank(f.Email.value))
    {
        alert("Please, Enter your email address.");
        f.Email.focus();
        return false;
    }

	if (!checkMail(f.Email.value))
	{
        alert("Your email address is not valid.");
        f.Email.focus();
        return false;
	}

    if (isBlank(f.Phone.value))
    {
        alert("Please, Enter phone number.");
        f.Phone.focus();
        return false;
    }

}

function checkMail(eml)
{
    if (isSpecialChar(eml)) return false;

    comIndex=eml.indexOf(",");
    aIndex=eml.indexOf("@");
    dotIndex=eml.indexOf(".", aIndex);
    len=eml.length;

    if (len==0)
    	return true;

    else if (comIndex=="-1" && aIndex > 1 && dotIndex > 3 && aIndex < (dotIndex-1))
    {
        return true;
    }
    else
    {
        return false;
    }
    return false;
}

function isSpecialChar(str)
{
    len= str.length;
    for(i=0; i<len; i++)
    {
    	if (str.charAt(i) == "'" || str.charAt(i) == "%" ||
    		str.charAt(i) == "\"" || str.charAt(i) == "&" ||
    		str.charAt(i) == "," )
    	{
            // alert("You can't use special charecter \", ', %, &, etc.");
            return true;
        }
    }

    return false;
}

function isBlank(str)
{
	if (str == "" || str == null) return true;

	for (i=0; i<str.length; i++)
	{
		if (str.charAt(i) != " " && str.charAt(i) != "\n" && str.charAt(i) != "\t" && str.charAt(i) != "\r")
		{
			return false;
		}
		i++;
	}

	return true;
}
