function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

var box_info = new Array();
    box_info['boxlive'] = new Array();

function change_box_init (box_stop) {
    box_info['boxlive'][0] = 1;
    box_info['boxlive'][1] = box_stop;
    box_info['boxlive'][2] = 1;
    setTimeout("change_box('boxlive')", 8000);
}

function change_box (witch) {
    var cur = box_info[witch][2];
    var last = cur;
    if (box_info[witch][1] < cur+1) {
        cur                     = box_info[witch][0];
    } else {
        cur++;
    }
    box_info[witch][2] = cur;
    showHideLayers('productboxlive'+last,'','hide');
    showHideLayers('productboxlive'+cur,'','show');
    setTimeout("change_box('"+witch+"')", 8000);
}

function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function showHideLayers() { //v3.0
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }
    obj.display=v; }
}
function showHideDiv() {
  var i,p,v,obj,args=showHideDiv.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='block')?'block':(v='none')?'none':v; }
    obj.display=v; }
}

function showHideThis(_myarr, showThis) {
    var myarr = _myarr.split(',');
    for (var i = 0; i < myarr.length; i++) {
        if (showThis == myarr[i]) {
            showHideDiv(showThis, '', 'block');
        } else {
            showHideDiv(myarr[i], '', 'none');
        }
    }
}

function submit_this_form(form_id) {
    var tag_elements = document.getElementsByTagName('form');

    for (var i = 0; i < tag_elements.length; i++) {
        var tag_element = tag_elements[i];
        if (form_id == tag_element.id
        ) {
            return tag_element.submit();
        }
    }
}


function displayview(myid) {
    
    switch(myid){
        case 1:
            if(productprevflash != 'no_flash' && swfobject.hasFlashPlayerVersion("9.0.0")){
                $('#productprevimg0').hide();
                $('#viewportcontrol h3').hide();
                $('.map-control').hide();
                swfobject.embedSWF("_media/product/player_product.swf?_p="+productprevflash, "productprevflash", "408", "290", "9.0.0", "expressInstall.swf");
                $('#productprevflash').show();
                break;
            }
        default:
            $('#productprevimg0').show();
            $('#viewportcontrol h3').show();
            $('.map-control').show();
            $('#productprevflash').hide();
    if (obj = findObj('productprevimg0')) {
        obj.style.background = 'url('+productprevimg[myid]+'&w=315)';
    }

    if (obj = findObj('productprevimg1')) {
        obj.src = productprevimg[myid]+'&w=722';
    }

    if (obj = findObj('productprevimg2')) {
        obj.src = productprevimg[myid]+'&w=1444';
    }
        break;
    }
}

function PopMeUp (theUrl, winName, features) {
    window.open(theUrl, winName, features);
}
