function check_empty_field (ff,val,ntype) {
    if ( ff.value == val )
    {
        ff.value='';
        try
        {
            ff.type=ntype;
        }
        catch (err) {
        /* special IE routine - cause type substitution does not work... */
            var input2= ff.cloneNode(false);
            input2.type='password';
            ff.parentNode.replaceChild(input2,ff);
        }
    }
}

function pz_submit_article()
{
    var i=0;
    for ( i=0;i < document.getElementsByName("Auflage").length;i++)
    {
        try
        {
            if ( document.getElementsByName("Auflage")[i].checked == true )
            {
                document.getElementsByName("Auflage")[i].name = document.getElementsByName("Auflage")[i].id;
            }
        } catch (err) {}
    }
    document.getElementById('article_form').submit();
}

function show_pi(oEvent,id) {
/*	document.getElementById('tile_pi_' + id).style.left=(oEvent.clientX+20) + "px";
	document.getElementById('tile_pi_' + id).style.top=(oEvent.clientY-100) + "px"; */
	document.getElementById('tile_pi_' + id).style.display='block';
}
function hide_pi(id) {
	document.getElementById('tile_pi_' + id).style.display='none';
}

function switch_display(id,href) {
	if (document.getElementById(id).style.display=='block')
	{
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(id).style.display='block';
		if ( href )
		{
			window.location.hash=href;
			window.location.hash=href + "_s";
		}
	}
}
                                
function switch_show_class (a,b) {
    if (a.checked)
    {
        document.getElementById(b).style.display="block";
        a.checked="checked";
    }
    else
    {      
        document.getElementById(b).style.display="none";
        a.checked="";
    }
}

function switch_tr_show (a) {
    if (document.getElementById(a).style.display == "none")
    {
        document.getElementById(a).style.display="table-row";
    }
    else
    {
        document.getElementById(a).style.display="none";
    }
}

var tr_r_show = "none";

function switch_tr_rs () {
    var i=0;
    if ( tr_r_show == "none" )
    {
        tr_r_show = "table-row";
    }
    else
    {
        tr_r_show = "none";
    }
    
    var ok=0;
    do
    {
        i++;
        try
        {
            if ( document.getElementById("tr_" + i) )
            {
                document.getElementById("tr_" + i).style.display=tr_r_show;
            }
            else
            {
                ok = 1;
            }
        }
        catch (err)
        {
            ok=1;
        }
    } while( ok == 0 );
}


/* This is for CC-Paymentsystem 
 * The content (po_data) will be filled dynamicly by template.
 */

var po_data = new Object;
var po_old_submit_value;

var po_options = {
    return_type : 'object',
    callback_function_name : 'processPayoneResponse'
}

function processPayoneResponse(response) {
    if (response.get('status') == 'APPROVED') {
        document.paymentform.cardpan.value='';
        document.paymentform.cardcvc2.value='';
        document.paymentform.pseudocardpan.value=response.get('pseudocardpan');
        document.paymentform.txid.value=response.get('txid');
        document.paymentform.userid.value=response.get('userid');
        document.paymentform.transaction_status.value=response.get('status');
        document.paymentform.submit();
    }
    else if (response.get('status') == 'REDIRECT') {
        window.location.href=response.get('redirecturl');
    }
    else
    {
        document.getElementById('paymentform_div').innerHTML='<p class="fehler">' + response.get('customermessage') + '</p>';
        document.getElementById('paymentform_div').style.display='block';
        document.paymentform.submitbutton.disabled="";
        document.paymentform.submitbutton.value=po_old_submit_value;
    }
}

/* End Paymentsystem */

var upload_id_status = new Array;
var forms_to_upload = new Array;
var is_multi_upload = false;

function single_upload (my_id)
{
	if ( document.getElementById(my_id).value != '' )
	{
		upload_id_status[my_id] = setTimeout("check_upload_status('" + my_id + "')",500);
		document.forms['form_' +my_id].submit();
	}
	else
	{
	    multi_upload(forms_to_upload);
	}
}

function upload_all ()
{
    document.getElementById('upload_button').disabled=1;
    document.getElementById('upload_button').innerHTML='Bitte warten...';
	var i;
	for (i=0;i<=document.getElementsByName("upload_field").length-1;i++)
	{
		try
		{
			var b=document.getElementsByName("upload_field")[i].parentNode.attributes["action"].value.match(/^(.+)\..+$/);
			is_multi_upload=true;
			if (b[1] == "upload")
			{
				var id=document.getElementsByName("upload_field")[i].parentNode.attributes["id"].value.match(/^form_(.+)$/);
				forms_to_upload.push(id[1]);
			}
		} catch (err) { }
	}
	multi_upload();
}

function multi_upload ()
{
    if ( forms_to_upload.length == "0" )
    {
    	var uri=document.URL;
    	window.document.location = uri + "&success=true";
    }
    try
    {
        var id = forms_to_upload[0];
        forms_to_upload.splice(0,1);
    	single_upload(id,true);
    } catch (err) {}
}

function check_upload_status (my_id)
{
	var params = new Object;
	params.section = 'get_upload_status';
	params.id=my_id;
	
	var f = xml_request_post("/customer/upload.fcgi",params,true,set_upload_status);
}

