function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	
	var http = createRequestObject();
function set_selected_value(select_element_name, value)
{
	$("#"+select_element_name).value = value;
	//alert($("#"+select_element_name).selectedValue = value);
}

function currencyFormat(fld, e) 
{	
	var key = '';
	var i = 0;
	var len;
	var strCheck = '0123456789.,';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if(whichCode == null) whichCode = e.keyCode;
	if (whichCode == 13) return true; // Enter
	if (whichCode == 8) return true; // Delete 
	key = String.fromCharCode(whichCode); // Get key value from key code
	len = fld.value.length;	
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key
		
	if(key == '.')
	{
		if(hasPoint(fld.value))
		{
			return false;
		}
	}
	
	if(len == 0 && key == '.')
	{
		return false;
	}
}

function hasPoint(aux)
{
	if(aux.indexOf('.') != -1)
	{
		return true;
	}
	return false;
}
var iR=0;
function change_Image(maxR,current_item){	
	iR=current_item;
	ShowHideLayer(maxR);
}

function ShowHideLayer(maxR){
	for(var i = 0 ; i < maxR ; i ++) {
			var xControl = document.getElementById('imgR'+i);	
			if(i==iR) {				
				xControl.className="showLayer";				
			}
			else {
				xControl.className="hideLayer";
			}		
		}
}

function confirmDelete()
{
	return confirm("Are you sure you want to delete?");
		
}

function confirm_delete(url)
{
	jConfirm('Are you sure you want to delete?', 'Confirmation Dialog', function(r) {
	if( r ) 
	{
		window.location = url;
	}
	else { } 
	});
	return false; 
};
	
function check_checkbox(doc)
{
  var j = 0;
  var k = 0;
  var c = new Array();
  c = doc.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].type == 'checkbox' && c[i].checked == true && c[i].name == 'cb[]')
    {
      j++;
    }
	
	if (c[i].type == 'checkbox' && c[i].checked == true && c[i].name == 'attribute')
    {
      k++;
    }
	if (c[i].type == 'checkbox' && c[i].checked == true && c[i].name == 'category')
    {
      k++;
    }
	if (c[i].type == 'checkbox' && c[i].checked == true && c[i].name == 'tax')
    {
      k++;
    }
	if (c[i].type == 'checkbox' && c[i].checked == true && c[i].name == 'option')
    {
      k++;
    }
	if (c[i].type == 'checkbox' && c[i].checked == true && c[i].name == 'series')
    {
      k++;
    }
  }
  
  if(j<=0)
  {
	jAlert("Please select at least one product!", "Alert Dialog");
	return false;		
  }
    
  if(k<=0)
  {
	jAlert("Please select one property to update!", "Alert Dialog");
	return false;
  }
  
  return true;
  
};

function checkAll(doc) {
   
  var c = new Array();
  var selected = doc.frmproductlist.checkall.value;
  c = doc.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
	if(selected == "1")
	{
		if (c[i].type == 'checkbox')
		{
		  c[i].checked = true;
		}
	}
	else
	{
		if (c[i].type == 'checkbox')
		{
		  c[i].checked = false;
		}
	}
  }
}

	
function handleResponse() {
		if(http.readyState == 4){
			var response = http.responseText;
			var update = new Array();

			if (response.indexOf('|' != -1)) {
				update = response.split('|');
				document.getElementById(update[0]).innerHTML = update[1];
				var obj = document.getElementById("valid");
				if(obj != null)
				{
					obj.value = update[2];
				}
			}
		}
	}
	
function ajax_checkemail(email) {		
		http.onreadystatechange = handleResponse;
		http.open('get', '/home/user/checkemail/email/'+email, true);
		http.send(null);		
}

