/*ok*/
function ajaxlogin(loginUrl, productUrl){
	
	pass = $("ajaxpass").value;
	email = $("ajaxemail").value;
	new Ajax.Request(loginUrl, {
		method: 'post',
  		parameters: {'login[password]': pass, 'login[username]': email},
  		onLoading: function(transport){
  			$('user-login').hide();
  			Element.show('loadingmaskhorizontal');
  		},
   		onSuccess: function(transport){
   			 if(transport.responseText.match('<ajaxlogintag tag="4"/>')){
				response = '<iframe id="remote-add-to-cart" src ="' + productUrl + '" width="100%" height="60px" frameborder="0" scrolling="auto"></iframe>';
				$('user-addtocart').update(response);
				Element.hide('loadingmaskhorizontal');
				toggleTopLinks('top-links-signin','Sign Out', '/customer/account/logout/');
   			 }else{
   			 	Element.hide('loadingmaskhorizontal');
   			 	$('user-login').show();
				message_error = '<strong>Invalid login or password.</strong>';
				$('login-error').update(message_error);
   			 }
   		
    }
    });
}

/*ok*/
var state_login = 0;
function showPanel(product_link, product_name, product_image, login){

	var image = '<img src="' + product_image + '"/>';
	$('grid-atc-image').update(image);
	var name = '<h3>' + product_name + '</h3>';
	$('grid-atc-name').update(name);
	if(login == '1' || state_login == 1){
		Element.show('loadingmaskhorizontal');
		$('user-crossroads').hide();
		response = '<iframe id="remote-add-to-cart" src ="' + product_link + '" width="100%" height="82px" frameborder="0" scrolling="auto"></iframe>';
		$('user-addtocart').update(response);
		Element.hide('loadingmaskhorizontal');
	}else{
		if(login == '2'){
			$('not-show').hide();
		}else{
			$('ajaxproductidurl').value = product_link;
		}
		
	}
	$('loadingmask').show();
}


function ajaxloginpanel(loginUrl){
	pass = $("ajaxpass").value;
	email = $("ajaxemail").value;
	pruductidurl = $("ajaxproductidurl").value;
	
	new Ajax.Request(loginUrl, {
		method: 'post',
  		parameters: {'login[password]': pass, 'login[username]': email},
  		onLoading: function(transport){
  			$('user-login').hide();
  			Element.show('loadingmaskhorizontal');
  		},
   		onSuccess: function(transport){
   			 if(transport.responseText.match('<ajaxlogintag tag="4"/>')){
   			 	state_login = 1;
   			 	toggleTopLinks('top-links-signin','Sign Out', '/customer/account/logout/');
				response = '<iframe id="remote-add-to-cart" src ="' + pruductidurl + '" width="100%" height="82px" frameborder="0" scrolling="auto"></iframe>';
				$('user-addtocart').update(response);
				Element.hide('loadingmaskhorizontal');
   			 }else{
   			 	Element.hide('loadingmaskhorizontal');
   			 	$('user-login').show();
				message_error = '<strong>Invalid login or password.</strong>';
				$('login-error').update(message_error);
   			 }
   		
    }
    });
}

/*ok*/
function toggleTopLinks(id, text, link){
	var item_menu = $(id).firstChild;
	item_menu.innerHTML = text;
	item_menu.setAttribute('href', link);
}

function ajax_getProductpart(reloadurl){
	Element.show('loadingmask');
	new Ajax.Request(reloadurl, {
		method: 'get',
		onSuccess: process,
		onFailure: function() {
			message_error = '<strong>Invalid login or password.</strong>';
			$('login-error').update(message_error);
			Element.hide('loadingmask');
	    }
	});
}


function process(transport) {
  var response = transport.responseText;
  	$('user-login').hide();
	Element.hide('loadingmask');
	response = '<iframe src ="html_intro.asp" width="100%" height="262">' + response + '</iframe>';
	$('user-addtocart').update(response);
}


window.resizeiframe1 = function(height){
	document.getElementById('remote-add-to-cart').style.height=(height)+'px';
}




