function just_active_popup()
{
	child_flag = true;
}
function just_inactive_popup()
{
	child_flag = false;
}

function show_pop_up_dialog()
{
	var popup_main = document.getElementById('dialog_pop_up');
	dialog_show = true;
	popup_main.style.display = 'block';
	child_elem = popup_main.childNodes;
	for (i=popup_main.childNodes.length; -- i > -1; )
    {
		popup_main.childNodes[i].onmouseover = just_active_popup;
		popup_main.childNodes[i].onmouseout = just_inactive_popup;
    }
	/*for (i=0; i<child_elem.length; i++)
    {
		child_elem[i].onmouseover = just_active_popup;
		child_elem[i].onmouseout = just_inactive_popup;
	}*/
}

function real_hiding()
{
    if (child_flag)
	return false;
 	var dialog_pop_up = document.getElementById('dialog_pop_up');
    dialog_pop_up.style.display = 'none';
	//dialog_show = false;
}

function hide_pop_up_dialog()
{
    child_flag = false;
 	setTimeout(real_hiding, 500);
}

function show_dialog(param_index)
{
    if (param_index != 'undefined' && param_index >= 1 && param_index <= items.length-1)
    index = param_index;
    if (index < 1 ) { index++; return false; }
	if (index > items.length-1) { index--; return false; }
	document.getElementById('img_in_dialog').src = '';
	document.getElementById('img_in_dialog').src = items[index][0];
	document.getElementById('price_goods').innerHTML = items[index][1];
	document.getElementById('paint_title').innerHTML = 'IN CLOSE UP: ' + items[index][2];
	var size = items[index][3] + 24;
	if (items[index][3] > 382) document.getElementById('dialog').style.width = size + 'px';
		else document.getElementById('dialog').style.width = '382px';
	document.getElementById('dialog').style.display = 'block';

	document.getElementById('dpud_type').innerHTML = items[index][4];
	document.getElementById('dpud_size').innerHTML = items[index][5];
	document.getElementById('dpud_artist').innerHTML = items[index][6];

	document.getElementById('dpud_title').innerHTML = items[index][2];
	document.getElementById('dpud_price').innerHTML = items[index][1];
}
function close_dialog()
{
	document.getElementById('dialog').style.display = 'none';
	return false;
}

function getWinSize(){
 var xScroll, yScroll, windowWidth, windowHeight, b = document.body, de = document.documentElement;
 if (window.innerHeight && window.scrollMaxY) {
  xScroll = b.scrollWidth;
  yScroll = window.innerHeight + window.scrollMaxY;
 } else if (b.scrollHeight > b.offsetHeight){ // all but Explorer Mac
  xScroll = b.scrollWidth;
  yScroll = b.scrollHeight;
 } else if (de && de.scrollHeight > de.offsetHeight){ // Explorer 6 strict mode
  xScroll = de.scrollWidth;
  yScroll = de.scrollHeight;
 } else { // Explorer Mac...would also work in Mozilla and Safari
  xScroll = b.offsetWidth;
  yScroll = b.offsetHeight;
 }

 if (self.innerHeight) { // all except Explorer
  windowWidth = self.innerWidth;
  windowHeight = self.innerHeight;
 } else if (de && de.clientHeight) { // Explorer 6 Strict Mode
  windowWidth = de.clientWidth;
  windowHeight = de.clientHeight;
 } else if (b) { // other Explorers
  windowWidth = b.clientWidth;
  windowHeight = b.clientHeight;
 }

 // for small pages with total height less then height of the viewport
 var pageHeight = yScroll < windowHeight? windowHeight : yScroll;

 // for small pages with total width less then width of the viewport
 var pageWidth = xScroll < windowWidth? windowWidth : xScroll;

 //return [pageWidth,pageHeight,windowWidth,windowHeight]
 return windowHeight;
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

if (name=='show_perpage')
path = '/';

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
 // first we'll split this cookie up into name/value pairs
 // note: document.cookie only returns name=value, not the other components
 var a_all_cookies = document.cookie.split( ';' );
 var a_temp_cookie = '';
 var cookie_name = '';
 var cookie_value = '';
 var b_cookie_found = false; // set boolean t/f default f

 for ( i = 0; i < a_all_cookies.length; i++ )
 {
  // now we'll split apart each name=value pair
  a_temp_cookie = a_all_cookies[i].split( '=' );


  // and trim left/right whitespace while we're at it
  cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

  // if the extracted name matches passed check_name
  if ( cookie_name == check_name )
  {
   b_cookie_found = true;
   // we need to handle case where cookie has no value but exists (no = sign, that is):
   if ( a_temp_cookie.length > 1 )
   {
    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
   }
   // note that in cases where cookie is initialized but no value, null is returned
   return cookie_value;
   break;
  }
  a_temp_cookie = null;
  cookie_name = '';
 }
 if ( !b_cookie_found )
 {
  return null;
 }
}


