var selected;
var submitter = null;

function submitFunction() {
        submitter = 1;
}

function popupWindow(url) {
        window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function selectRowEffect(object, buttonSelect) {
        if (!selected) {
                if (document.getElementById) {
                        selected = document.getElementById('defaultSelected');
                } else {
                selected = document.all['defaultSelected'];
                }
        }

        if (selected) selected.className = 'moduleRow';
        object.className = 'moduleRowSelected';
        selected = object;

        if (document.getElementById('payment'[0])) {
                document.getElementById('payment'[buttonSelect]).checked=true;
        } else {
        }
}

function rowOverEffect(object) {
        if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
        if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function popupImageWindow(url) {
        window.open(url,'popupImageWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function RequestObject_auto() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Ihr Browser unterstoetzt diese Funktion leider nicht.");
	}
}
var num_option_id = new Array();
var num_op_value = new Array();
var product_price = RequestObject_auto();
var option_image_req = RequestObject_auto();
var attribute_id = '';
function checkvalue_dropdown_id(option_id){

	var num_all = document.getElementById('num_all').value;
	var p_id = document.getElementById('p_id').value;
	var check_id = '';
	var selectid = '';
	for(i=0;i<num_all;i++){
		num_op_string = "num_op_name["+i+"]";
		num_option_id[i] = document.getElementById(num_op_string).value;
		id_string = 'id['+num_option_id[i]+']';
		check_id =	check_id+num_option_id[i]+"="+document.getElementById(id_string).value+";";
		if((option_id != null) && (option_id == num_option_id[i])){
			selectid = num_option_id[i]+"="+document.getElementById(id_string).value;
		}
	}
	if(product_price.readyState == 4 || product_price.readyState == 0){
		product_price.open("GET",'product_option_price.php?op_id='+check_id+'&p_id='+p_id, true);
		product_price.onreadystatechange = priceGetResponse;
		product_price.send(null);
	}
	if(selectid != ''){
		if(option_image_req.readyState == 4 || option_image_req.readyState == 0){
			option_image_req.open("GET",'product_option_image.php?p_id='+p_id+'&op_value='+selectid , true);
			option_image_req.onreadystatechange = imageGetResponse;
			option_image_req.send(null);
		}
	}
}

function checkvalue_id(att_id){
	attribute_id = att_id;
	var num_all = document.getElementById('num_all').value;
	var p_id = document.getElementById('p_id').value;
	var num_option;
	check_id = '';
	for(i=0;i<num_all;i++){
		num_op_string = "num_op_name["+i+"]";
		num_option_id[i] = document.getElementById(num_op_string).value; 
		num_op_value_string = "num_op_value["+i+"]";
		num_op_value[i] = document.getElementById(num_op_value_string).value; 
		for(j=0;j<num_op_value[i]; j++){
			check_op_string = "op_value_id["+i+"]["+j+"]";
			option_id = document.getElementById(check_op_string).value;
			id_string = 'id['+num_option_id[i]+']['+option_id+']';
			if(document.getElementById(id_string).checked == true) {
				check_id = check_id+num_option_id[i]+"="+document.getElementById(id_string).value+";";
			}
		}
		
	}

	if(product_price.readyState == 4 || product_price.readyState == 0){
		product_price.open("GET", 'product_option_price.php?op_id='+check_id+'&p_id='+p_id, true);
		product_price.onreadystatechange = priceGetResponse;
		product_price.send(null);
	}
	if(attribute_id != ''){
		if(option_image_req.readyState == 4 || option_image_req.readyState == 0){
			option_image_req.open("GET",'product_option_image.php?p_id='+p_id+'&att_id='+attribute_id, true);
			option_image_req.onreadystatechange = imageGetResponse;
			option_image_req.send(null);
		}
	}
}
function imageGetResponse(){
var result_image = '';
	if(option_image_req.readyState == 4){
		p_id = document.getElementById('p_id').value;
		result_image = option_image_req.responseText;
		if(attribute_id != null){
			document.getElementById('product_option_image').src = result_image;
			if(result_image.indexOf('pixel_trans') == -1){
				var image_link = document.getElementById('img_link').href;
				if(image_link.indexOf("imgID") == -1){
					//for light box
					image_link = document.getElementById('product_option_image').src;
					image_link2 = image_link.replace(/info_images/, "popup_images");
					document.getElementById('img_link').href = image_link2;
					// for light box
				}else{
					image_link2 = image_link.substr(0,image_link.indexOf("imgID=0"));
					image_link2 = image_link2+'imgID=0&att_id='+ attribute_id+"')";
					document.getElementById('img_link').href = image_link2;
				}
			}
			document.getElementById('product_option_image').style.filter="blendTrans(duration=2)";
			document.getElementById('product_option_image').filters.blendTrans.Apply();
			document.getElementById('product_option_image').filters.blendTrans.Play();
		}
	}
}
function priceGetResponse(){
	if(product_price.readyState == 4){
		var result = product_price.responseText;
		document.getElementById('report_price').innerHTML = result;
	}
}

