function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
	}
	
	
	function changeDropbox(form) {
		var val=form.categoryid.options[form.categoryid.options.selectedIndex].value;
		var strURL='/ajaxinc/categories.php?catID='+val;
		//this.displayForm(val);
		//alert(strUrl);
	  var req = getXMLHTTP(); // fuction to get xmlhttp object
    if (req) {
      req.onreadystatechange = function() {
        if (req.readyState == 4) { //data is retrieved from server
          if (req.status == 200) { // which reprents ok status                    
            document.getElementById('products').innerHTML=req.responseText;     
          
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req.open("GET", strURL, true); //open url using get method
      req.send(null);
    }
    if(form.productid) { 
    	this.changeDropbox1(form);
    }
  }
  
  function changeDropbox1(form) {
		var val=form.categoryid.options[form.categoryid.options.selectedIndex].value;
		var val1=form.productid.options[form.productid.options.selectedIndex].value;
		
		var strURL='/ajaxinc/products.php?catID='+val;
		if(val1) strURL +='&prodID='+val1;
		//alert(strUrl);
	  var req1 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req1) {
      req1.onreadystatechange = function() {
        if (req1.readyState == 4) { //data is retrieved from server
          if (req1.status == 200) { // which reprents ok status                    
          document.getElementById('displayVariants').innerHTML=req1.responseText;
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req1.open("GET", strURL, true); //open url using get method
      req1.send(null);
    } 
  }
  
 function changeContactDropbox(form) {
    //alert(form);
		var val4=form.regionid.options[form.regionid.options.selectedIndex].value;
		var strURLc='/ajaxinc/contactcategories.php?regionID='+val4;
		if(form.contactcategoryid) { 
		  var val3=form.contactcategoryid.options[form.contactcategoryid.options.selectedIndex].value;
		  if(val3) strURLc +='&concatID='+val3;
		}
		//this.displayForm(val);
		//alert(strUrl);
	  var req3 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req3) {
      req3.onreadystatechange = function() {
        if (req3.readyState == 4) { //data is retrieved from server
          if (req3.status == 200) { // which reprents ok status                    
            document.getElementById('listCats').innerHTML=req3.responseText;     
          
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req3.open("GET", strURLc, true); //open url using get method
      req3.send(null);
    }
    if(form.contactcategoryid) { 
    	this.changeContactDropbox1(form);
    }
   }
  
  
  function changeContactDropbox1(form) {
		var val=form.regionid.options[form.regionid.options.selectedIndex].value;
		var val1=form.contactcategoryid.options[form.contactcategoryid.options.selectedIndex].value;
		var strURL='/ajaxinc/contacts.php?regionID='+val;
		if(val1) strURL +='&concatID='+val1;
		//alert(strUrl);
	  var req4 = getXMLHTTP(); // fuction to get xmlhttp object
    if (req4) {
      req4.onreadystatechange = function() {
        if (req4.readyState == 4) { //data is retrieved from server
          if (req4.status == 200) { // which reprents ok status                    
          document.getElementById('displayContactDetails').innerHTML=req4.responseText;
          } else { 
            alert("There was a problem while using XMLHTTP:\n");
          }
        }            
      }        
      req4.open("GET", strURL, true); //open url using get method
      req4.send(null);
    }
   
  }
  
 function prefill(form,customerID) {
  //  alert(customerID);
    //this.showUserList(srcStr);
    $.post("/ajaxinc/getUserDetails.php", {queryString: customerID}, function(data){
				for ( i=0; i < data.length; i++ )
          {
       //     alert ( data[i] );
          }

		//		alert(data[3]);
				if(data.length >0) {
					$('#form_contactname').val(data[3]);
//					$('#autoSuggestionsList').html(data);
				}
			});
    }
    
    function showProd(p) {
  alert(p);
 // $('#products' + p).slideToggle(900);
  return false;
}

 jQuery(window).load(function(){
$(".products").hide();
			$(function(){
	
				$('#cropbox').Jcrop({
					aspectRatio: 1,
					onSelect: updateCoords,
				});

// $('#cropbox').Jcrop({ boxWidth: 2400, boxHeight: 1500, onSelect: updateCoords, });
         
			});
			});

 $(document).ready(function(){
	//hide the all of the element with class msg_body
	/* $(".products").hide();
	//toggle the componenet with class msg_body
	$(".productHeading").click(function(){ 
	  $(".products").slideToggle(900);
*/

  $(".products").hide();
	//toggle the componenet with class msg_body
	
	/* $('a.comment').click(function() {
	   var id = $(this).attr('id');
	   $('#products' + id).slideToggle(900);
     return false;
     }); 
*/
});
			function updateCoords(c)
			{
			  $('#x').val(c.x);
				$('#y').val(c.y);
				$('#w').val(c.w);
				$('#h').val(c.h);
			};

			function checkCoords()
			{
				if (parseInt($('#x').val())) return true;
				alert('Please select a crop region then press submit.');
				return false;
			};