
function textarea_charcount(textarea_field, charcount_field, maxlen) {
var str;
    if (textarea_field.value.length > maxlen){
        str = textarea_field.value.substr(0,maxlen);
        textarea_field.value = str;
    }
    charcount_field.value = maxlen - textarea_field.value.length;
}


function get_address_book_recipient(form) {

var id = form.address_book.value;
    if (id == "none"){
        form.delivery_company.value = "";
        form.delivery_name.value = "";
        form.delivery_address1.value = "";
        form.delivery_address2.value = "";
        form.delivery_city.value = "";
        form.delivery_area.value = "";
        form.delivery_zip_code.value = "";
        form.delivery_phone.value = "";
        form.delivery_instructions.value = "";
        form.delivery_is_save_address.checked = true;
    }
    else{
    
        form.delivery_company.value = eval("form.contact_company"+id+".value");
        form.delivery_name.value = eval("form.contact_name"+id+".value");
        form.delivery_address1.value = eval("form.contact_address1"+id+".value");
        form.delivery_address2.value = eval("form.contact_address2"+id+".value");
        form.delivery_city.value = eval("form.contact_city"+id+".value");
        form.delivery_area.value = eval("form.contact_area"+id+".value");
        form.delivery_zip_code.value = eval("form.contact_zip_code"+id+".value");
        form.delivery_phone.value = eval("form.contact_phone"+id+".value");
        form.delivery_instructions.value = eval("form.contact_delivery_instructions"+id+".value");
        form.delivery_is_save_address.checked = false;
    }

}


function confirm_selectballoon(form) {
	
	if (form.balloon_qty.value > 0)
	    if (form.balloon_id.value > 1)
		    return true;
		else{
		    alert("Please select a balloon type");
		    document.addtocart_form.balloon_id.focus();
		    return false;
		}
    
	if (form.balloon_id.value > 1)
	    if (form.balloon_qty.value > 0)
		    return true;
		else{
		    alert("Please select balloons quanity");
		    document.addtocart_form.balloon_qty.focus();
		    return false;
		}

}


function confirm_msgbox(temp) {
	if (confirm (temp))
		return true;
	return false;
}

function confirm_selectcolor(form) {
	if (form.color_id.value.length > 0)
		return true;
	else{
	    alert("Please select color");
	    return false;
	}
}


/*******************************************************************/

function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine) {
     
	var strTemp = "";
	var strLineCounter = 0;
	var strCharCounter = 0;
	
	for (var i = 0; i < theField.value.length; i++) {
		var strChar = theField.value.substring(i, i + 1);
		if (strChar == '\n') {
			strTemp += strChar;
			strCharCounter = 1;
			strLineCounter += 1;
		}
		else if (strCharCounter == maxPerLine) {
			strTemp += '\n' + strChar;
			strCharCounter = 1;
			strLineCounter += 1;
		}
		else {
			strTemp += strChar;
			strCharCounter ++;
		}
	}
     
	theCharCounter.value = maxChars - strTemp.length;
	theLineCounter.value = maxLines - strLineCounter;
}


function winPopUp(url,width,height) {
     
	var url = url;
	var width = width;
	var height = height;
	var winleft = (screen.width - width) / 2;
	var wintop = (screen.height - height) / 2;
	var winprops = 'height='+height+',width='+width+',top='+wintop+',left='+winleft+',scrollbars=no';
	var win = window.open(url, 'win', winprops);
	return false;
}

    	
function deluxePopUp() {
     
	var url = "popups/deluxe_popup.html";
	var width = 330;
	var height = 350;
	var winleft = 0;//(screen.width - width) / 2;
	var wintop = 0;//(screen.height - height) / 2;
	var winprops = 'height='+height+',width='+width+',top='+wintop+',left='+winleft+',scrollbars=no';
	var win = window.open(url, 'win', winprops);
}
    
	function premiumPopUp() {
     
	var url = "popups/premium_popup.html";
	var width = 400;
	var height = 400;
	var winleft = 0;//(screen.width - width) / 2;
	var wintop = 0;//(screen.height - height) / 2;
	var winprops = 'height='+height+',width='+width+',top='+wintop+',left='+winleft+',scrollbars=no';
	var win = window.open(url, 'win', winprops);
}



	function validate_search_keyword(form) {

    if (form.keyword.value.length > 0)
        return true;
    else{
        alert("Please enter search keyword");
        form.keyword.focus();
        return false;
    }
}
/******************************************************************/