function payment_recount(x) {this.location.href = "shopping_bag.php?page=payment&my_pay_id=" + x;}
function dispatch_recount(x) {this.location.href = "shopping_bag.php?page=dispatch&my_dispatch_id=" + x;}
function transfer_recount(x) {this.location.href = "shopping_bag.php?page=dispatch&transfer_type=" + x;}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}

function change_order(x)    {this.location.href = x;}
function Zoom(id,type)      {fenster1=window.open('product_zoom.php?id=' + id + '&type=' + type,'Zoom','height=750,width=750,noscrollbars');}
function SizeScale(id)      {fenster1=window.open('size_scale.php','SizeScale','height=460,width=300,noscrollbars');}
function SizeScaleUSA(id)   {fenster1=window.open('size_scale_usa.php','SizeScale','height=600,width=900,noscrollbars');}
function SizeScaleShoes(id) {fenster1=window.open('size_scale_shoes.php','SizeScale','height=390,width=770,noscrollbars');}
function SizeScaleMen(id)   {fenster1=window.open('size_scale_men.php','SizeScale','height=600,width=900,scrollbars');}
function More(id)           {fenster1=window.open('product_more.php?id='+id,'Zoom','height=750,width=750,noscrollbars');}
function Popup(url,w,h,fbox) {
	if((fbox === undefined) || (fbox == false))
		fenster1=window.open(url,'infofenster','height=' + h + ',width=' + w + ',scrollbars');
	else
		$.fancybox({
			'href'	: url,
			'type'      : 'iframe',
			'width'     : w,
			'height'    : h
		});
}
function Popup2(url,w,h,fbox) {
	if((fbox === undefined) || (fbox == false))
		fenster1=window.open(url,'infofenster','height=' + h + ',width=' + w + ',noscrollbars');
	else
		$.fancybox({
			'href'	    : url,
			'type'      : 'iframe',
			'width'     : w,
			'height'    : h
		});
}
function fbox(url,w,h,hidescrollbars, iframe) {
	if((hidescrollbars === undefined) || (hidescrollbars == false)) {
		$.fancybox({
			'href'		: url,
			'width'     : w,
			'height'    : h
		});
	} else {
		if((iframe === undefined) || (iframe == false)) {
			$.fancybox({
				'href'	: url,
				'width'     : w,
				'height'    : h,
				'scrolling' : 'no'
			});
		} else {
			$.fancybox({
				'href'	: url,
				'width'     : w,
				'height'    : h,
				'scrolling' : 'no',
				'type'      : 'iframe'
			});
		}
	}
}
function showhide(name,action) {
	var e=document.getElementById(name);
	e.style.display=(e.style.display==action)?'none':action;
}



function checkOption() {
	for (i = 0; i < document.setSize.reference.length; ++i) {
		if (document.setSize.reference.options[i].selected == true && document.setSize.reference.options[i].value.substring(0,5) == "popup") {
			Popup2(document.setSize.reference.options[i].value,500,300,false);
		} else if (document.setSize.reference.options[i].selected == true && document.setSize.reference.options[i].value.substring(0,4) == "fbox") {
			//open fancy box, delete "fbox" from value
			Popup2(document.setSize.reference.options[i].value.substring(4,document.setSize.reference.options[i].value.length),500,300,true)
		}
	}
}

function checkOption2(myId) {
	myId2 = document.getElementById(myId);
	for (i = 0; i < myId2.length; ++i) {
		if (myId2.options[i].selected == true && myId2.options[i].value.substring(0,5) == "popup") {
			Popup2(myId2.options[i].value,500,300);
		} else if (myId2.options[i].selected == true && myId2.options[i].value.substring(0,4) == "fbox") {
			//open fancy box, delete "fbox" from value
			Popup2(myId2.options[i].value.substring(4,myId2.options[i].value.length),500,300,true)
		}
	}
}

function checkOptionNew() {
	for (i = 0; i < document.setSize.reference.length; ++i) {
		if (document.setSize.reference.options[i].selected == true && document.setSize.reference.options[i].value.substring(0,5) == "popup") {
			iBox.showURL(document.setSize.reference.options[i].value);
		}
	}
}



function showhide2(name,action) {
	var e=document.getElementById(name);
	e.style.display = action;
}
function rowOverEffect(object) {object.className = 'row_active';}
function rowOutEffect(object)  {object.className = 'row_inactive';}

