var xmlHttp;
var methodName;
function remoteCall(url)
{
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      
      
      if(methodName == "checkUser"){
	      xmlHttp.onreadystatechange=checkUserHandle;
	      }
	      if(methodName == "stateCheckHandle"){
	      xmlHttp.onreadystatechange=stateCheckHandle;
	      }
	      else if(methodName == "defaultStateCheckHandle"){
	      	xmlHttp.onreadystatechange=defaultStateCheckHandle;
	      
	      }else if(methodName == "addCC"){
	      	xmlHttp.onreadystatechange=addCCHandle;
	      
	      }else if(methodName == "editAddress"){
	      	xmlHttp.onreadystatechange=editAddressHandle;
	      
	      }else if(methodName == "createAddress"){
	      	xmlHttp.onreadystatechange=createAddressHandle;
	      
	      }else if(methodName == "getShippingHandle"){
	      	xmlHttp.onreadystatechange=getShippingHandle;
	      
	      }else if(methodName == "updateDeliveryMethod"){
	      	xmlHttp.onreadystatechange=updateDeliveryMethodHandle;
	      
	      }else if(methodName == "updateDeliveryMethodLoad"){
	      	xmlHttp.onreadystatechange=updateDeliveryMethodHandle;
	      
	      }else if(methodName == "checkUserIdHandle"){
	      
	      	xmlHttp.onreadystatechange=checkUserIdHandle;
	      
	      }
       
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
}

var stateId;
function stateCheck(url,country1,state1){
	if(url){
		
		if(url.length > 0){	
		stateId = state1;
		 methodName = "stateCheckHandle";
		 if(url.indexOf(';')>-1 ){
		         url = url.substring(0,url.lastIndexOf(';'));
		      }
       
       var countryCode = document.getElementById(country1).value;
       url = url +"?countryId="+countryCode;
       remoteCall(url);
       }
	  }      
}

function stateCheckHandle(){

	if(xmlHttp.readyState==4 && xmlHttp.status==200){
			$("#"+stateId).empty();
			$("#"+stateId).append(xmlHttp.responseText);
          
     }
} 

function defaultStateCheckHandle(){
	if(xmlHttp.readyState==4 && xmlHttp.status==200){
		$("#"+stateId).empty();
		$("#"+stateId).append(xmlHttp.responseText);
               
     }

}

function defaultStateCheck(url,country1,state1){
	if(url){
		if(url.length > 0){	
		stateId = state1;
		 methodName = "defaultStateCheckHandle";
		 if(url.indexOf(';')>-1 ){
		         url = url.substring(0,url.lastIndexOf(';'));
		      }
       
       var countryCode = document.getElementById(country1).value;
       url = url +"?countryId="+countryCode;
       remoteCall(url);
       }
	  }      
}

$(document).ready(function(){
	/* Bottom boxes expanding code */
	var h1 = $("#box-1-contents").height();
	var h2 = $("#box-2-contents").height();
	var h3 = $("#box-3-contents").height();
	$("#box-1-contents").css({ height:"50px", overflow:"hidden" });
	$("#box-2-contents").css({ height:"50px", overflow:"hidden" });
	$("#box-3-contents").css({ height:"50px", overflow:"hidden" });

	$("#box-1-button").click(function () {
		//alert('Here' + $("#box-1-contents").height());
		if($("#box-1-contents").height() == "50"){
			$("#box-1-contents").animate({height: h1}, 500 );
			$("#box-1-button").text("Less...");
		}else{
			$("#box-1-contents").animate({height:"50"}, 500 );
			$("#box-1-button").text("Read more...");
		}
	});

	$("#box-2-button").click(function () {
		if($("#box-2-contents").height() == "50"){
			$("#box-2-contents").animate({height: h1}, 500 );
			$("#box-2-button").text("Less...");
		}else{
			$("#box-2-contents").animate({height:"50"}, 500 );
			$("#box-2-button").text("Read more...");
		}
	});
	//alert("before box-3-button");
	$("#box-3-button").click(function () {
		if($("#box-3-contents").height() == "50"){
			$("#box-3-contents").animate({height: h1}, 500 );
			$("#box-3-button").text("Less...");
		}else{
			$("#box-3-contents").animate({height:"50"}, 500 );
			$("#box-3-button").text("Read more...");
		}
	});
	// Changes proudct view images
	/*$('.product-details-image img').hide();
	$('#product-details-image-1').show();
	$('.p-views a').click(function() {
		$('.product-details-image img').hide();
		$('.p-views a').removeClass('selected');
		$(this).addClass('selected');
		var thisTarget = $(this).attr('title');  
		$('#product-details-image-'+thisTarget).show();
		return false;
	});*/

});

