function check_field(form,field,errorMsg)
{if(!document.getElementById(field).value)
{alert(errorMsg);document.getElementById(field).focus();}
else
document.getElementById(form).submit();}
function check(id)
{if(document.getElementById(id).checked)
document.getElementById(id).checked=false;else
document.getElementById(id).checked=true;}
function ajax_request(file,params,msg)
{var url='/dev/projects.php?'+params;var opt={method:'get',onSuccess:alert(msg),on404:function(t){alert('Error 404: location "'+t.statusText+'" was not found.');},onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText);}}
new Ajax.Request(url,opt);return false;}
function register()
{if(document.getElementById('fname').value==''){document.getElementById('fnameMSG').innerHTML='<font color=red>First name can not be empty</font>';new Effect.Highlight('fnameMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('fnameMSG').innerHTML='';if(document.getElementById('lname').value==''){document.getElementById('lnameMSG').innerHTML='<font color=red>Last name can not be empty</font>';new Effect.Highlight('lnameMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('lnameMSG').innerHTML='';if(checkUsername(document.getElementById('r_user').value,1)=='')
return false;else
document.getElementById('usernameMSG').innerHTML='';if(document.getElementById('r_pass').value==''){document.getElementById('passwordMSG').innerHTML='<font color=red>Password can not be empty</font>';new Effect.Highlight('passwordMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('passwordMSG').innerHTML='';if(document.getElementById('r_cpass').value==''){document.getElementById('cpasswordMSG').innerHTML='<font color=red>Password can not be empty</font>';new Effect.Highlight('cpasswordMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('cpasswordMSG').innerHTML='';if(document.getElementById('r_pass').value!=document.getElementById('r_cpass').value){document.getElementById('passwordMSG').innerHTML='<font color=red>The two passwords are different</font>';new Effect.Highlight('passwordMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});document.getElementById('cpasswordMSG').innerHTML='<font color=red>The two passwords are different</font>';new Effect.Highlight('cpasswordMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
{document.getElementById('passwordMSG').innerHTML='';document.getElementById('cpasswordMSG').innerHTML='';}
if(document.getElementById('r_email').value==''){document.getElementById('emailMSG').innerHTML='<font color=red>Email can not be empty</font>';new Effect.Highlight('emailMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('emailMSG').innerHTML='';if(document.getElementById('r_street').value==''){document.getElementById('streetMSG').innerHTML='<font color=red>Street address can not be empty</font>';new Effect.Highlight('streetMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('streetMSG').innerHTML='';if(document.getElementById('r_city').value==''){document.getElementById('cityMSG').innerHTML='<font color=red>City can not be empty</font>';new Effect.Highlight('cityMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('cityMSG').innerHTML='';if(document.getElementById('r_country').value==''){document.getElementById('countryMSG').innerHTML='<font color=red>Please select your country from the list</font>';new Effect.Highlight('countryMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('countryMSG').innerHTML='';if(document.getElementById('r_phone').value==''){document.getElementById('phoneMSG').innerHTML='<font color=red>Phone can not be empty</font>';new Effect.Highlight('phoneMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('phoneMSG').innerHTML='';if(!document.getElementById('agreement').checked)
{alert('You need read and accept our customer agreements before register');return false;}
return true;}
function profile()
{if(document.getElementById('fname').value==''){document.getElementById('fnameMSG').innerHTML='<font color=red>First name can not be empty</font>';new Effect.Highlight('fnameMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('fnameMSG').innerHTML='';if(document.getElementById('lname').value==''){document.getElementById('lnameMSG').innerHTML='<font color=red>Last name can not be empty</font>';new Effect.Highlight('lnameMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('lnameMSG').innerHTML='';if(document.getElementById('r_pass').value!=document.getElementById('r_cpass').value){document.getElementById('passwordMSG').innerHTML='<font color=red>The two passwords are different</font>';new Effect.Highlight('passwordMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});document.getElementById('cpasswordMSG').innerHTML='<font color=red>The two passwords are different</font>';new Effect.Highlight('cpasswordMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
{document.getElementById('passwordMSG').innerHTML='';document.getElementById('cpasswordMSG').innerHTML='';}
if(document.getElementById('r_email').value==''){document.getElementById('emailMSG').innerHTML='<font color=red>Email can not be empty</font>';new Effect.Highlight('emailMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('emailMSG').innerHTML='';if(document.getElementById('r_street').value==''){document.getElementById('streetMSG').innerHTML='<font color=red>Street address can not be empty</font>';new Effect.Highlight('streetMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('streetMSG').innerHTML='';if(document.getElementById('r_postal').value==''){document.getElementById('postalMSG').innerHTML='<font color=red>Postal code can not be empty</font>';new Effect.Highlight('postalMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('postalMSG').innerHTML='';if(document.getElementById('r_city').value==''){document.getElementById('cityMSG').innerHTML='<font color=red>City can not be empty</font>';new Effect.Highlight('cityMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('cityMSG').innerHTML='';if(document.getElementById('r_country').value==''){document.getElementById('countryMSG').innerHTML='<font color=red>Please select your country from the list</font>';new Effect.Highlight('countryMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('countryMSG').innerHTML='';if(document.getElementById('r_phone').value==''){document.getElementById('phoneMSG').innerHTML='<font color=red>Phone can not be empty</font>';new Effect.Highlight('phoneMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});return false;}
else
document.getElementById('phoneMSG').innerHTML='';return true;}
function checkUsername(username,type)
{var status;var opt={method:'get',onSuccess:function(t){if(t.responseText.match('success'))
{document.getElementById('usernameMSG').innerHTML='<font color=green>Username is available</font>';new Effect.Highlight('usernameMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});status=true;}
else
{if(t.responseText.match('error')){document.getElementById('usernameMSG').innerHTML='<font color=red>Username is not available</font>';new Effect.Highlight('usernameMSG',{startcolor:'#DFE4EA',endcolor:'#A1BBE4'});status=false;}}},on404:function(t){alert('Error 404: location "'+t.statusText+'" was not found.');},onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText);}}
new Ajax.Request('register.php?action=CU:'+username,opt);return status;}
function addToCart(id,price,type)
{var optNum=document.getElementsByTagName('select').length;var action='forward';var options='';for(var i=0;i<optNum;i++)
{if(document.getElementById('opt'+i).value==''&&action=='forward')
{alert('You need to select all options for the item before adding to cart');document.getElementById('opt'+i).focus();action='return';}
if(document.getElementById('opt'+i).value!=''&&action=='forward')
options=options+'|'+document.getElementById('opt'+i).value+'|';}
if(action=='forward')
{var opt={method:'get',onSuccess:updateVisibleArea(id,price,type),on404:function(t){alert('Error 404: location "'+t.statusText+'" was not found.');},onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText);}}
new Ajax.Request('/shopping_cart.php?action=add_item&id='+id+'&price='+price+'&options='+options,opt);notice('notice','Product is successfully added to your shopping cart.');}
document.getElementById('add2cart').disabled='true';return false;}
function notice(id,message)
{new Effect.Highlight(id,{startcolor:'#EAEFF5',endcolor:'#FFFFFF'});document.getElementById(id).innerHTML='<br>'+message;}
function updateVisibleArea(id,price,type)
{if(type!=1)
{var items=document.getElementById('shopping_cart_items').innerHTML;document.getElementById('shopping_cart_items').innerHTML=1*items+1;var total=document.getElementById('shopping_cart_total').innerHTML.replace(',','.');document.getElementById('shopping_cart_total').innerHTML=1*total+1*price;new Effect.Highlight('shopping_cart_row',{startcolor:'#DFE4EA',endcolor:'#EAEFF5'});}}
function viewCart()
{document.location.href='/shopping_cart.php?action=view_cart';}
function checkout()
{document.location.href='/shopping_cart.php?action=checkout';}
function getVal(id)
{if(parent.document.getElementById(id))
{if(!parent.document.getElementById(id).type)
return parent.document.getElementById(id).innerHTML;else
return parent.document.getElementById(id).value;}
else
return false;}
function setVal(id,value)
{if(parent.document.getElementById(id))
{if(!parent.document.getElementById(id).type)
{document.getElementById(id).innerHTML=value;return true;}
else
{parent.document.getElementById(id).value=value;return true;}}
else
return false;}
function updateCart()
{var total=0;var array='';for(var i=1;i<=100;i++)
{if(getVal('v'+i)>0)
{var subtotal=(getVal('p'+i)*1)*(getVal('q'+i)*1);setVal('st'+i,'$'+subtotal);total=total+subtotal;array=array+getVal('v'+i)+'-'+getVal('q'+i)+'|';}}
var total2=total+(getVal('shipping')*1)+(getVal('tax')*1);updateCartSession(array,total);setVal('total_price',total2);notice('notice','<font color=green>Shopping cart is successfully updated.</font>');}
function updateCartSession(array,total)
{var opt={method:'get',on404:function(t){alert('Error 404: location "'+t.statusText+'" was not found.');},onFailure:function(t){alert('Error '+t.status+' -- '+t.statusText);}}
new Ajax.Request('/shopping_cart.php?action=update&items='+array+'&total='+total,opt);return false;}
function removeFromCart(id,key)
{Effect.SwitchOff('item'+id);setVal('q'+key,0);updateCart();}
function changeState(country)
{if(country=='United States')
{document.getElementById('USstates').style.display='';document.getElementById('r_state').style.display='none';}
else
{document.getElementById('USstates').style.display='none';document.getElementById('r_state').style.display='';}}
function checkCreditCard()
{var r=2;if(!getVal('ccname'))
{alert('You need to enter your card holder name');document.getElementById('ccname').focus();r=1;}
if(!getVal('ccnumber'))
{alert('You need to enter Credit Card number before continue');document.getElementById('ccnumber').focus();r=1;}
if(!getVal('cvv2'))
{alert('Security code can not be empty');document.getElementById('cvv2').focus();r=1;}
if(r==2)
document.getElementById('creditCardForm').submit();}
