// JavaScript Document

var ajax=new sack();
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 showHideForm()
	{
		if(document.getElementById('showHideForm').style.display=='block')
		document.getElementById('showHideForm').style.display='none';
		else
		document.getElementById('showHideForm').style.display='block';
	}
function sameAsBilling(countryName)	
	{
		var breakCountry=countryName.split('##');
		if(document.getElementById('sameas').checked==true)
			{
				document.getElementById('CfirstName').value=document.getElementById('BfirstName').value;
				document.getElementById('CmiddleName').value=document.getElementById('BmiddleName').value;
				document.getElementById('ClastName').value=document.getElementById('BlastName').value;
				document.getElementById('Caddress1').value=document.getElementById('Baddress1').value;
				document.getElementById('Caddress2').value=document.getElementById('Baddress2').value;
				/*document.getElementById('Ccountry').options.length = 0;
document.getElementById('Ccountry').options[0] = new Option(document.getElementById('Bcountry').value,document.getElementById('Bcountry').value);*/
document.getElementById('Ccountry').options.length = 0;
				document.getElementById('Ccountry').options[0] = new Option('--Select Country--','');
				for(var j=0;j<breakCountry.length-1;j++)
					{
						if(document.getElementById('Bcountry').value==breakCountry[j])
							{
								//document.getElementById('Ccountry').options[j+1] = new Option(breakCountry[j],breakCountry[j],true);   remember works only in mozila
								//document.getElementById('theDay').options[i].selected=true;   work in both
								document.getElementById('Ccountry').options[j+1] = new Option(breakCountry[j],breakCountry[j]);
								document.getElementById('Ccountry').options[j+1].selected=true;
							}
						else
							{
								document.getElementById('Ccountry').options[j+1] = new Option(breakCountry[j],breakCountry[j]);	
							}
					}
				document.getElementById('Ccity').value=document.getElementById('Bcity').value;
				document.getElementById('Cstate').value=document.getElementById('Bstate').value;
				document.getElementById('Czip').value=document.getElementById('Bzip').value;
				document.getElementById('CtelPhone').value=document.getElementById('BtelPhone').value;
				document.getElementById('makeShippingEmpty').value='makeShippingEmpty';
			}
		else
			{
					
				//document.registration.submit();
				document.getElementById('CfirstName').value='';
				document.getElementById('CmiddleName').value='';
				document.getElementById('ClastName').value='';
				document.getElementById('Caddress1').value='';
				document.getElementById('Caddress2').value='';
				document.getElementById('Ccountry').options.length = 0;
				document.getElementById('Ccountry').options[0] = new Option('--Select Country--','');
				for(var j=0;j<breakCountry.length-1;j++)
					{
document.getElementById('Ccountry').options[j+1] = new Option(breakCountry[j],breakCountry[j]);
					}
				document.getElementById('Ccity').value='';
				document.getElementById('Cstate').value='';
				document.getElementById('Czip').value='';
				document.getElementById('CtelPhone').value='';
				document.getElementById('makeShippingEmpty').value='makeShippingEmpty';
			}
	}
	
function forgotPassword()
	{
		if(document.getElementById('rowPassword').style.display=='block')
		document.getElementById('rowPassword').style.display='none';
		else
		document.getElementById('rowPassword').style.display='block';
	}
	

function takeToMyAccount()
	{
		alert(3333333);
	}

function getDtlProduct(base,orderId)
	{
		ajax.requestFile=base+'/member/getproductdetail/orderid-'+orderId;
		ajax.onCompletion=function()
			{
				showProductDetail(base,orderId);
			}
		ajax.onLoading=function()
			{
				showLoading(base,orderId);
			}
		ajax.runAJAX();
	}

function showLoading(base,orderId)
	{
		document.getElementById('detail_'+orderId).innerHTML='<div class="abcd"><center><img src="'+base+'/images/ajax_load.gif"></center>Loading..</div>';
	}

function showProductDetail(base,orderId)
	{
		document.getElementById('detail_'+orderId).innerHTML=ajax.response;
		document.getElementById('txtDetail_'+orderId).innerHTML='<a href="javascript: void(0);" onclick="hideProductDetail(\''+base+'\','+orderId+');">Hide Details</a>';
		
	}

function hideProductDetail(base,orderId)
	{
		document.getElementById('detail_'+orderId).innerHTML='';
		document.getElementById('txtDetail_'+orderId).innerHTML='<a href="javascript: void(0);" onclick="getDtlProduct(\''+base+'\','+orderId+');">Details</a>';
	}

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

function getShippingDtl(base,shippingId,memId,total)
	{
		if(document.getElementById('shippingList').value!=0)
			{
		ajax.requestFile=base+'/member/showshippinginfomember/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+','+memId+');">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+'/member/editshippinginfomember/shippingid-'+shippingId+'\',450,550);return false";>Edit</a>';
		}
		else
			{
				document.getElementById('selectShippingAddress').innerHTML='';
				
				document.getElementById('edit').innerHTML='';
			}
	}
	
	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 style="padding-top:25px" href="javascript: void(0);" onclick="makeInvisible(); displayMessage(\''+base+'/member/editshippinginfomember/shippingid-'+splitResult[1]+'\',450,550)"><img src="'+base+'/images/btn-edit.jpg" class="button" />	</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 checkForgotPasswordField()
	{
		if(document.getElementById('forgotEmail').value=='')
			{
				alert('Please enter your email address ');
				return false;
			}
		else
			{
				return true;
			}
	}
	
function deleteShippingAddress(base,shippingId,memId)
	{
		window.location=base+'/member/myaccountprofile/task-profile/memid-'+memId+'/task-delspadd/spid-'+shippingId;
	}


function trackOrder(base)
	{
		ajax.requestFile=base+'/member/trackorder';
		ajax.onCompletion=function ()
			{
				showTrackOrder(base);
			}
		ajax.runAJAX();
	}

function showTrackOrder(base)
	{
		
		if(ajax.response == 'notlogged')
			{
				window.location=base+'/member/status-tord';
			}
		else
			{
				var breakRes=ajax.response.split('##');
				window.location=base+'/member/myaccountprofile/memid-'+breakRes[1];
			}
	}


function checkMyAccount(base)
	{
		ajax.requestFile=base+'/member/checkmyaccount';
		ajax.onCompletion=function ()
			{
				showMyAccount(base);
			}
		ajax.runAJAX();
	}

function showMyAccount(base)
	{
		
		if(ajax.response == 'notlogged')
			{
				window.location=base+'/member/status-notloggedmyacc';
			}
		else
			{
				var breakRes=ajax.response.split('##');
				window.location=base+'/member/myaccountprofile/memid-'+breakRes[1];
			}
	}
	
	
function makeInvisible()
	{
		document.getElementById('shippingContainer').style.visibility='hidden';
	}






