var default_value = 'enter your E-mail address';
var error_email   = 'Incorrect E-mail address format';
var subs_passed   = 'Your email address has been added to our mailing list';
var subs_failed   = 'Error occurs during subsription. Please try again';
var user_exists   = 'User with specified email already registered. Plese specify new email';

function subscribtion(default_value, error_email, subs_passed, subs_failed, user_exists, origin)
{
	var regex = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;


			if (!regex.test($('#email_subs').attr('value'))) 
			{
    			alert(error_email);
			}	
			else
			{
			    $.ajax({
			        type: "GET",        
			        url:  site_rel +  '/pub/user_add.php?email='+$('#email_subs').attr('value')+'&origin='+origin,
			        success: function(data){
						if (2 == data)
			    		{
							alert(user_exists);
			    		}
						else if (1 == data)
						{
							alert(subs_failed);
						}
						else 
						{
							alert(subs_passed);
							$('#email_subs').attr('value','');
						}
			        }        
			    });				
			}

}


function submitByImage(pfrm, action)
{
	var obj = document.getElementById(pfrm);
	obj.action = action;
}


function expandBlock(block_id)
{
	var good = false;
	ul = document.getElementById(block_id);
	if (good = (ul != null && ul.className != null && ul.innerHTML != null)) 
	{
		if ((ul.className == "visible") || (ul.className == ""))
		{
			ul.className = "hidden";
		}
		else
			if (ul.className == "hidden")
			{
				ul.className = "visible";
			}
	}
	return true;
}

function expandBlockEx(block_id, image_id)
{
	expandBlock(block_id);
	
	var good = false;
	ul = document.getElementById(image_id);
	if (good = (ul != null && ul.className != null && ul.innerHTML != null)) 
	{
		var str = ul.src;
		var new_str = str.replace(/icon_top.gif/, "icon_right.gif");
		
		if (new_str == str)
			 ul.src = str.replace(/icon_right.gif/, "icon_top.gif");
		else
			  ul.src = new_str;
	}
	
	return true;
}

function ClearItem(caller)
{
	document.getElementById(caller).value = '';
	
}


var d = document;
var winIE = (navigator.userAgent.indexOf("Opera")==-1 && (d.getElementById &&  d.documentElement.behaviorUrns))  ? true : false;

function wo(link,ww,hh,title)
{
        ww = ww ? ' width='+ww+' ' : ' width=700 ';
        hh = hh ? ' height='+hh+' ' : ' height=500 ';
        w=window.open(link,'',(ww)+', '+(hh)+', toolbar=0,scrollbars=0,resizable');
        if (link.indexOf('.html')==-1)
		{
                if (document.layers) title='';
				
               w.document.open();
			   //w.document.write('&lt;html&gt;rewtt&lt;html/&gt;');

                w.document.write('<html><head><title>'+title+'<\/title>');
                w.document.write('<meta http-equiv=Content-Type content="text/html; charset=windows-1251"><\/head>');
                w.document.write('<body bgcolor=white marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>');
				w.document.write('<table width=100% height=100% border=0 cellspacing=0 cellpadding=0><tr><td align=center>');
				w.document.write('<img src='+link+' border=0 alt=""><\/td><\/tr><\/table><\/body><\/html>'); 
                w.document.close();
        }
        w.focus();
}   



function bodySize(){
	if(winIE && document.documentElement.clientWidth && document.getElementById("minWidth")) {
		sObj = document.getElementById("minWidth").style;
		sObj.width = (document.documentElement.clientWidth<=1000) ? "1000px" : "100%";
	}
}

function init(){
	if(winIE) { bodySize(); }
 }
 
onload = init;

if(winIE) { onresize = bodySize; }

function copyShippingAddress() {
    $("input[@type='text']").each(function(){
        var b_id = 'b_' + this.id;
        if ($("#" + b_id).length > 0) {
            $("#" + b_id).attr("value", this.value);
        }
    });
}


