// begin of init httpresponse
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function MM_findObj(n, d) { //v4.01
	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=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); 
	return x;
}

function MM_validateForm() { //v4.0
	var i,p,q,test,name,num,min,max,errors='',args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) {
		test=args[i+2];
		val=MM_findObj(args[i]);
		if (val) { 
			name=args[i+1];
			if ((val=val.value)!="") {
				if (test.charAt(0) == 'P') { 
					vals=MM_findObj(args[i+3]);				
					if (val != (vals=vals.value)) {
						errors+='- Security No. doesn\'t match Re-Security No.! Please correct\n';
					}
				}
			} else if (test.charAt(0) == 'R') {
				errors += '- '+name+' is required.\n'; 
			} else if (test.charAt(0) == 'P') {
				errors += '- '+name+' is required.\n'; 
			} else if (test.charAt(0) == 'C') { 
				errors += '- '+name+' is required.\n'; 
			}
		}
	} 
	if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
}

function open_sub_menu(id_category,action) {
    if (MM_findObj('parent_list_'+id_category)) {
        if (action == 'open') {
            if (MM_findObj('parent_list_'+id_category).style.display == 'block') {				
				jQuery('#parent_list_'+id_category).hide("normal");
                MM_findObj('parent_'+id_category).className = '';
            } else {
				jQuery('#parent_list_'+id_category).show("normal");				
                MM_findObj('parent_'+id_category).className = 'toggle';
            }
        }
        return false;
    } else {
        return true;
    }
}

function submit_button_form () {
	jQuery('#table_invice').fadeOut('slow'); 
	jQuery('#loading').show();
	setTimeout("document.form.submit();",5000);
}

function open_new_window(id_product,action,name_product) {
    var name_products = 'Empire Style - '+name_product;
    var url = 'big_images.php?product='+id_product;
    var variable = 'toolbar=no,status=no,scrolling=yes,scrollbars=yes,location=no,menubar=no,directories=no,resizable=yes,width=680,height=600';
    window.open(url,name_product,variable);
}

function exchange_to(targ,selObj,restore){ //v3.0
  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  document.exchange.submit();
  //alert (targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function state_change (where,targ,selObj,restore) {
    //alert (targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (selObj.options[selObj.selectedIndex].value == 'USA') {
        MM_findObj(where+'_state').disabled = '';
    } else {
        MM_findObj(where+'_state').disabled = true;
    }
}

function exchange_to_currency(currency) {
    MM_findObj('currency').value = currency;
}

function GetVal(form_name) {
	var a = null;
	var f = document.forms['formBuyProduct'];
	var e = f.elements[form_name];
	for (var i=0; i < e.length; i++) {
		if (e[i].selected) {
			a = e[i].value;
			break;
		}
	}
	return a;
}
function GetSel(form_name, time) {
	var f = document.forms['formBuyProduct'];
	var e = f.elements[form_name];
	for (var i=0; i < e.length; i++) {
		if (e[i].value == time) {
			e[i].selected = 'selected';
		} else {
			e[i].selected = '';
		}
	}
}

function autofield() {
    var billing_country = GetVal('billing_country');
    var billing_first_name = MM_findObj('billing_first_name');
    var billing_last_name = MM_findObj('billing_last_name');
    //var billing_house_number_name = MM_findObj('billing_house_number_name');
    var billing_zip_code = MM_findObj('billing_zip_code');
    var billing_house_number = MM_findObj('billing_house_number');
    var billing_town = MM_findObj('billing_town');
    var billing_contact_number = MM_findObj('billing_contact_number');
    var billing_last_name = MM_findObj('billing_last_name');
    var billing_house_number_name = MM_findObj('billing_house_number_name');
    
    var delivery_country = GetVal('delivery_country');
    var delivery_first_name = MM_findObj('delivery_first_name');
    var delivery_last_name = MM_findObj('delivery_last_name');
    //var delivery_house_number_name = MM_findObj('delivery_house_number_name');
    var delivery_zip_code = MM_findObj('delivery_zip_code');
    var delivery_house_number = MM_findObj('delivery_house_number');
    var delivery_town = MM_findObj('delivery_town');
    var delivery_contact_number = MM_findObj('delivery_contact_number');
    var delivery_last_name = MM_findObj('delivery_last_name');
    var delivery_house_number_name = MM_findObj('delivery_house_number_name');
    
    if (MM_findObj('same_billling').checked == true) {        
        
        GetSel("delivery_country", billing_country);
        if (billing_country == 'USA') {
            MM_findObj('delivery_state').disabled = '';
            var billing_state = GetVal('billing_state');
            GetSel("delivery_state", billing_state);
        } else {
            MM_findObj('delivery_state').disabled = true;
        }
        delivery_first_name.value = billing_first_name.value;
        delivery_last_name.value = billing_last_name.value;
        delivery_zip_code.value = billing_zip_code.value;
        delivery_house_number.value = billing_house_number.value;
        delivery_town.value = billing_town.value;
        delivery_contact_number.value = billing_contact_number.value;
        delivery_last_name.value = billing_last_name.value;
        //delivery_house_number_name.value = billing_house_number_name.value;
        
    } else {
        
        delivery_first_name.value = '';
        delivery_last_name.value = '';
        delivery_zip_code.value = '';
        delivery_house_number.value = '';
        delivery_town.value = '';
        delivery_contact_number.value = '';
        delivery_last_name.value = '';
        //delivery_house_number_name.value = '';
    
    }
}

function image_rollover(image) {	
	temp_name = document[image].name;
	document[image].name = document['main_image'].name;
	document['main_image'].name = temp_name;		
	document[image].src = "/product_images/product/resize_2/" + document[image].name;
	document['main_image'].src = "/product_images/product/resize_1/" + document['main_image'].name;
}	

function new_window(page, name, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open("/zoom.php?prod=" + document['main_image'].name, name, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }		
}
	
function NewWindow(mypage, myname, w, h, sc, s) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+sc+',resizable,status='+s
	return window.open(mypage, myname, winprops)
}
