var ajax=new sack();
function checkLogin(base,myAccount)
	{
		var myAccount=(myAccount==null)?null:myAccount;
		ajax.requestFile=base+'/cart/checklogin';
		ajax.onCompletion=function ()
			{
				showResult(base,myAccount);
			}
		ajax.runAJAX();
	}

function showResult(base,myAccount)
	{
		var myAccount=(myAccount)==null?null:myAccount;
		if(ajax.response == 'notlogged')
			{
				if(myAccount==null)
				window.location=base+'/member/status-notlogged';
				else
				window.location=base+'/member/status-notloggedmyacc';
			}
		else
			{
				var breakRes=ajax.response.split('##');
				if(myAccount==null)
				window.location=base+'/cart/checkout';
				else
				window.location=base+'/member/myaccountprofile/memid-'+breakRes[1];
			}
	}

function selectGetway()
	{
		var error='';
		/*if(document.getElementById('shippingCharge').value==0)
			{
				error+='Please Select Shipping Charge !!!!\n';	
			}*/
		if(document.getElementById('getway_'+0).checked!=true && document.getElementById('getway_'+2).checked!=true && document.getElementById('getway_'+1).checked!=true && document.getElementById('getway_'+3).checked!=true && document.getElementById('getway_'+4).checked!=true)
			{
				error+='Please Select Payment Method !!!!\n';
			}
		if(error!='')
			{
				alert(error);
				return false;
			}
		else
			{
				return true;
			}
		
	}

messageObj = new DHTML_modalMessage();	// We only create one object of this class
messageObj.setShadowOffset(5);	// Large shadow


function displayMessage(url,width,height)
{
	
	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(width,height);
	messageObj.setShadowDivVisible(true);	// Enable shadow for these boxes
	messageObj.display();
}

function closeMessage()
{
	messageObj.close();	
}

function takeToMyAccount()
	{
		alert(3333333);
	}

function showShippingList(base,memId)
	{
		ajax.requestFile=base+'/cart/showshippinglistcart/memid-'+memId;
		ajax.onCompletion=showList;
		ajax.runAJAX();
	}
function showList()
	{
		document.getElementById('shippingContainer').innerHTML=ajax.response;
	}

function getShippingDtl(base,shippingId,total)
	{
		
		if(document.getElementById('shippingList').value!=0)
			{
				ajax.requestFile=base+'/cart/showshippinginfo/shippingid-'+shippingId;
				ajax.onCompletion=function()
					{
						showShippingInfo(base,shippingId);
					}
				ajax.onLoading=function()
					{
						//showShippingLoading(base,shippingId);	
					}
				ajax.runAJAX();
				
				
				var alertMsg='Atleast One Shipping Address Is Required !!!';
				if(total>1)
					{
						document.getElementById('selectShippingAddress').innerHTML='<a style="float:left; font:12px arial; color:#c00; padding-left:10px;" href="javascript: void(0);" onclick="deleteShippingAddress(\''+base+'\','+shippingId+');">Delete</a>';
					}
				else
					{
						document.getElementById('selectShippingAddress').innerHTML='<a style="float:left; font:12px arial; color:#c00; padding-left:10px;" href="javascript: void(0);" onclick="alert(\''+alertMsg+'\');">Delete</a>';
					}
				
				document.getElementById('edit').innerHTML='<a style="float:left; font:12px arial; color:#c00; padding-left:10px;" href="javascript: void(0);" onclick="makeInvisible(); displayMessage(\''+base+'/cart/editshippinginfocart/shippingid-'+shippingId+'\',400,550);return false";>Edit</a>';
			}
		else
			{
				document.getElementById('selectShippingAddress').innerHTML='';
				
				document.getElementById('edit').innerHTML='';
			}
	}
function showShippingLoading(base,shippingId)
	{
		alert('loading');
		document.getElementById('shippingInfo').innerHTML='<span style="padding-top:150px;" class="xyz"><img src="'+base+'/images/ajax_load.gif"> Loading Shipping Information ....</span>';
	}

function showShippingInfo(base,shippingId)
	{
		var result=ajax.response;
		var splitResult=result.split('##');
		document.getElementById('shippingInfo').innerHTML=splitResult[0];
		
		if(splitResult[2]>0)
			{
		document.getElementById('editLink').innerHTML='<a href="javascript: void(0);" onclick="makeInvisible(); displayMessage(\''+base+'/cart/editshippinginfocart/shippingid-'+splitResult[1]+'\',400,550)"><img src="'+base+'/images/button-change.jpg" />	</a>';
			}
							
	}




function validateShippingField()
	{
		var error='';
		if(document.getElementById('CfirstName').value=='')
			{
				error+='Shipping First Name Is Required !!!\n';
			}
		if(document.getElementById('Caddress1').value=='')
			{
				error+='Shipping Address1 Is Required !!!\n';
			}
		if(document.getElementById('Ccountry').value=='')
			{
				error+='Shipping Country Is Required !!!\n';
			}
		if(document.getElementById('Czip').value=='')
			{
				error+='Shipping Zip Is Required !!!\n';
			}
		if(document.getElementById('CtelPhone').value=='')
			{
				error+='Shipping Phone Number Is Required !!!\n';
			}
		if(error=='')
			{
				return true;
			}
		else
			{
				alert(error);
				return false;
			}
	}

function validateBillingField()
	{
		var error='';
		if(document.getElementById('BfirstName').value=='')
			{
				error+='Billing First Name Is Required !!!\n';
			}
		if(document.getElementById('Baddress1').value=='')
			{
				error+='Billing Address1 Is Required !!!\n';
			}
		if(document.getElementById('Bcountry').value=='')
			{
				error+='Billing Country Is Required !!!\n';
			}
		if(document.getElementById('Bzip').value=='')
			{
				error+='Billing Zip Is Required !!!\n';
			}
		if(document.getElementById('BtelPhone').value=='')
			{
				error+='Billing Phone Number Is Required !!!\n';
			}
		if(error=='')
			{
				return true;
			}
		else
			{
				alert(error);
				return false;
			}
	}
	
function deleteShippingAddress(base,shippingId)
	{
		window.location=base+'/cart/checkout/task-delspadd/spid-'+shippingId;
	}

function makeInvisible()
	{
		document.getElementById('shippingContainer').style.visibility='hidden';
	}
	
	
	


