function validate_dealer_payment_info_form()
{if(document.getElementById('cc_holder_name').value.search(/\S/)==-1)
{alert("Please enter credit card holder's name.");document.getElementById('cc_holder_name').focus();return false;}
if(document.getElementById('cc_type').value.search(/\S/)==-1)
{alert('Please select your credit card type.');document.getElementById('cc_type').focus();return false;}
if(document.getElementById('cc_no').value.search(/\S/)==-1)
{alert('Please enter your credit card no.');document.getElementById('cc_no').focus();return false;}
if(document.getElementById('cc_exdate_month').value.search(/\S/)==-1)
{alert('Please select your credit card expiration month.');document.getElementById('cc_exdate_month').focus();return false;}
if(document.getElementById('cc_exdate_year').value.search(/\S/)==-1)
{alert('Please select your credit card expiration year.');document.getElementById('cc_exdate_year').focus();return false;}
if(document.getElementById('cc_cvv2').value.search(/\S/)==-1)
{alert('Please enter your credit card verification value .');document.getElementById('cc_cvv2').focus();return false;}
return true;}
function gen_state(value)
{new Ajax.Updater('neighborhood','/checkouts/change_city/'+value,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize('b_country_code'),requestHeaders:['X-Update','neighborhood']});}
function gen_state_2(value)
{new Ajax.Updater('neighborhood_2','/checkouts/change_city_2/'+value,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize('s_country_code'),requestHeaders:['X-Update','neighborhood_2']});}
function validate_dealer_signup_form()
{if(document.getElementById('dealer_company').value.search(/\S/)==-1)
{alert('Please enter your company name.');document.getElementById('dealer_company').focus();return false;}
if(document.getElementById('first_name').value.search(/\S/)==-1)
{alert('Please enter your first name.');document.getElementById('first_name').focus();return false;}
if(document.getElementById('last_name').value.search(/\S/)==-1)
{alert('Please enter your last name.');document.getElementById('last_name').focus();return false;}
if(document.getElementById('dealer_comp_email').value.search(/\S/)==-1)
{alert('Please enter your email address.');document.getElementById('dealer_comp_email').focus();return false;}
if(!document.getElementById('dealer_comp_email').value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
{alert("Please enter a proper email address");document.getElementById('dealer_comp_email').focus();return false;}
if(document.getElementById('dealer_comp_ph').value.search(/\S/)==-1)
{alert('Please enter your phone no.');document.getElementById('dealer_comp_ph').focus();return false;}
else
{var ret_value=ParseUSNumber(document.getElementById('dealer_comp_ph').value);if(!ret_value)
{document.getElementById('dealer_comp_ph').focus();return false;}}
if(document.getElementById('b_address_1').value.search(/\S/)==-1)
{alert('Please enter your billing address.');document.getElementById('b_address_1').focus();return false;}
if(document.getElementById('b_city').value.search(/\S/)==-1)
{alert('Please enter your billing city.');document.getElementById('b_city').focus();return false;}
if(document.getElementById('b_state_code').value.search(/\S/)==-1)
{alert('Please enter your billing state.');document.getElementById('b_state_code').focus();return false;}
if(document.getElementById('b_country_code').value.search(/\S/)==-1)
{alert('Please enter your billing country.');document.getElementById('b_country_code').focus();return false;}
if(document.getElementById('b_zip').value.search(/\S/)==-1)
{alert('Please enter your billing zip.');document.getElementById('b_zip').focus();return false;}
else
{if(document.getElementById('b_country_code').value=='US')
{var ret_value_zip=validateZIP(document.getElementById('b_zip').value);if(!ret_value_zip)
{document.getElementById('b_zip').focus();return false;}}
else if(isNaN(document.getElementById('b_zip').value))
{alert('Please enter valid billing zip.');document.getElementById('b_zip').focus();return false;}}
if(document.getElementById('s_address_1').value.search(/\S/)==-1)
{alert('Please enter your shipping address.');document.getElementById('s_address_1').focus();return false;}
if(document.getElementById('s_city').value.search(/\S/)==-1)
{alert('Please enter your shipping city.');document.getElementById('s_city').focus();return false;}
if(document.getElementById('s_state_code').value.search(/\S/)==-1)
{alert('Please enter your shipping state.');document.getElementById('s_state_code').focus();return false;}
if(document.getElementById('s_country_code').value.search(/\S/)==-1)
{alert('Please enter your shipping country.');document.getElementById('s_country_code').focus();return false;}
if(document.getElementById('s_zip').value.search(/\S/)==-1)
{alert('Please enter your shipping zip.');document.getElementById('s_zip').focus();return false;}
else
{if(document.getElementById('s_country_code').value=='US')
{var ret_value_zip=validateZIP(document.getElementById('s_zip').value);if(!ret_value_zip)
{document.getElementById('s_zip').focus();return false;}}
else if(isNaN(document.getElementById('s_zip').value))
{alert('Please enter valid shipping zip.');document.getElementById('s_zip').focus();return false;}}
return true;}
function ParseUSNumber(PhoneNumberInitialString)
{var FmtStr="";var index=0;var LimitCheck;var bool=false;LimitCheck=PhoneNumberInitialString.length;while(index!=LimitCheck)
{if(isNaN(parseInt(PhoneNumberInitialString.charAt(index))))
{}
else
{FmtStr=FmtStr+PhoneNumberInitialString.charAt(index);}
index=index+1;}
if(FmtStr.length==10)
{FmtStr=FmtStr.substring(0,3)+"-"+FmtStr.substring(3,6)+"-"+FmtStr.substring(6,10);document.getElementById('dealer_comp_ph').value=FmtStr;bool=true;}
else
{FmtStr=PhoneNumberInitialString;alert("United States phone numbers must have exactly ten digits.Ex: 714-881-3325");}
return bool;}
function validateZIP(field){var valid="0123456789-";var hyphencount=0;if(field.length!=5&&field.length!=10){alert("Please enter your 5 digit or 5 digit+4 zip code.");return false;}
for(var i=0;i<field.length;i++){temp=""+field.substring(i,i+1);if(temp=="-")hyphencount++;if(valid.indexOf(temp)=="-1"){alert("Invalid characters in your zip code.  Please try again.");return false;}
if((hyphencount>1)||((field.length==10)&&""+field.charAt(5)!="-")){alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");return false;}}
return true;}
function validate_merchant_contact_form()
{if(document.getElementById('first_name').value.search(/\S/)==-1)
{alert('Please enter your first name.');document.getElementById('first_name').focus();return false;}
if(document.getElementById('last_name').value.search(/\S/)==-1)
{alert('Please enter your last name.');document.getElementById('last_name').focus();return false;}
if(document.getElementById('email').value.search(/\S/)==-1)
{alert('Please enter your email address.');document.getElementById('email').focus();return false;}
if(!document.getElementById('email').value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
{alert("Please enter a proper email address");document.getElementById('email').focus();return false;}
if(document.getElementById('phone')!=null){if(document.getElementById('phone').value.search(/\S/)==-1)
{alert('Please enter your phone number.');document.getElementById('phone').focus();return false;}}
return true;}
function text_format(text_flag)
{switch(text_flag)
{case'0':if(document.getElementById('email').value=='Enter your email address')
{document.getElementById('email').value='';}
break;case'1':if(document.getElementById('email').value=='')
{document.getElementById('email').value='Enter your email address';}
break;}}
function srch_key_format(text_flag)
{switch(text_flag)
{case'0':if(document.getElementById('srch_key').value=='search by keywords....')
{document.getElementById('srch_key').value='';}
break;case'1':if(document.getElementById('srch_key').value=='')
{document.getElementById('srch_key').value='search by keywords....';}
break;}}
function chk_srch()
{if(document.getElementById('srch_key').value=='keywords....')
{alert('Must provide a search keyword.');document.getElementById('srch_key').focus();return false;}
return true;}
function zip_srch(val)
{switch(val)
{case'0':document.getElementById('srch_zip').style.display='none';break;case'1':document.getElementById('srch_zip').style.display='block';break;}}
function zip_form()
{if(document.getElementById('srch_zip_code').value.search(/\S/)==-1)
{alert('You must enter a zip code to search.');document.getElementById('srch_zip_code').focus();return false;}
document.srch_form.submit();return true;}
function zip_form_dup()
{if(document.getElementById('srch_zip_code_dup').value.search(/\S/)==-1)
{alert('You must enter a zip code to search.');document.getElementById('srch_zip_code_dup').focus();return false;}
document.srch_form_dup.submit();return true;}
function chk_form()
{if(document.getElementById('email').value.search(/\S/)==-1)
{alert('You must enter your email address for signing up.');document.getElementById('email').focus();return false;}
if(document.getElementById('email').value=='Enter your email address')
{alert('You must enter your email address for signing up.');document.getElementById('email').focus();return false;}
if(!document.getElementById('email').value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
{alert("Please enter a proper email id");document.getElementById('email').focus();return false;}
return true;}
function chk_submit()
{if(document.getElementById('section_id').value=='A')
{alert('This section is still with the administrator. You cannot change it\'s access.');return false;}
return true;}
function change_tab(id)
{var featureObj=document.getElementById('F_div');var addInfoObj=document.getElementById('A_div');var shippingObj=document.getElementById('S_div');var tabObj=document.getElementById('tab');var tab_inner='';if(id=='F')
{tab_inner+="<li><a href='javascript:void(0)' class='select' id='F' onclick='javascript: change_tab(this.id);'>Features</a></li>";tab_inner+="<li><a href='javascript:void(0)' id='A' onclick='javascript: change_tab(this.id);'>Additional Info</a></li>";tab_inner+="<li><a href='javascript:void(0)' id='S' onclick='javascript: change_tab(this.id);'>Shipping Info</a></li>";featureObj.style.display='block';addInfoObj.style.display='none';shippingObj.style.display='none';}
else if(id=='A')
{tab_inner+="<li><a href='javascript:void(0)' id='F' onclick='javascript: change_tab(this.id);'>Features</a></li>";tab_inner+="<li><a href='javascript:void(0)' class='select' id='A' onclick='javascript: change_tab(this.id);'>Additional Info</a></li>";tab_inner+="<li><a href='javascript:void(0)' id='S' onclick='javascript: change_tab(this.id);'>Shipping Info</a></li>";featureObj.style.display='none';addInfoObj.style.display='block';shippingObj.style.display='none';}
else if(id=='S')
{tab_inner+="<li><a href='javascript:void(0)' id='F' onclick='javascript: change_tab(this.id);'>Features</a></li>";tab_inner+="<li><a href='javascript:void(0)' id='A' onclick='javascript: change_tab(this.id);'>Additional Info</a></li>";tab_inner+="<li><a href='javascript:void(0)' class='select' id='S' onclick='javascript: change_tab(this.id);'>Shipping Info</a></li>";featureObj.style.display='none';addInfoObj.style.display='none';shippingObj.style.display='block';}
tabObj.innerHTML=tab_inner;}
function sign_up_text(fieldID,text_flag)
{var fieldObj=document.getElementById(fieldID);switch(text_flag)
{case'0':if(fieldObj.value=='Enter your email address')
{fieldObj.value='';}
break;case'1':if(fieldObj.value=='')
{fieldObj.value='Enter your email address';}
break;}}
function trim(str,chars){return ltrim(rtrim(str,chars),chars);}
function ltrim(str,chars){chars=chars||"\\s";return str.replace(new RegExp("^["+chars+"]+","g"),"");}
function rtrim(str,chars){chars=chars||"\\s";return str.replace(new RegExp("["+chars+"]+$","g"),"");}
function gen_state_home(value,id,onchng_id,chng_id,hid)
{new Ajax.Updater(chng_id,'/checkouts/new_change_city/'+value+'/'+id+'/'+hid,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize(onchng_id),requestHeaders:['X-Update',chng_id]});}
function scroll_deal(id,way,onchng_id)
{var re_track=false;if(id=='')
{id=document.getElementById('first_id').value;re_track=true;}
go_url='/homes/scroll_deals/'+id+'/'+way;new Ajax.Updater("scroll_div",go_url,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize(onchng_id),onLoading:function(){loading_in();},onLoaded:function(){loading_out();Behaviour.start();call_demo();},requestHeaders:['X-Update','scroll_div']});if(re_track)
{rotate_scroll();}}
function loading_in()
{document.getElementById('loading_div').style.display='block';}
function loading_out()
{document.getElementById('loading_div').style.display='none';}
function pause_scroll_deal()
{rotate_flag=false;}
jQuery(function()
{jQuery("#alpha_link").click(function(event){event.preventDefault();jQuery("#alpha_characters").slideToggle();if(document.getElementById("alpha_hid").value==0)
{document.getElementById("alpha_hid").value=1;document.getElementById("imageDiv").innerHTML="<img src='http://www.clickedeals.com/img/up-arrow.png' width='13' height='7' title='Alpha Search Collapse' />";}
else
{document.getElementById("alpha_hid").value=0;document.getElementById("imageDiv").innerHTML="<img src='http://www.clickedeals.com/img/down-arrow.png' width='13' height='7' title='Alpha Search Expand' />";}});});function search_alpha_business(alpha)
{go_url='/homes/search_alpha_business/'+alpha;new Ajax.Updater("showcase_div",go_url,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize('alpha_characters'),onLoading:function(){document.getElementById('loading_div_new').style.display='block';},onLoaded:function(){document.getElementById('loading_div_new').style.display='none';},requestHeaders:['X-Update','showcase_div']});}
function search_deal()
{if(document.getElementById('srch_by_deal').value.search(/\S/)==-1)
{alert('You must provide the title of the deal to search.');document.getElementById('srch_by_deal').focus();return false;}
else
{var deal_title=document.getElementById('srch_by_deal').value;go_url='/homes/search_by_deals/'+deal_title;new Ajax.Updater("showcase_div",go_url,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize('showcase_div'),onLoading:function(){document.getElementById('loading_div_new').style.display='block';},onLoaded:function(){document.getElementById('loading_div_new').style.display='none';},requestHeaders:['X-Update','showcase_div']});}
return true;}

function get_pizza_topping(ini,len,global_it)
{
    var chk_flag = false;
    var chked = '';
    var tmp_global_it = global_it-(len+1);
    
    for(i=0;i<=len;i++)
    {
        if(document.getElementById('size_'+tmp_global_it+'_'+i).checked==true)
        {
            chk_flag = true;
            chked = 'size_'+tmp_global_it+'_'+i;
        }
        tmp_global_it++;
    }
    if(!chk_flag)
    {
        alert('Please select a Pizza Size to continue.');
    }
    else
    {
        document.getElementById('loading_image'+ini).style.display = 'inline';
        jQuery.ajax({
	  type: "POST",
	  url: document.getElementById('full_web_url').value+"/get_toppings/"+document.getElementById(chked).value+'/'+ini+'/'+document.getElementById('open_status').value+'/'+document.getElementById('delv_status').value,
	  success: function(msg){
                    toggle_div('pizza_topping_list_'+ini);document.getElementById('loading_image'+ini).style.display = 'none';
		    jQuery("#pizza_topping_list_"+ini).html(msg);
	    }
	});
        
    }
}

function get_generic_topping(ini,len,global_it,builder_cat_id)
{
    var chk_flag = false;
    var chked = '';
    var tmp_global_it = global_it-(len+1);
    
    for(i=0;i<=len;i++)
    {
        if(document.getElementById('size_'+tmp_global_it+'_'+i).checked==true)
        {
            chk_flag = true;
            chked = 'size_'+tmp_global_it+'_'+i;
        }
        tmp_global_it++;
    }
    if(!chk_flag)
    {
        alert('Please select a Generic Size to continue.');
    }
    else
    {
        document.getElementById('loading_image'+ini).style.display = 'inline';
        jQuery.ajax({
	  type: "POST",
	  url: document.getElementById('full_web_url').value+"/get_generic_toppings/"+document.getElementById(chked).value+'/'+ini+'/'+document.getElementById('open_status').value+'/'+document.getElementById('delv_status').value+'/'+builder_cat_id,
	  success: function(msg){
                    toggle_div('pizza_topping_list_'+ini);document.getElementById('loading_image'+ini).style.display = 'none';
		    jQuery("#pizza_topping_list_"+ini).html(msg);
	    }
	});
        
    }
}

function get_pizza_topping_cpy(divId,len,global_it)
{
    var chk_flag = false;
    var chked = '';
    var tmp_global_it = global_it-(len+1);
    
    for(i=0;i<=len;i++)
    {
        if(document.getElementById('size_'+tmp_global_it+'_'+i).checked==true)
        {
            chk_flag = true;
            chked = 'size_'+tmp_global_it+'_'+i;
        }
        tmp_global_it++;
    }
    if(!chk_flag)
    {
        alert('Please select an Item Size to continue.');
    }
    else
    {
        toggle_div(divId)
    }
}

function get_pizza_topping_new(ini,len,global_it)
{
    var chk_flag = false;
    var chked = '';
    var tmp_global_it = global_it-(len+1);
    
    for(i=0;i<=len;i++)
    {
        if(document.getElementById('size_'+tmp_global_it+'_'+i).checked==true)
        {
            chk_flag = true;
            chked = 'size_'+tmp_global_it+'_'+i;
        }
        tmp_global_it++;
    }
    if(!chk_flag)
    {
        alert('Please select a Pizza Size to continue.');
    }
    else
    {
        document.getElementById('loading_image'+ini).style.display = 'inline';
        jQuery.ajax({
	  type: "POST",
	  url: document.getElementById('full_web_url').value+"/get_toppings_new/"+document.getElementById(chked).value+'/'+ini+'/'+document.getElementById('open_status').value+'/'+document.getElementById('delv_status').value,
	  success: function(msg){
                    toggle_div('pizza_topping_list_'+ini);document.getElementById('loading_image'+ini).style.display = 'none';
		    jQuery("#pizza_topping_list_"+ini).html(msg);
	    }
	});
        
    }
}

function close_size_div(i,k,l)
{
    for(it=0;it<parseInt(l);it++)
    {
        if(it!=k)
        {
            if(document.getElementById('size_div_'+i+'_'+it)!=null)
            {
                document.getElementById('size_div_'+i+'_'+it).style.display = 'none';
            }
        }
    }
}

function add_BP_to_order(i,len,size_id)
{
    var price = 0;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    
    for(it=0;it<len;it++)
    {
        for(jit=1;jit<=3;jit++)
        {
            if(document.getElementById('topping_id_'+i+'_'+it+'_'+jit).checked)
            {
                id_str = document.getElementById('topping_id_'+i+'_'+it+'_'+jit).value;
                id_arr = id_str.split('__');
                price_arr[price_chk++] = id_arr[0]+'__'+id_arr[1];
                switch(id_arr[0])
                {
                    case 'F' : extra_txt = 'Full - ';break;
                    case 'L' : extra_txt = 'Left Half - ';break;
                    case 'R' : extra_txt = 'Right Half - ';break;
                }
                topping_id_str += id_arr[2]+'--'+extra_txt+',';
                topping_chk_flag = true;
            }
        }
    }
    
    if(price_arr.length>0)
    {
        if(price_chk>1)
        {
            for(it=0;it<price_chk;it++)
            {
                tmp_price = 0;
                tmp = price_arr[it].split('__');
                if(tmp[0]=='F')
                {
                    tmp_price = parseFloat(tmp[1]);
                }
                else
                {
                    tmp_price = parseFloat(tmp[1])/2;
                }
                price += tmp_price;
            }
        }
        else if(price_chk<=1)
        {
            tmp = price_arr[0].split('__');
            price = tmp[1];
        }
    }
    else
    {
        price = 0.00;
    }
    
    pizza_type_id = document.getElementById('hid_prod_'+i).value;
    addToCartUrl = document.getElementById('add_to_cart_url').value;
    quantity = document.getElementById('unit_'+i).value;
    
    if(parseInt(quantity)<=0 || isNaN(quantity))
    {
        alert('Invalid value of quantity to add in cart');
        document.getElementById('unit_'+i).focus();
        return false;
    }
    if(!topping_chk_flag)
    {
        ch = confirm('Do you wish to continue without adding any toppings for your pizza?')
        if(!ch)
        {
            return false;
        }
    }
    
    var spcl_inst = document.getElementById('spcl_inst'+i).value;
    spcl_inst = Base64.encode(spcl_inst);
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    
    url = addToCartUrl+price+'/'+size_id+'/'+pizza_type_id+'/'+quantity+'/'+topping_id_str+'/'+spcl_inst;
    //alert(url);return false;
    location.href = url;
}

function add_GB_to_order(i,len,size_id)
{
    var price = 0;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    
    for(it=0;it<len;it++)
    {
        for(jit=1;jit<=2;jit++)
        {
            if(document.getElementById('topping_id_'+i+'_'+it+'_'+jit).checked)
            {
                id_str = document.getElementById('topping_id_'+i+'_'+it+'_'+jit).value;
                id_arr = id_str.split('__');
                price_arr[price_chk++] = id_arr[0]+'__'+id_arr[1];
                switch(id_arr[0])
                {
                    case 'Y' : extra_txt = 'Yes - ';break;
                    case 'N' : extra_txt = 'No - ';break;
                }
                topping_id_str += id_arr[2]+'--'+extra_txt+',';
                topping_chk_flag = true;
            }
        }
    }
    
    if(price_arr.length>0)
    {
        if(price_chk>1)
        {
            for(it=0;it<price_chk;it++)
            {
                tmp_price = 0;
                tmp = price_arr[it].split('__');
                if(tmp[0]=='Y')
                {
                    tmp_price = parseFloat(tmp[1]);
                }
                price += tmp_price;
            }
        }
        else if(price_chk<=1)
        {
            tmp = price_arr[0].split('__');
            price = tmp[1];
        }
    }
    else
    {
        price = 0.00;
    }
    
    generic_type_id = document.getElementById('hid_prod_'+i).value;
    addToCartUrl = document.getElementById('add_to_cart_url').value;
    quantity = document.getElementById('unit_'+i).value;
    
    if(parseInt(quantity)<=0 || isNaN(quantity))
    {
        alert('Invalid value of quantity to add in cart');
        document.getElementById('unit_'+i).focus();
        return false;
    }
    if(!topping_chk_flag)
    {
        ch = confirm('Do you wish to continue without adding any toppings for your item?')
        if(!ch)
        {
            return false;
        }
    }
    
    var spcl_inst = document.getElementById('spcl_inst'+i).value;
    spcl_inst = Base64.encode(spcl_inst);
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    
    url = addToCartUrl+price+'/'+size_id+'/'+generic_type_id+'/'+quantity+'/'+topping_id_str+'/'+spcl_inst;
    //alert(url);return false;
    location.href = url;
}

function add_N_to_order_cpy(i,len,size_id,l1,pid,l2,global_it)
{
    var price = 0;
    var toppingPrice = 0;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    
    var topping_cnt = 0;
    var free_topping = document.getElementById('free_toppings'+i).value;
    var topping_multiplier = document.getElementById('toppings_multiplier'+i).value;
    
    for(it=0;it<len;it++)
    {
        for(jit=1;jit<=3;jit++)
        {
            if(document.getElementById('topping_id_'+i+'_'+it+'_'+jit).checked)
            {
                id_str = document.getElementById('topping_id_'+i+'_'+it+'_'+jit).value;
                id_arr = id_str.split('__');
                price_arr[price_chk++] = id_arr[0]+'__'+id_arr[1];
                switch(id_arr[0])
                {
                    case 'F' : extra_txt = 'Full - ';break;
                    case 'L' : extra_txt = 'Left Half - ';break;
                    case 'R' : extra_txt = 'Right Half - ';break;
                }
                topping_id_str += id_arr[2]+'--'+extra_txt+',';
                topping_chk_flag = true;
            }
        }
    }
    
    if(price_arr.length>0)
    {
        if(price_chk>1)
        {
            for(it=0;it<price_chk;it++)
            {
                topping_cnt++;
                tmp_price = 0;
                tmp = price_arr[it].split('__');
                if(tmp[0]=='F')
                {
                    tmp_price = parseFloat(tmp[1]);
                }
                else
                {
                    tmp_price = parseFloat(tmp[1])/2;
                }
                if(topping_cnt>free_topping)
                {
                    price += tmp_price;
                }
            }
        }
        else if(price_chk<=1)
        {
            tmp = price_arr[0].split('__');
            if(topping_cnt>free_topping)
            {
                price = tmp[1];
            }
        }
    }
    else
    {
        price = 0.00;
    }
    price *= topping_multiplier;
    
    if(!topping_chk_flag)
    {
        ch = confirm('Do you wish to continue without adding any toppings for your item?')
        if(!ch)
        {
            return false;
        }
    }
    
    var spcl_inst = document.getElementById('spcl_inst'+i).value;
    spcl_inst = Base64.encode(spcl_inst);
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    toppingIdStr = topping_id_str;
    toppingPrice = price;
    
    /*alert(price);
    return false;*/
    
    //url = addToCartUrl+price+'/'+size_id+'/'+pizza_type_id+'/'+quantity+'/'+topping_id_str;alert(url);
    //return false;
    
    var price = 0.00;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    var pr_details_id = 0;
    var chk1 = false;
    
    for(it=0;it<=len;it++)
    {
        if(document.getElementById('topping'+i+'_'+it)!=null)
        {
            if(document.getElementById('topping'+i+'_'+it).checked)
            {
                id_str = document.getElementById('topping'+i+'_'+it).value;
                id_arr = id_str.split('__');
                price_arr[price_chk++] = id_arr[1];
                topping_id_str += id_arr[0]+',';
                topping_chk_flag = true;
            }
        }
    }
    
    if(price_arr.length>0)
    {
        for(it=0;it<price_chk;it++)
        {
            price += parseFloat(price_arr[it]);
        }
    }
    else
    {
        price = 0.00;
    }
    
    addToCartUrl = document.getElementById('add_to_cart_url_cpy').value;
    quantity = document.getElementById('unit_'+i).value;
    
    if(parseInt(quantity)<=0 || isNaN(quantity))
    {
        alert('Invalid value of quantity to add in cart');
        document.getElementById('unit_'+i).focus();
        return false;
    }
    if(!topping_chk_flag)
    {
        chk1 = true;
    }
    
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    
    var tmp_global_it = global_it-(l2+1);
    
    for(it=0;it<=l2;it++)
    {
        if(document.getElementById('size_'+tmp_global_it+'_'+it)!=null)
        {
            if(document.getElementById('size_'+tmp_global_it+'_'+it).checked==true)
            {
                pr_details_id = document.getElementById('size_'+tmp_global_it+'_'+it).value;
            }
        }
        tmp_global_it++;
    }
    
    var spcl_inst = document.getElementById('spcl_inst'+i).value;
    spcl_inst = Base64.encode(spcl_inst);
    
    price += toppingPrice;
    price1 = price;
    topping_id_str1 = topping_id_str;
    
    //alert(price1+' : '+topping_id_str1);return false;
    
    var price = 0;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    
    for(it=0;it<=len;it++)
    {
        for(jit=1;jit<=2;jit++)
        {
            if(document.getElementById('topping_yn_'+i+'_'+it+'_'+jit)!=null)
	    {
		if(document.getElementById('topping_yn_'+i+'_'+it+'_'+jit).checked)
		{
		    id_str = document.getElementById('topping_yn_'+i+'_'+it+'_'+jit).value;
		    id_arr = id_str.split('__');
		    price_arr[price_chk++] = id_arr[0]+'__'+id_arr[1];
		    switch(id_arr[0])
		    {
			case 'Y' : extra_txt = 'Yes - ';topping_chk_flag = true;break;
			case 'N' : extra_txt = 'No - ';break;
		    }
		    topping_id_str += id_arr[2]+'--'+extra_txt+',';
		}
	    }
        }
    }
    
    if(price_arr.length>0)
    {
        if(price_chk>1)
        {
            for(it=0;it<price_chk;it++)
            {
                tmp_price = 0;
                tmp = price_arr[it].split('__');
                if(tmp[0]=='Y')
                {
                    tmp_price = parseFloat(tmp[1]);
                }
                price += tmp_price;
            }
        }
        else if(price_chk<=1)
        {
            tmp = price_arr[0].split('__');
            price = tmp[1];
        }
    }
    else
    {
        price = 0.00;
    }
    
    if(!topping_chk_flag && chk1==true)
    {
        ch = confirm('Do you wish to continue without adding any extras for your item?')
        if(!ch)
        {
            return false;
        }
    }
    
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    price += price1;
    
    //url1 = url+'/'+document.getElementById('this_url').value+'/'+price+'/'+pid+'/'+pr_details_id+'/'+quantity+'/'+topping_id_str+'/'+spcl_inst;
    url = addToCartUrl+price+'/'+pid+'/'+pr_details_id+'/'+quantity+'/'+topping_id_str1+'----'+topping_id_str+'/'+toppingIdStr+'/'+spcl_inst;
    //alert(url);return false;
    location.href = url;
}

function chk_spcl_inst(i,len,pr_id,length,global_it,msg)
{
    msg = str_replace('@@@','"',msg);
    if(document.getElementById('spcl_inst'+i).value=='')
    {
        alert(msg);
        document.getElementById('spcl_inst'+i).focus();
        return false;
    }
    else
    {
        add_N_to_order(i,len,pr_id,length,global_it);
    }
}

function chk_spcl_inst_cpy(p1,p2,p3,p4,p5,p6,global_it,p7)
{
    p7 = str_replace('@@@','"',p7);
    if(document.getElementById('spcl_inst'+p1).value=='')
    {
        alert(p7);
        document.getElementById('spcl_inst'+p1).focus();
        return false;
    }
    else
    {
        add_N_to_order_cpy(p1,p2,p3,p4,p5,p6,global_it);
    }
}

function add_N_to_order(i,len,pr_id,length,global_it)
{//alert(i+' : '+len+' : '+pr_id);return false;
    var price = 0.00;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    var pr_details_id = 0;
    var chk1 = false;
    var chk2 = false;
    
    for(it=0;it<=len;it++)
    {
        if(document.getElementById('topping'+i+'_'+it)!=null)
        {
            if(document.getElementById('topping'+i+'_'+it).checked)
            {
                id_str = document.getElementById('topping'+i+'_'+it).value;
                id_arr = id_str.split('__');
                price_arr[price_chk++] = id_arr[1];
                topping_id_str += id_arr[0]+',';
                topping_chk_flag = true;
            }
        }
    }
    
    if(price_arr.length>0)
    {
        for(it=0;it<price_chk;it++)
        {
            price += parseFloat(price_arr[it]);
        }
    }
    else
    {
        price = 0.00;
    }
    
    addToCartUrl = document.getElementById('add_to_cart_url').value;
    quantity = document.getElementById('unit_'+i).value;
    
    if(parseInt(quantity)<=0 || isNaN(quantity))
    {
        alert('Invalid value of quantity to add in cart');
        document.getElementById('unit_'+i).focus();
        return false;
    }
    if(!topping_chk_flag)
    {
	chk1 = true;
    }
    
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    
    var tmp_global_it = global_it-(length+1);
    
    for(it=0;it<=length;it++)
    {
        if(document.getElementById('size_'+tmp_global_it+'_'+it)!=null)
        {
            if(document.getElementById('size_'+tmp_global_it+'_'+it).checked==true)
            {
                pr_details_id = document.getElementById('size_'+tmp_global_it+'_'+it).value;
            }
        }
        tmp_global_it++;
    }
    
    var spcl_inst = document.getElementById('spcl_inst'+i).value;
    spcl_inst = Base64.encode(spcl_inst);
    price1 = price;
    topping_id_str1 = topping_id_str;
    
    url = addToCartUrl+price+'/'+pr_id+'/'+pr_details_id+'/'+quantity+'/'+topping_id_str+'/'+spcl_inst;
    //alert(url);
    
    var price = 0;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    
    for(it=0;it<=len;it++)
    {
        for(jit=1;jit<=2;jit++)
        {
            if(document.getElementById('topping_yn_'+i+'_'+it+'_'+jit)!=null)
	    {
		if(document.getElementById('topping_yn_'+i+'_'+it+'_'+jit).checked)
		{
		    id_str = document.getElementById('topping_yn_'+i+'_'+it+'_'+jit).value;
		    id_arr = id_str.split('__');
		    price_arr[price_chk++] = id_arr[0]+'__'+id_arr[1];
		    switch(id_arr[0])
		    {
			case 'Y' : extra_txt = 'Yes - ';topping_chk_flag = true;break;
			case 'N' : extra_txt = 'No - ';break;
		    }
		    topping_id_str += id_arr[2]+'--'+extra_txt+',';
		}
	    }
        }
    }
    
    if(price_arr.length>0)
    {
        if(price_chk>1)
        {
            for(it=0;it<price_chk;it++)
            {
                tmp_price = 0;
                tmp = price_arr[it].split('__');
                if(tmp[0]=='Y')
                {
                    tmp_price = parseFloat(tmp[1]);
                }
                price += tmp_price;
            }
        }
        else if(price_chk<=1)
        {
            tmp = price_arr[0].split('__');
            price = tmp[1];
        }
    }
    else
    {
        price = 0.00;
    }
    
    if(!topping_chk_flag && chk1==true)
    {
        ch = confirm('Do you wish to continue without adding any extras for your item?')
        if(!ch)
        {
            return false;
        }
    }
    
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    price += price1;
    url = addToCartUrl+price+'/'+pr_id+'/'+pr_details_id+'/'+quantity+'/'+topping_id_str1+'----'+topping_id_str+'/'+spcl_inst;
    //alert(url);return false;
    location.href = url;
}

function add_PO_to_order(i,len,size_id)
{
    var price = 0;
    var price_chk = 0;
    var price_arr = new Array();
    var topping_id_str = '';
    var topping_chk_flag = false;
    
    for(it=0;it<len;it++)
    {
        for(jit=1;jit<=3;jit++)
        {
            if(document.getElementById('topping_id_'+i+'_'+it+'_'+jit).checked)
            {
                id_str = document.getElementById('topping_id_'+i+'_'+it+'_'+jit).value;
                id_arr = id_str.split('__');
                price_arr[price_chk++] = id_arr[0]+'__'+id_arr[1];
                switch(id_arr[0])
                {
                    case 'F' : extra_txt = 'Full - ';break;
                    case 'L' : extra_txt = 'Left Half - ';break;
                    case 'R' : extra_txt = 'Right Half - ';break;
                }
                topping_id_str += id_arr[2]+'--'+extra_txt+',';
                topping_chk_flag = true;
            }
        }
    }
    
    if(price_arr.length>0)
    {
        if(price_chk>1)
        {
            for(it=0;it<price_chk;it++)
            {
                tmp_price = 0;
                tmp = price_arr[it].split('__');
                if(tmp[0]=='F')
                {
                    tmp_price = parseFloat(tmp[1]);
                }
                else
                {
                    tmp_price = parseFloat(tmp[1])/2;
                }
                price += tmp_price;
            }
        }
        else if(price_chk<=1)
        {
            tmp = price_arr[0].split('__');
            price = tmp[1];
        }
    }
    else
    {
        price = 0.00;
    }
    
    pizza_type_id = document.getElementById('hid_prod_'+i).value;
    addToCartUrl = document.getElementById('add_to_cart_url').value;
    quantity = document.getElementById('unit_'+i).value;
    
    if(parseInt(quantity)<=0 || isNaN(quantity))
    {
        alert('Invalid value of quantity to add in cart');
        document.getElementById('unit_'+i).focus();
        return false;
    }
    if(!topping_chk_flag)
    {
        ch = confirm('Do you wish to continue without adding any toppings for your pizza?')
        if(!ch)
        {
            return false;
        }
    }
    
    if(topping_id_str=='')
    {
        topping_id_str = null;
    }
    
    var spcl_inst = document.getElementById('spcl_inst'+i).value;
    spcl_inst = Base64.encode(spcl_inst);
    
    url = addToCartUrl+price+'/'+size_id+'/'+pizza_type_id+'/'+quantity+'/'+topping_id_str+'/'+spcl_inst;
    //alert(url);return false;
    location.href = url;
}

function remove_from_cart(i,option)
{
    ch = confirm('Are you sure you want to delete this item from the cart?');
    if(ch)
    {
        location.href = document.getElementById('remove_from_cart_url').value+'/'+i+'/'+option;
    }
}

function toggle_cart_div(divId,option)
{
    switch(option)
    {
        case 'show' :
            document.getElementById('txt'+divId).style.display = 'inline';
            document.getElementById('label'+divId).style.display = 'none';
            break;
        case 'hide' :
            document.getElementById('txt'+divId).style.display = 'none';
            document.getElementById('label'+divId).style.display = 'inline';
            break;
    }
}

function edit_cart(length)
{
    var quantity = '';
    var ids = '';
    var chk_flag = false;
    
    for(i=0;i<length;i++)
    {
        if(document.getElementById('txt'+i).style.display!='none')
        {
            tmp_qnt = document.getElementById('cart_unit_'+i).value;
            if(parseInt(tmp_qnt)<=0 || isNaN(tmp_qnt) || tmp_qnt=='')
            {
                alert('Invalid value of quantity in cart');
                document.getElementById('cart_unit_'+i).focus();
                return false;
            }
            else
            {
                quantity += tmp_qnt+',';
                ids += document.getElementById('type_id_'+i).value+',';
                chk_flag = true;
            }
        }
    }
    
    if(!chk_flag)
    {
        alert('Please specify the changed quantity of at least one item in your cart to proceed.');
        return false;
    }
    else
    {
        location.href = document.getElementById('edit_cart_url').value+'/'+quantity+'/'+ids;
    }
}

function edit_cart_new(length)
{
    var quantity = '';
    var ids = '';
    var chk_flag = false;
    
    for(i=0;i<length;i++)
    {
        tmp_qnt = parseInt(document.getElementById('cart_unit_'+i).value);
        if(parseInt(tmp_qnt)<=0 || isNaN(tmp_qnt) || tmp_qnt=='')
        {
            alert('Invalid value of quantity in cart');
            document.getElementById('cart_unit_'+i).focus();
            return false;
        }
        else
        {
            quantity += tmp_qnt+',';
            ids += document.getElementById('type_id_'+i).value+',';
            chk_flag = true;
        }
    }
    
    if(!chk_flag)
    {
        alert('Please specify the changed quantity of at least one item in your cart to proceed.');
        return false;
    }
    else
    {
        location.href = document.getElementById('edit_cart_url').value+'/'+quantity+'/'+ids;
    }
}

Number.prototype.isFloat =
      function() {
        return /\./.test(this.toString());
      };

function show_notice(option,img_url,i)
{
    jQuery("#lightbox"+i).fadeIn(300);
    jQuery("#lb_content"+i).html('<img src="'+img_url+'loading_new.gif" height="20"  width="20" alt="loading..." title="loading..." style="text-align: center; padding-left: 180px; padding-top: 10px;" />');
    
    jQuery.ajax({
              type: "POST",
              url: document.getElementById('full_web_url').value+'/light_error_view/'+option,
              success: function(msg)
              {
                    jQuery("#lb_content"+i).html(msg);
                }
            });
}

function check_all()
{
    var chk_var = false;
    if(document.getElementById('chk_all').checked)
    {
        chk_var = true;
    }
    len = document.getElementById('hid_len').value;
    for(i=0;i<len;i++)
    {
        document.getElementById('item_'+i).checked = chk_var;
    }
}

function remove_selected_from_cart()
{
    var remove_ids = '';
    var chk_flag = false;
    len = document.getElementById('hid_len').value;
    for(i=0;i<len;i++)
    {
        if(document.getElementById('item_'+i).checked)
        {
            remove_ids += document.getElementById('item_'+i).value+',';
            chk_flag = true;
        }
    }
    
    if(!chk_flag)
    {
        alert('Please select item(s) from your cart to remove them.');
        return false;
    }
    ch = confirm('Are you sure you want to delete the selected item(s) from the cart?');
    if(ch)
    {//alert(document.getElementById('remove_from_cart_url').value+'/'+remove_ids);return false;
        location.href = document.getElementById('remove_from_cart_url').value+remove_ids;
    }
}

function check_signup_form()
{
    //alert(document.getElementById('hid1').value);return false;
    if(document.getElementById('f_name')!=null)
    {
        if (trim(document.getElementById('f_name').value) == '')
        {
                alert ('Please enter first name.');
                document.getElementById('f_name').focus();
                return false;
        }
    }
    if(document.getElementById('l_name')!=null)
    {
        if (trim(document.getElementById('l_name').value) == '')
        {
                alert ('Please enter last name.');
                document.getElementById('l_name').focus();
                return false;
        }
    }
    if(document.getElementById('address')!=null)
    {
        if (trim(document.getElementById('address').value) == '')
        {
                alert ('Please enter address.');
                document.getElementById('address').focus();
                return false;
        }
    }
    if(document.getElementById('city')!=null)
    {
        if (trim(document.getElementById('city').value) == '')
        {
                alert ('Please enter city.');
                document.getElementById('city').focus();
                return false;
        }
    }
    if(document.getElementById('country_id')!=null)
    {
        if (trim(document.getElementById('country_id').value) == '')
        {
                alert ('Please select country.');
                document.getElementById('country_id').focus();
                return false;
        }
    }
    if(document.getElementById('state')!=null)
    {
        if (trim(document.getElementById('state').value) == '')
        {
                alert ('Please select a state.');
                document.getElementById('state').focus();
                return false;
        }
    }
    if(document.getElementById('zip')!=null)
    {
        if (trim(document.getElementById('zip').value) == '')
        {
                alert ('Please enter zip.');
                document.getElementById('zip').focus();
                return false;
        }
    }
    if(document.getElementById('email')!=null)
    {
        if (trim(document.getElementById('email').value) == '')
        {
                alert ('Please enter email1.');
                document.getElementById('email').focus();
                return false;
        }
        else if(!document.getElementById('email').value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
        {
                alert("Please enter a proper email address");
                document.getElementById('email').focus();
                return false;
        }
    }
    if (trim(document.getElementById('b_f_name').value) == '')
    {
            alert ('Please enter billing first name.');
            document.getElementById('b_f_name').focus();
            return false;
    }
    else if (trim(document.getElementById('b_l_name').value) == '')
    {
            alert ('Please enter billing last name.');
            document.getElementById('b_l_name').focus();
            return false;
    }
    else if (trim(document.getElementById('b_address').value) == '')
    {
            alert ('Please enter billing address.');
            document.getElementById('b_address').focus();
            return false;
    }
    else if (trim(document.getElementById('b_city').value) == '')
    {
            alert ('Please enter billing city.');
            document.getElementById('b_city').focus();
            return false;
    }
    else if (trim(document.getElementById('b_country_id').value) == '')
    {
            alert ('Please select billing country.');
            document.getElementById('b_country_id').focus();
            return false;
    }
    else if (trim(document.getElementById('hid1').value) == '')
    {
            alert ('Please select a billing state.');
            document.getElementById('hid1').focus();
            return false;
    }
    else if (trim(document.getElementById('b_zip').value) == '')
    {
            alert ('Please enter billing zip.');
            document.getElementById('b_zip').focus();
            return false;
    }
    else if (trim(document.getElementById('s_f_name').value) == '')
    {
            alert ('Please enter shipping first name.');
            document.getElementById('s_f_name').focus();
            return false;
    }
    else if (trim(document.getElementById('s_l_name').value) == '')
    {
            alert ('Please select shipping last name.');
            document.getElementById('s_l_name').focus();
            return false;
    }
    else if (trim(document.getElementById('s_address').value) == '')
    {
            alert ('Please enter shipping address.');
            document.getElementById('s_address').focus();
            return false;
    }
    else if (trim(document.getElementById('s_city').value) == '')
    {
            alert ('Please enter shipping city.');
            document.getElementById('s_city').focus();
            return false;
    }
    else if (trim(document.getElementById('s_country_id').value) == '')
    {
            alert ('Please select shipping country.');
            document.getElementById('s_country_id').focus();
            return false;
    }
    else if (trim(document.getElementById('hid2').value) == '')
    {
            alert ('Please select a shipping state.');
            document.getElementById('hid2').focus();
            return false;
    }
    else if (trim(document.getElementById('s_zip').value) == '')
    {
            alert ('Please enter shipping zip.');
            document.getElementById('s_zip').focus();
            return false;
    }
    else if (document.getElementById('isagreed').checked == false)
    {
            alert ('Please check terms & comdition checkbox.');
            document.getElementById('isagreed').focus();
            return false;
    }
    else if (trim(document.getElementById('username').value) == '')
    {
            alert ('Please enter username.');
            document.getElementById('username').focus();
            return false;
    }
    else if (trim(document.getElementById('password').value) == '')
    {
            alert ('Please enter password.');
            document.getElementById('password').focus();
            return false;
    }
    
    //alert(document.signup_form.length);
    //document.signup_form.submit();
    //alert(document.getElementById('isagreed').checked);
    //return false;
}

function check_login_form(id)
{
    if (trim(document.getElementById('login_username'+id).value) == '')
    {
        alert ('Please enter username.');
        document.getElementById('login_username'+id).focus();
        return false;
    }
    else if (trim(document.getElementById('login_password').value) == '')
    {
        alert ('Please enter password.');
        document.getElementById('login_password'+id).focus();
        return false;
    }
    return true;
}


/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function str_replace (search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/str_replace    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
     for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}        }
    }
    return sa ? s : s[0];
}