function tI(status)
{
	if(status == 1)
	{
		window.document.getElementById("designerFooter").style.display = "block";
	}
	else
	{
		window.document.getElementById("designerFooter").style.display = "none";
	}
	return false;
}

function fsiviewer_DoFSCommand(fsievent, args) {

	switch (fsievent){

		case "ImageUrl":
			args = args.replace("[template]","Zoom");
			args = args.replace("[width]","800");
			args = args.replace("[height]","1200");
			args = args.replace(/^(.*)&left=(.*)&top=(.*)&right=(.*)&bottom=(.*)&(.*)$/, '$1&$6&quality=80');
			$myclipZoom.attr("href",args);
			break;
	 }
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub fsiviewer_FSCommand(ByVal fsievent, ByVal args)\n');
	document.write('  call fsiviewer_DoFSCommand(fsievent, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

function submitOrder2(text) {
	$.fancybox({
		'content'			: '<div style="width: 400px; height:180px; text-align: center;"><div style="color: #888888; margin-top: 85px;">' + text + '<br/><br/><img src="/grafic/loading.gif" ></div></div>',
		'showCloseButton'   : false,
		'enableEscapeButton': false,
		'hideOnOverlayClick': false,
		'width'				: 400,
		'height'			: 200
	});
}

function checkCoupons() {
    result = true;
    var inputArr = document.getElementById("coupondiv").getElementsByTagName("input");
    multi = 0;
    inputcount = 0;
    var doublecoupon = new Array();
    for(i = 0; i < inputArr.length; i++) {
	if ((inputArr[i].type == "text") && (inputArr[i].value != "")) {
	    inputcount++;
	}
	doublecoupon[i] = false;
    }
    if (inputcount > 1)
	multi = 1;
    //alert(inputcount);

    for(i = 0; i < inputArr.length; i++) {
	if ((inputArr[i].type == "hidden") && (inputArr[i].name == "error")) {
	    result = false;
	} else {
	    //alert(inputArr[i].id);
	    id = inputArr[i].id;
	    id = id.substring(6);
	    value = inputArr[i].value;
	    for (j = 0; j < inputArr.length; j++) {
		//alert (i+":"+j);
		if ((j != i) && (inputArr[j].type == "text")) {
		    if ((inputArr[j].value == inputArr[i].value ) &&(inputArr[j].value != "")) {
			doublecoupon[i] = true;
			doublecoupon[j] = true;
			inputArr[i].setAttribute("class", "newInputError");
			inputArr[j].setAttribute("class", "newInputError");
//			$('#couponresult'+id).load('scripts/ajaxRequest.php?action=checkcoupon&code='+value+'&multi='+multi+'&double=1', function() {
//			});
		    } else {
			doublecoupon[j] = false;
		    }
		}
	    }
	    if (doublecoupon[i])
		doublestr = '&double=1';
	    else
		doublestr = '';

	    //alert('id: '+id+", doublestr: "+doublestr);
	    $('#couponresult'+id).load('scripts/ajaxRequest.php?action=checkcoupon&code='+value+'&multi='+multi+doublestr, function() {
		var inputArr = document.getElementById("coupondiv").getElementsByTagName("input");
		for(i = 0; i < inputArr.length; i++) {
		    if (inputArr[i+1]) {
			if (inputArr[i+1].type == "hidden")
			    inputArr[i].setAttribute("class", "newInputError");
			else
			    inputArr[i].setAttribute("class", "newInput");
		    } else {
			inputArr[i].setAttribute("class", "newInput");
		    }
		}
//		$(".removecoupon").live("click", function() {
//			var c = $(this);
//			var b = c.parent();
//			b.toggle(200, function() {
//				$(this).remove();
//				checkCoupons();
//			});
//		});
	    });
	}
    }
    for(i = 0; i < inputArr.length; i++) {
	if (inputArr[i+1]) {
	    if (inputArr[i+1].type == "hidden")
		inputArr[i].setAttribute("class", "newInputError");
	    else
		inputArr[i].setAttribute("class", "newInput");
	} else {
	    inputArr[i].setAttribute("class", "newInput");
	}
    }
    return result;
}

function checkDelivery (form, error) {
	if (form.billCountryId.value == 0) {
	    form.billCountryId.setAttribute("class", "newInputError");
		alert(error);
		return false;
	}
	return checkCoupons();
}

function checkProductForm(text) {
	var myIndex = document.getElementById("itemReference").selectedIndex;
	if (myIndex == 0) {
		alert(text);
		return false;
	}
	return true;
}
