function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie55=(this.ver.indexOf("MSIE 5.5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6 || this.ie7
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

var bw=lib_bwcheck();

function MM_openBrWindow(theURL,wName,features) { //v2.0
	winName = Math.round((Math.random()*100000))
	window.open(theURL,winName,features);
}

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_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
		else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

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 clear_form(f)
{
	f = document.forms[f];
	for (k=f.elements.length-1;k>=0;k--){
		inputType = f.elements[k].type
		if (inputType == "text") f.elements[k].value = "";
		if (inputType == "select-one") f.elements[k].selectedIndex = 0
	}
}


blankimg = new Image(1,1);
blankimg.src = ('../images/blank.gif');

function getMousePos(e){
	if (!e)
	var e = window.event||window.Event;
	if('undefined'!=typeof e.pageX){
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop;
	}
}

function hover(elID,mouseAction){
	elOBJ = document.getElementById(elID);
	if(mouseAction=='over'){
		elOBJ.className += "_hover";
	}else{
		elOBJ.className  = elOBJ.className.replace("_hover","");
	}
}



function popupWindow(href) {
	uniPop(href, "_blank", 320, 253, 75, 50, 'no', 'no', 'no', 'no');
}

function swapDivs(elm,invert) {
	for(n=1;n<elm.length;n++){
		mydiv = document.getElementById('swap_'+elm[n].value);
		if(elm[n].value && mydiv ) mydiv.style.display=(invert)?'block':'none';
	}
	if(mydiv = document.getElementById('swap_'+elm[elm.selectedIndex].value))
	mydiv.style.display=(invert)?'none':'block';

}


MM_preloadImages(
"http://www.nima.bg/html/images/order1_bg_hover.jpg",
"http://www.nima.bg/html/images/leftpanel_topgraybg_hover.jpg");


$(document).ready(function(){

	$('.hover').hover(function() {
		$(this).addClass('hovered');
	}, function() {
		$(this).removeClass('hovered');
	});

	$(function(){
		$(".hintbox").jHelperTip({
			trigger: "hover",
			source: "attribute",
			attrName: "alt",
			opacity: 0.9,
			topOff: -110,
			leftOff: 10,
			autoClose:true
		});
	});

});



function changecount(type)
{
	$("#bcards_ammount").load("/ajax/ajax_bcchangecount.php", {type: type})
	$("#cvetnostid").load("/ajax/ajax_bcchangecolortypes.php", {type: type})
	$("#bcards_paper_type").load("/ajax/ajax_bcchangepaper.php", {type: type})
	return false;
}
function checkprice(type, count, pechat, lice, gryb, flag)
{

	if(flag == false)
	{
		var lice =0;
		var	gryb = 0;

		$(".front").each(function(){

			if($(this).is(":checked"))
			{
				lice = lice +1;
			}

		})
		$(".back").each(function(){

			if($(this).is(":checked"))
			{
				gryb = gryb +1;
			}

		})

		$("#orderpriceid").load("/ajax/ajax_bccheckprice.php", {type: type, count: count, pechat: pechat, lice : lice, gryb: gryb})
		return false;
	}
	else
	{
		$("#orderpriceid").load("/ajax/ajax_bccheckprice.php", {type: type, count: count, pechat: pechat, lice : lice, gryb: gryb})
		return false;
	}
}
function changeprinttype(type)
{
	$("#printtype_id").load("/ajax/ajax_bcchangeprinttype.php", {type: type})
	return false;
}

function checkcountboxes() {

	var  frontcount = 0;
	var backcount = 0;

	$(".front").each(function(){

		if($(this).is(":checked"))
		{
			frontcount = frontcount +1;
		}

	})
	$(".back").each(function(){

		if($(this).is(":checked"))
		{
			backcount = backcount +1;
		}

	})
	checkprice(document.getElementById('bcards_format').value,
	document.getElementById('bcards_ammount').value ,
	document.getElementById('bcards_print').value,frontcount,backcount, "true");
	//	console.log(frontcount);
	//console.log(backcount);

	return false;
}
function changecolortampon(type)
{
	$("#stamp_company_tampon_color1").load("/ajax/ajax_stchangetampon.php", {type: type});
	$("#stamp_company_tampon_color2").load("/ajax/ajax_stchangetampon.php", {type: type});
	return false;
}
function stcheckprice(type1, type2, tqlo1, tqlo2, count1, count2)
{
	$("#stampprice").load("/ajax/ajax_stcheckprice.php", {type1: type1, type2: type2, tqlo1:tqlo1, tqlo2: tqlo2, count1:count1, count2:count2});
	return false;
}

function changecontent(id)
{
	if(id == true)
	{

		document.getElementById("swap_other").style.display = "none";
		document.getElementById("company").style.display = "block";
	}
	else if(id == false)
	{

		document.getElementById("swap_other").style.display = "block";
		document.getElementById("company").style.display = "none";
	}
	return false;
}
function changepaper(id)
{
	$("#invoice_simple_paper_type").load("/ajax/ajax_invchangepaper.php", {id: id})
	return false;
}
function invcheckprice(type, razmer, broi, kochani)
{

	$("#invprice").load("/ajax/ajax_invcheckprice.php", {type: type, razmer:razmer, broi:broi, kochani:kochani});
	return false;
}
function orderdetails(id)
{
	$(".orders_id").hide();
	$("#tds"+id).show();
	$("#tds"+id).load("/ajax/ajax_orderdetails.php", {id: id});

}
function changedds(id)
{
	if(id=="1")
	{
		document.getElementById("ddsid").style.display = "block";
	} else
	{
		document.getElementById("ddsid").style.display = "none";
	}
}