function validate_merchant_contact_form_cpy()
{if(document.getElementById('first_name').value.search(/\S/)==-1)
{alert('Please enter your first name.');document.getElementById('first_name').focus();return false;}
if(document.getElementById('last_name').value.search(/\S/)==-1)
{alert('Please enter your last name.');document.getElementById('last_name').focus();return false;}
if(document.getElementById('email').value.search(/\S/)==-1)
{alert('Please enter your email address.');document.getElementById('email').focus();return false;}
if(!document.getElementById('email').value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
{alert("Please enter a proper email address");document.getElementById('email').focus();return false;}
if(document.getElementById('city').value.search(/\S/)==-1)
{alert('Please enter your city.');document.getElementById('city').focus();return false;}
if(document.getElementById('state').value.search(/\S/)==-1)
{alert('Please enter your state.');document.getElementById('state').focus();return false;}
if(document.getElementById('zip').value.search(/\S/)==-1)
{alert('Please enter your zip.');document.getElementById('zip').focus();return false;}
if(document.getElementById('phone')!=null){if(document.getElementById('phone').value.search(/\S/)==-1)
{alert('Please enter your phone number.');document.getElementById('phone').focus();return false;}}
if(document.getElementById('message').value.search(/\S/)==-1)
{alert('Please provide some message for the admin.');document.getElementById('message').focus();return false;}
return true;}

function chk_order_selection()
{
    if(document.getElementById('is_future_order').value=='0')
    {
	document.getElementById('date1').style.display = 'none';
	document.getElementById('date2').style.display = 'none';
	document.getElementById('time1').style.display = 'none';
	document.getElementById('time2').style.display = 'none';
    }
    else if(document.getElementById('is_future_order').value=='1')
    {
	document.getElementById('date1').style.display = 'block';
	document.getElementById('date2').style.display = 'block';
	document.getElementById('time1').style.display = 'block';
	document.getElementById('time2').style.display = 'block';
    }
}

function estimate_shipping_cost(val, id, merchant_id)
{
    if(val!='')
    {
    new Ajax.Updater('estimated_shipping_cost_div','/checkouts/calculate_shipping_cost/'+val+'/'+id+'/'+merchant_id+'/'+document.getElementById('checkout_s_zip').value,{asynchronous:true,evalScripts:true,parameters:Form.Element.serialize(id),onLoading:function(){document.getElementById('loading_img').style.display='inline';},onLoaded:function(){document.getElementById('loading_img').style.display='none';},requestHeaders:['X-Update','estimated_shipping_cost_div']});
    }
}

function validate_widget_form()
{
    var regEmail = /^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;
    
    if(document.getElementById('first_name').value.search(/\S/)==-1)
    {
	alert('Must enter your first name');
	document.getElementById('first_name').focus();
	return false;	
    }
    if(document.getElementById('last_name').value.search(/\S/)==-1)
    {
	alert('Must enter your last name');
	document.getElementById('last_name').focus();
	return false;	
    }
    if(document.getElementById('email').value.search(/\S/)==-1)
    {
	alert('Must enter your email address');
	document.getElementById('email').focus();
	return false;	
    }
    if(document.getElementById('email').value.search(/\S/)!=-1)
    {
	if(!regEmail.test(document.getElementById('email').value))
	{
	    alert("Invalid email address.");
	    document.getElementById('email').focus();
	    return false;
	}
    }
    if(document.getElementById('date_of_birth').value.search(/\S/)!=-1)
    {
	var dob = document.getElementById('date_of_birth').value;
	var dob_array = dob.split('-');
	if(dob_array.length!=3)
	{
	    alert('The date of birth format should be mm-dd-YYYY');
	    document.getElementById('date_of_birth').focus();
	    return false;
	}
	else
	{
	    var formatted_dob = dob_array[0]+'/'+dob_array[1]+'/'+dob_array[2];
	    if(!isDate(formatted_dob))
	    {
		document.getElementById('date_of_birth').focus();
		return false;
	    }
	}
    }
    if(document.getElementById('anniversary_date').value.search(/\S/)!=-1)
    {
	var ann_date = document.getElementById('anniversary_date').value;
	var ann_date_array = ann_date.split('-');
	if(ann_date_array.length!=3)
	{
	    alert('The anniversary date format should be mm-dd-YYYY');
	    document.getElementById('anniversary_date').focus();
	    return false;
	}
	else
	{
	    var formatted_ann_date = ann_date_array[0]+'/'+ann_date_array[1]+'/'+ann_date_array[2];
	    if(!isDate(formatted_ann_date))
	    {
		document.getElementById('anniversary_date').focus();
		return false;
	    }
	}
    }
}