function show_hide_wishlist(maximize_str, minimize_str)
{
 wishlist_div = document.getElementById('wishlist');
 if (wishlist_div != null)
 {
  if (wishlist_div.style.display != 'block')
  {
    $("#wishlist").slideDown("medium");
    Set_Cookie('max_wishlist', 1, 0, "/");
    $("#bottom_line_div").css("padding","0 0 162px 0");
    //$("a.wishlist_button").css("background-position", "bottom left");
    $(".wishlist_out_button").css("background-position", "bottom left");
    $("a.wishlist_button").html(minimize_str);
  }
  else
  {
    $("#wishlist").slideUp(1000);
    Set_Cookie('max_wishlist', 0, 0, "/");
    $("#bottom_line_div").css("padding","0 0 0 0");
    //$("a.wishlist_button").css("background-position", "bottom right");
    $(".wishlist_out_button").css("background-position", "top left");
    $("a.wishlist_button").html(maximize_str);
  }
 }
}

function show_wishlist(minimize_str)
{
 wishlist_div = document.getElementById('wishlist');
    //$("#wishlist").css("display", "block");
    $("#wishlist").slideDown("medium");
    Set_Cookie('max_wishlist', 1, 0, "/");
    $("#line_footer").css("padding","0 0 130px 0");
    //$("#frame").css("margin","0 0 120px 0");
    $("#show_hide_wishlist > a").css("background-position", "top right");
    $("#show_hide_wishlist > a").html(minimize_str);
}

function add_to_wishlist(productid)
{
    $("#wishlist").load("/wishlist/add/"+productid, '',
        function(){
        });
    wishlist_div = document.getElementById('wishlist');
	if (wishlist_div.style.display != 'block')
    show_hide_wishlist("Open", "Hide");
}

function remove_from_wishlist(productid)
{
    $("#wishlist").load("/wishlist/remove/"+productid, '',
        function(){
        });
}
function tell_a_friend()
{
    $.blockUI({ message: $('#tell_a_friend_container')});
}
function check_contactus_form()
{
    //$("#register_form").
    
    if (requiered_field(document.forms["contactus"].name) &&
        requiered_field(document.forms["contactus"].email) &&
        requiered_field(document.forms["contactus"].message) &&
        requiered_field(document.forms["contactus"].captcha) &&
        checkEmailAddress(document.forms["contactus"].email)
        )
    document.forms["contactus"].submit();
    else 
    {
	alert('Please check required fields');
	return false;
    }
}
function requiered_field(field)
{
    if (field.value == '')
    {
        field.focus();
        field.select();
        return false;
    }
    else
    return true;
}

function checkEmailAddress(field) {
    var goodEmail = field.value.search(/^[^\.]*[A-Za-z0-9_\-\.]*[^\.]\@[^\.][A-Za-z0-9_\-\.]+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.info)|(\.biz)|(\.us)|(\.bizz)|(\.coop)|(\..{2,2}))[ ]*$/gi);

    if (goodEmail!=-1) 
    {
        return true;
    }
    else 
    {
        alert("E-mail address is invalid! Please correct.");
        field.focus();
        field.select();
        return false;
    }
}
function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}
function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}