
function popupWindow(url){window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=200,height=200,screenX=150,screenY=150,top=150,left=150')}
function initialise_prices()
{if(Math.round(document.forms["cart_quantity"].cart_quantity.value,0)==0){update_prices(document.forms["cart_quantity"].Model.value,30);}
else{update_prices(document.forms["cart_quantity"].Model.value,0);}
if(Math.round(document.forms["cart_quantity"].UpdateCQ.value,0)<1){if(document.forms["cart_quantity"].elements["id[13]"]){update_greeting_tmp(document.forms["cart_quantity"].elements["id[13]"].value);}}}
function update_prices($model,$quantity_change)
{const_discount=0.10;print_colour();old_quantity=document.forms["cart_quantity"].cart_quantity.value;if(($quantity_change+Math.round(document.forms["cart_quantity"].cart_quantity.value,0))<30)
{if(($quantity_change==10)&&Math.round(document.forms["cart_quantity"].cart_quantity.value,0)<30)
{document.forms["cart_quantity"].cart_quantity.value=30;}
else{document.forms["cart_quantity"].cart_quantity.value="0";}}
else
{document.forms["cart_quantity"].cart_quantity.value=Math.round(document.forms["cart_quantity"].cart_quantity.value,0)+$quantity_change;}
if(document.forms["cart_quantity"].ColourOption)
{if(document.forms["cart_quantity"].ColourOption.value==1)
{$colour_price="";$colp=0;}
else
{
$colour_price="";$colp=0;
if(document.forms["cart_quantity"].cart_quantity.value<=5000)
{
  //$colp=(0.15/0.9)*Math.round(document.forms["cart_quantity"].cart_quantity.value,0);
  //$colp_temp=$colp*0.9;
  //$colp_a=$colp_temp.toFixed(2);
  //$colour_price="(Colour charge : £"+$colp_a+")";
  $colp=60/0.9;
  $colour_price="(Full Colour : £60.00)";
  }
if(document.forms["cart_quantity"].cart_quantity.value<=1000) {
  //$colp=(0.23/0.9)*Math.round(document.forms["cart_quantity"].cart_quantity.value,0);
  //$colp_temp=$colp*0.9;
  //$colp_a=$colp_temp.toFixed(2);
  //$colour_price="(Colour charge : £"+$colp_a+")";
  $colp=60/0.9;
  $colour_price="(Full Colour : £60.00)";
  }
if(document.forms["cart_quantity"].cart_quantity.value<=300) {
  $colp=60/0.9;
  $colour_price="(Full Colour : £60.00)";
  }
}
}
else{$colour_price="";$colp=0;}

if(document.forms["cart_quantity"].ColourOption)
{if(document.forms["cart_quantity"].ColourOption.value==1){document.forms["cart_quantity"].elements["id[9]"].value=1;}
else{document.forms["cart_quantity"].elements["id[9]"].value=2;if(document.forms["cart_quantity"].cart_quantity.value>300){document.forms["cart_quantity"].elements["id[9]"].value=3;}
if(document.forms["cart_quantity"].cart_quantity.value>1000){document.forms["cart_quantity"].elements["id[9]"].value=4;}
if(document.forms["cart_quantity"].cart_quantity.value>5000){document.forms["cart_quantity"].elements["id[9]"].value=5;}}}
if(document.forms["cart_quantity"].Colour){document.forms["cart_quantity"].Colour.value=$colour_price;}
$Tot=Math.round(((document.forms["cart_quantity"].cart_quantity.value*get_unit_price(get_band($model),document.forms["cart_quantity"].cart_quantity.value))+$colp*(1-const_discount))*100,0)/100;$Basic=Math.round((($Tot-$colp*(1-const_discount))/(1-const_discount))*100)/100;$Discount=($Basic+$colp)-$Tot;$UnitPrice=$Tot/document.forms["cart_quantity"].cart_quantity.value;$Tot="Total : £"+addCommas($Tot.toFixed(2));if($colp>0){$Basic_Prime=$Basic+$colp;$Basic="Price (RRP) : £"+addCommas($Basic_Prime.toFixed(2));}
else{$Basic="Price (RRP) : £"+addCommas($Basic.toFixed(2));}
$Discount="Discount (10%) : £"+addCommas($Discount.toFixed(2));if(document.forms["cart_quantity"].cart_quantity.value>0){$UnitPrice="(£"+$UnitPrice.toFixed(2)+" per card)";}
else
{$UnitPrice="";}
document.forms["cart_quantity"].Total.value=$Tot;document.forms["cart_quantity"].Price.value=$Basic;document.forms["cart_quantity"].Discount.value=$Discount;document.forms["cart_quantity"].UnitPrice.value=$UnitPrice;if(document.forms["cart_quantity"].UpdateCQ.value=="1"){document.forms["cart_quantity"].elements["cart_quantity[0]"].value=document.forms["cart_quantity"].cart_quantity.value;}}
function addCommas(nStr)
{nStr+='';x=nStr.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,'$1'+','+'$2');}
return x1+x2;}

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