function set_upload_status(x)
{
	try
	{
	    try
	    {
		    document.getElementById( 'status_' + x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue + '_fill' ).style.width = x.getElementsByTagName("root")[0].getElementsByTagName("status")[0].firstChild.nodeValue + "px";
		} catch (err) {}
        try
        {
            document.getElementById( 'status_' + x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue + '_box').innerHTML = x.getElementsByTagName("root")[0].getElementsByTagName("msg")[0].firstChild.nodeValue ;
        } catch (err) {}
		
		
		if ( x.getElementsByTagName("root")[0].getElementsByTagName("finished")[0].firstChild.nodeValue == "false" )
		{
			upload_id_status[x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue] = setTimeout("check_upload_status('" + x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue + "')",500);
		}
		else
		{
			if ( x.getElementsByTagName("root")[0].getElementsByTagName("status")[0].firstChild.nodeValue == "-2" )
			{
				document.getElementById( 'status_' + x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue + '_box').innerHTML = x.getElementsByTagName("root")[0].getElementsByTagName("msg")[0].firstChild.nodeValue;
			}
			else
			{
			    
				document.forms['form_' + x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue ].reset();
				setTimeout('adi_reload(\'prev_img_' + x.getElementsByTagName("root")[0].getElementsByTagName("id")[0].firstChild.nodeValue + '\')', 5000);
				if ( is_multi_upload == true )
				{
					multi_upload(forms_to_upload);
				}
			}
		}
		
	} catch (err) {}
}

function disporders_show_pos (id)
{
	if ( document.getElementById(id).style.display == 'none' )
	{
		document.getElementById(id).style.display = '';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
	}
}

function myhide(id)
{
    document.getElementById(id).style.display='none';
}

function adi_reload(id)
{
    var o=document.getElementById(id);
    var a = o.src;
    o.src='/icons/' + shop_sub_dir + '/blank.gif';
    setTimeout("document.getElementById('" + id + "').src='" + a + "&a=a'",50);
//    o.src=a;
}

/* Start general functions */
function xml_request (dname,async_var)
{
    var x;
    var async_bool = false;
    if ( async_var )
    {
        async_bool = async_var;
    }
    
    if (window.XMLHttpRequest) {
        xmlDoc = new window.XMLHttpRequest();
        xmlDoc.open("GET", dname, async_bool);
        xmlDoc.send("");
        if ( xmlDoc.status != 200 )
        {
            alert ("There was an communication Error. Pleasy try again later...");
        }
        x = xmlDoc.responseXML;
    }
// IE 5 and IE 6
    else if (ActiveXObject("Microsoft.XMLDOM")) {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = async_bool;
        xmlDoc.load(dname);
        x = xmlDoc;
    }
    return x
}

function xml_request_post (dname,params,async_var,async_func)
{
    var x;
    var async_bool = false;
    if ( async_var )
    {
        async_bool = async_var;
    }
    
    xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX! Working with our shop will not work. Please contact our support.");
		return;
	}
//Send the proper header information along with the request
	xmlHttp.async=async_bool;
	
	// prepare the MIME POST data
	var boundaryString = 'bp';
	var boundary = '--' + boundaryString;
	
	var postContent = '\r\n';
	
	for ( var item in params )
	{
	    postContent += boundary+'\r\n'+
          'Content-Disposition: form-data; name="' + item + '"\r\n'+
          'Content-Type: application/octet-stream\r\n'+
          "\r\n"+
          params[item] + "\r\n"; 
	}
	postContent += boundary+"\r\n";
	// do the AJAX request
	if ( async_bool == true )
	{
	
    	if (typeof(xmlHttp.onprogress)=='object')
    	{
            xmlHttp.onload = function()
            {
                if (window.XMLHttpRequest) {
                    x = xmlHttp.responseXML;
                } else if (ActiveXObject("Microsoft.XMLDOM")) {
                    x = xmlHttp;
                }
                eval(async_func)(x);
            }
        } else {
            xmlHttp.onreadystatechange = function()
            {
                if (xmlHttp.readyState == 4)
                {
                    if (window.XMLHttpRequest) {
                        x = xmlHttp.responseXML;
                    } else if (ActiveXObject("Microsoft.XMLDOM")) {
                        x = xmlHttp;
                    }
                    eval(async_func)(x);
                }
            };
    	}
    }
    
	xmlHttp.open('POST', dname, false);
	xmlHttp.setRequestHeader("Content-Type", "multipart/form-data; boundary=\"" + boundaryString + "\";charset=UTF-8");
	xmlHttp.setRequestHeader("content-length", postContent.length);
	xmlHttp.send(postContent);
    
    if ( async_bool == false )
    {
    	if (window.XMLHttpRequest)
    	{
            x = xmlHttp.responseXML;
        } else if (ActiveXObject("Microsoft.XMLDOM"))
        {
            x = xmlHttp;
        }

        if ( xmlHttp.status != 200 )
        {
        	alert ("Communication Error. Please try later...");
        }
    }

    
    return x
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

/* End general Functions */