function get_unit_price(band,quant) {
  prices = document.getElementById("Prices").value;
  cursor = 0;
  quant = parseInt(quant) / 10 - 3;
  //alert( quant );
  if ( quant >= 97 ) { quant = 97; }
  for($i=0;$i<quant;$i++) {
    cursor = strpos(prices,",") + 1;
    prices = prices.substr(cursor,prices.length-cursor);
    }
  cursor=0;
  cursor_end = strpos(prices,",");
  price_ret = parseFloat( prices.substr(cursor+1,cursor_end-1) );
  return ( price_ret );
  }

function get_total_price($band,$quantity)
{return($quantity*get_unit_price($band,$quantity));}
function get_band($model)
{if(document.forms["cart_quantity"].Manufacturer){return(document.forms["cart_quantity"].Manufacturer.value);}}
function update_greeting()
{$erase_flag=0;if(document.forms["cart_quantity"].editsmade){if(document.forms["cart_quantity"].editsmade.value=="TRUE")
{$erase_flag=confirm("Edits have been made to the personalised greeting.  If you continue these changes will be lost, continue?");}
if(document.forms["cart_quantity"].editsmade.value!="TRUE"||$erase_flag==true)
{update_greeting_tmp(document.forms["cart_quantity"].elements["id[13]"].value);document.forms["cart_quantity"].editsmade.value="FALSE";}}}
function greeting_changed()
{if(document.forms["cart_quantity"].editsmade){document.forms["cart_quantity"].editsmade.value="TRUE";}}
function update_greeting_tmp($inp)
{if(document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"])
{switch($inp)
{case"13":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="With\nBEST WISHES for CHRISTMAS\nand the NEW YEAR\nfrom\n[Company name here]";break;case"14":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="SEASON'S GREETINGS\nfrom\n[Company name here]";break;case"15":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="In appreciation of our association\nduring the past year\nwe extend our best wishes for a\nMerry Christmas and a Happy New Year\nfrom\n[Company name here]";break;case"16":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="Wishing you a\nMERRY CHRISTMAS\nand a\nPROSPEROUS NEW YEAR\nfrom\n[Company name here]";break;case"17":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="Season's Greetings\nFrohliches Weinachten\nJoyeux Noel\nBuon Natale\nFeliz Navidad\nfrom\n[Company name here]";break;case"18":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="With all Good Wishes\nfor CHRISTMAS\nand Every Happiness in\nthe COMING YEAR\nfrom\n[Company name here]";break;case"19":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="MERRY CHRISTMAS\nand a\nHAPPY NEW YEAR\nfrom\n[Company name here]";break;case"20":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="With the\nSEASON'S GREETINGS and\nBEST WISHES for the NEW YEAR\n[Company name here]";break;case"21":document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="The year end brings\nno greater pleasure than the\nopportunity to express to you\nSeason's Greetings and Best Wishes\nfrom\n[Company name here]";break;default:document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value="";break;}}}
function preview_wording()
{var strMultiLineText=new String(document.forms["cart_quantity"].elements["id[TEXT_PREFIX3]"].value);var strSingleLineText=strMultiLineText.replace(new RegExp("\\n","g"),"<br>");$URL='http://www.christmas-cards-online.co.uk/preview.php?ts='+document.forms["cart_quantity"].elements["id[14]"].value+"&tc="+document.forms["cart_quantity"].elements["id[15]"].value+"&text="+strSingleLineText;window.open($URL,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=800,height=800,screenX=0,screenY=0,top=150,left=150')}
function preview_raf()
{var strMultiLineText=new String(document.ReferForm.message.value);var strSingleLineText=strMultiLineText.replace(new RegExp("\\n","g"),"<br>");$URL='http://www.christmas-cards-online.co.uk/preview_raf.php?cust_name='+document.ReferForm.name.value+'&message='+strSingleLineText;window.open($URL)}
function validate_sreq_form(form)
{ErrMsg="";Err=false;if(form.Title.selectedIndex==0){Err=true;ErrMsg="Please select a Title from the list\n";}
if(form.Samp1.value==""){Err=true;ErrMsg=ErrMsg+"Please select some sample invitations\n";}
if(form.Firstname.value==""){Err=true;ErrMsg=ErrMsg+"Please enter your first name\n";}
if(form.Lastname.value==""){Err=true;ErrMsg=ErrMsg+"Please enter your last name\n";}
if(form.Address1.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first line of your address in field Address 4\n";}
if(form.Address2.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first line of your address in field Address 2\n";}
if(form.Postcode.value==""){Err=true;ErrMsg=ErrMsg+"Please enter your postcode\n";}
if(form.Email.value==""){Err=true;ErrMsg=ErrMsg+"Please enter your email address\n";}
if(Err)
{alert(ErrMsg);return false;}
else{return true;}}
function check_refer_form()
{Err=false;ErrMsg="";AllBlank=true;if((document.ReferForm.firstname1.value+document.ReferForm.lastname1.value+document.ReferForm.friendemail1.value)!="")
{AllBlank=false;if(document.ReferForm.firstname1.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first name of your FRIEND 1\n";}
if(document.ReferForm.lastname1.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the last name of your FRIEND 1\n";}
if(document.ReferForm.friendemail1.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the email address of your FRIEND 1\n";}
else{if(checkEmail(document.ReferForm.friendemail1.value)==false){Err=true;ErrMsg=ErrMsg+"Please enter a valid email address for your FRIEND 1\n";}}}
if((document.ReferForm.firstname2.value+document.ReferForm.lastname2.value+document.ReferForm.friendemail2.value)!="")
{AllBlank=false;if(document.ReferForm.firstname2.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first name of your FRIEND 2\n";}
if(document.ReferForm.lastname2.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the last name of your FRIEND 2\n";}
if(document.ReferForm.friendemail2.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the email address of your FRIEND 2\n";}
else{if(checkEmail(document.ReferForm.friendemail2.value)==false){Err=true;ErrMsg=ErrMsg+"Please enter a valid email address for your FRIEND 2\n";}}}
if((document.ReferForm.firstname3.value+document.ReferForm.lastname3.value+document.ReferForm.friendemail3.value)!="")
{AllBlank=false;if(document.ReferForm.firstname3.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first name of your FRIEND 3\n";}
if(document.ReferForm.lastname3.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the last name of your FRIEND 3\n";}
if(document.ReferForm.friendemail3.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the email address of your FRIEND 3\n";}
else{if(checkEmail(document.ReferForm.friendemail3.value)==false){Err=true;ErrMsg=ErrMsg+"Please enter a valid email address for your FRIEND 3\n";}}}
if((document.ReferForm.firstname4.value+document.ReferForm.lastname4.value+document.ReferForm.friendemail4.value)!="")
{AllBlank=false;if(document.ReferForm.firstname4.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first name of your FRIEND 4\n";}
if(document.ReferForm.lastname4.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the last name of your FRIEND 4\n";}
if(document.ReferForm.friendemail4.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the email address of your FRIEND 4\n";}
else{if(checkEmail(document.ReferForm.friendemail4.value)==false){Err=true;ErrMsg=ErrMsg+"Please enter a valid email address for your FRIEND 4\n";}}}
if((document.ReferForm.firstname5.value+document.ReferForm.lastname5.value+document.ReferForm.friendemail5.value)!="")
{AllBlank=false;if(document.ReferForm.firstname5.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first name of your FRIEND 5\n";}
if(document.ReferForm.lastname5.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the last name of your FRIEND 5\n";}
if(document.ReferForm.friendemail5.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the email address of your FRIEND 5\n";}
else{if(checkEmail(document.ReferForm.friendemail5.value)==false){Err=true;ErrMsg=ErrMsg+"Please enter a valid email address for your FRIEND 5\n";}}}
if((document.ReferForm.firstname6.value+document.ReferForm.lastname6.value+document.ReferForm.friendemail6.value)!="")
{AllBlank=false;if(document.ReferForm.firstname6.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the first name of your FRIEND 6\n";}
if(document.ReferForm.lastname6.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the last name of your FRIEND 6\n";}
if(document.ReferForm.friendemail6.value==""){Err=true;ErrMsg=ErrMsg+"Please enter the email address of your FRIEND 6\n";}
else{if(checkEmail(document.ReferForm.friendemail6.value)==false){Err=true;ErrMsg=ErrMsg+"Please enter a valid email address for your FRIEND 6\n";}}}
if(AllBlank){alert("You have not entered any friend details");return false;}
else
{if(Err)
{alert(ErrMsg);return false;}
else{if(document.ReferForm.tandc_check.checked){return true;}
else{alert("Please tick the box to acknowledge that you have read our terms and conditions");return false;}}}}
function checkEmail(email){if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){return(true);}
return(false);}
