
/**************************************************
* dom-drag.js
* 09.25.2001
* www.youngpup.net
* Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
**************************************************
* 10.28.2001 - fixed minor bug where events
* sometimes fired off the handle, not the root.
**************************************************/


function openpopups(){
	var winpops=window.open("http://www.sancy.se/welcome.html","","width=300,height=300,resizable")
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadornot(){
	if (get_cookie('jkpopup')==''){
		openpopups()
		document.cookie="jkpopup=yes"
	}
}



var Drag = {
	obj : null,
	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;
		o.root = oRoot && oRoot != null ? oRoot : o ;
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},
	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;
		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}
		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		return false;
	},
	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;
		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)
		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;
		Drag.obj.root.onDrag(nx, ny);
		return false;
	},
	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
		parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},
	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};





function doTextSearch()
{
	query = document.getElementById("TextSearchBox");
	top.location.href = "/system/search/search.asp?q="+ query.value;
}
function ImageObj (_a,_b,_c)
{
	Img=new Object();
	Img.imagepath = _a;
	Img.imagedesc = _b;
	Img.thumbnail = _c;
	return Img;
}

function showPic (whichpic) 
{
	if (document.getElementById) 
	{
		document.getElementById('productimagebig').src = whichpic;
		return false;
	} 
	else 
	{
		return true;
	}
}

function printImages()
{
	this.TotalImages=imagearr.length;
	this.CurrentImage=0;
	this.ImagePosition=0;
	this.swap=Fswap;

	if(TotalImages>0)
	{
		if(TotalImages>1)
			document.write("<div style='position:relative;width:400px;height:400px;'><a href='javascript:this.swap(0)'>");

		document.write("<img border='0'  id='imagecontainer' src='"+ imagearr[0].imagepath +"'>");

		if(TotalImages>1)
			document.write("</a></div>");
		
		document.write("<div id='imagedesc' style='width:400px;'>"+unescape(imagearr[0].imagedesc)+"</div>")

	}
}

function ImageObj2 (_a,_b,_c,_d)
{
	Img=new Object();
	Img.imagepath = _a;
	Img.imagedesc = _b;
	Img.thumbnail = _c;
	Img.original = _d;
	return Img;
}

function printImages2()
{
	this.TotalImages = imagearr.length;
	this.CurrentImage = 0;
	this.ImagePosition = 0;
	this.swap = Fswap2;

	if(TotalImages > 0)
	{
		document.write("<div id='imagecontainer2'><a href='"+ imagearr[0].original +"' title='"+ unescape(imagearr[0].imagedesc) +"' id='href_image_source' class='thickbox'><img border='0' id='product_image' src='"+ imagearr[0].imagepath +"'></a>");

		if (TotalImages > 1)
		{
			document.write("<div id='pic_detail_container'><p class='pic_detail_text'>Klicka för större bild:</p>");
			for(i=0; i < TotalImages; i++)
			{
				document.write("<p class='pic_detail'><a href='javascript:this.swap("+(i+1)+")'><img border='0' src='"+ imagearr[i].thumbnail +"' /></a></p>");
			}
			document.write("</div><!-- End pic_detail_container -->");
		}
		document.write("</div><!-- End Imagecontainer -->");
	}

}

function Fswap2(_id)
{
	if(!_id)
	{
		if(this.ImagePosition >= this.TotalImages-1)
			this.ImagePosition = 0;
		else
			this.ImagePosition++;
	}
	else
	{
		this.ImagePosition= _id > 0 ? (_id-1):this.ImagePosition;
	}
	imagedescok = unescape(imagearr[this.ImagePosition].imagedesc).replace(/^\s*/,  '').replace(/\s*$/, '');
	document.getElementById("product_image").src = imagearr[this.ImagePosition].imagepath;
	document.getElementById("href_image_source").title = unescape(imagearr[this.ImagePosition].imagedesc);
	document.getElementById("href_image_source").href = imagearr[this.ImagePosition].original;
}

function printDImages()
{
	this.TotalImages=imagearr.length;
	this.CurrentImage=0;
	this.ImagePosition=0;
	this.swap=Dswap;

	if(TotalImages>0)
	{
		if(TotalImages>1)
			document.write("<div id='imagecontainer3'><a href='javascript:this.swap(0)'>");

		document.write("<img border='0' id='product_image' src='"+ imagearr[0].imagepath +"'>");

		if(TotalImages>1)
			document.write("</a></div>");
		
		document.write("<div id='imagedesc' style='width:400px;'>"+unescape(imagearr[0].imagedesc)+"</div>")

	}
}
function Dswap(_id, shape)
{
	if(!_id)
	{
		if(this.ImagePosition >= this.TotalImages-1){
			this.ImagePosition = 0;
			document.getElementById("floater").style.top = 85;		
			document.getElementById("floater").style.left = 170;
			document.getElementById("floaterimg").src = "/images/site/diamond-test-R.gif";		
	
			
		}else{
			this.ImagePosition++;
			document.getElementById("floater").style.top = 30;
			document.getElementById("floater").style.left = 160;
			document.getElementById("floaterimg").src = "/images/site/diamond-test-R-side.gif";				
		}
	}
	else
	{
		this.ImagePosition= _id > 0 ? (_id-1):this.ImagePosition;
	}
	imagedescok = unescape(imagearr[this.ImagePosition].imagedesc).replace(/^\s*/,  '').replace(/\s*$/, '');
	document.getElementById("imagecontainer2").src = imagearr[this.ImagePosition].imagepath;
}
	
function Fswap(_id)
{
	if(!_id)
	{
		if(this.ImagePosition >= this.TotalImages-1)
			this.ImagePosition = 0;
		else
			this.ImagePosition++;
	}
	else
	{
		this.ImagePosition= _id > 0 ? (_id-1):this.ImagePosition;
	}
	imagedescok = unescape(imagearr[this.ImagePosition].imagedesc).replace(/^\s*/,  '').replace(/\s*$/, '');
	document.getElementById("imagecontainer").src = imagearr[this.ImagePosition].imagepath;
}



function gotoEmail(_email){
	document.location = '/system/pb/email.asp?email=' + document.getElementById("tipsmail").value;
}
function gotoNewsletter(_email){
	document.location = '/system/user/newsletter_save.asp?email=' + document.getElementById("newsletter").value;
}
function dotextsearch()
{
	top.location.href='/system/search/text_search.asp?q='+ document.getElementById("textsearchbox").value
}
function open_xml_edit()
{
	matrix_window = window.open("matrix.asp", "matrix", "status=yes,scrolling=yes,width=400,height=400");
}
function validate_form(id)
{
		var formObj = document.forms[id];
		if(formObj.address && !isValidString(formObj, "address", 2))
		{
			alert("Vänligen kontrollera din adress.")
		}
		else if(formObj.zip && !isValidString(formObj, "zip", 3))
		{
			alert("Vänligen kontrollera ditt postnummer.")
		}
		else if(formObj.city && !isValidString(formObj, "city", 2))
		{
			alert("Vänligen kontrollera angiven ort.")
		}
		else if(formObj.phone && !isValidString(formObj, "phone", 5))
		{
			alert("Vänligen ange ditt telefonnummer.")
		}
		else
		{
			submit_form(id)			
		}
}

function confirm_del(msg, url)
{
	if(confirm(msg))
		location.href = url;
}

function chk(fid)
{
	if(validate(document.forms[fid]))
   	submit_form(fid)
}

function validate(formObject)
{
	if(document.getElementById("branchid").value<1)
	{
		alert("Du har inte valt någon smyckeskategori.");
		return false;
	}
	return true;
}
	
	
function chk_form(_form, msg)
{
	if(!msg){
		var msg = new String("Du har inte valt storlek.")
	}
	form = document.forms[_form];
	if(this.form.size)
	{
		if(this.form.size.value != 0)
		{
			this.form.submit();
		}
		else
		{
			alert(msg);
		}
	}
}



function CheckAll(formObj)
{
	for (var i=0;i<formObj.elements.length;i++)
	{
		var e = formObj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
			e.checked = !e.checked
	}
}

function checkKey(e, func)
{
	if(e.keyCode == 13)
		eval(func);
}

function open_login(str, url)
{
	if(confirm(str))
		location.href = url;
}

function open_print(url, page, query)
{
	if(query)
		query = "&"+query;

	var y = 100;
	var x = (screen.availWidth - 680) / 2;
	new_win = window.open(url+"?printpage="+escape(page)+query,'rootwin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes, top='+y+',screenY='+y+',left='+x+',screenX='+x)
	new_win.resizeTo(680, screen.availHeight-200);
}

function open_popup(url, handler, w, h)
{
	var wa = screen.Width;
	var ha = screen.Height;
	ha = (ha/2)-(h/2)
	wa = (wa/2)-(w/2)
	if(parent.wHander)
	{
		var handler = parent.wHandler;		
	}
	else
	{
		var handler
	}
	handler = window.open(url, handler ,'width='+w+',height='+h+',location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status=yes,top='+ha+',left='+wa);
	handler.focus();

}

function open_popup_noscroll(url, handler, w, h)
{
	var wa = screen.Width;
	var ha = screen.Height;
	ha = (ha/2)-(h/2)
	wa = (wa/2)-(w/2)
	if(parent.wHander)
	{
		var handler = parent.wHandler;		
	}
	else
	{
		var handler
	}
	parent.wHandler = window.open(url, handler ,'width='+w+',height='+h+',location=no,menubar=no,directories=no,toolbar=no,scrollbars=no,resizable=no,status=no,top='+ha+',left='+wa);
	parent.wHandler.focus();
}

function popUpString(w, h)
{
	var wa = screen.Width;
	var ha = screen.Height;
		
	var url = document.getElementById('imagecontainer').src;
	
	url = url.replace(/_L2.jpg/,"_L.jpg");
	
	ha = (ha/2)-(h/2)
	wa = (wa/2)-(w/2)
	if(parent.wHander)
	{
		var handler = parent.wHandler;		
	}
	else
	{
		var handler
	}
	parent.wHandler = window.open(url, handler ,'width='+w+',height='+h+',location=no,menubar=no,directories=no,toolbar=no,scrollbars=no,resizable=no,status=no,top='+ha+',left='+wa);
	parent.wHandler.focus();
}

function togglelayer(_name)
{
	if(document.getElementById(_name).style.display == 'block')
	{
		document.getElementById(_name).style.display = 'none'
		hide(_name);
	}
	else
	{
		document.getElementById(_name).style.display = 'block'
		show(_name);
	}

}

function submit_form(id)
{
		document.forms[id].submit();
}

function open_user_message(msg, data, dir)
{
	dir = new String(dir)
	if(dir != "undefined")
			dir = "&dir="+ dir;
	else
			dir = "";

	if(data == 'OF')
		location.href='/pa/system/sv/customer/tools/offert/view_offert.asp';
	else if (data == 'O')
	{	
		location.href='/pa/system/sv/user/offert/view_offert.asp';
	}
	else
		open_popup("/pa/system/sv/user/messenger/msg_view.asp?msgid="+msg+dir, "msg_item", "410", "300")
}

function small_win(link)
{
		open_popup(link, "small_win", "300", "200");
}

function custom_win(link, width, height)
{
	open_popup(link, "custom_win", width, height);
}

function show(object) 
{
	var obj1 = 156;
	var obj2 = 312;
	var obj3 = 468;
	var obj4 = 624;
	var obj5 = 780;

	document.getElementById(obj1).style.visibility = 'hidden';
	document.getElementById(obj2).style.visibility = 'hidden';
	document.getElementById(obj3).style.visibility = 'hidden';
	document.getElementById(obj4).style.visibility = 'hidden';
	document.getElementById(obj5).style.visibility = 'hidden';

	if (document.getElementById) 
		document.getElementById(object).style.visibility = 'visible';
	else if (document.layers && document.layers[object] != null) 
		document.layers[object].visibility = 'visible';
	else if (document.all) 
			document.all[object].style.visibility = 'visible';
	return false;
}


function toggle(object) 
{


	if (document.getElementById) 
	{
		if (document.getElementById(object).style.visibility == 'visible')
			document.getElementById(object).style.visibility = 'hidden';
	    else
			document.getElementById(object).style.visibility = 'visible';
	}

	else if (document.layers && document.layers[object] != null) 
	{
		if (document.layers[object].visibility == 'visible' || document.layers[object].visibility == 'show' )
			document.layers[object].visibility = 'hidden';
		else
			document.layers[object].visibility = 'visible';
	}

	else if (document.all) 
	{
		if (document.all[object].style.visibility == 'visible')
			document.all[object].style.visibility = 'hidden';
		else
			document.all[object].style.visibility = 'visible';
	}
	return false;
}


function hide(object) 
{

	if (document.getElementById) 
		document.getElementById(object).style.visibility = 'hidden';
	else if (document.layers && document.layers[object] != null) 
		document.layers[object].visibility = 'hidden';
	else if (document.all) 
			document.all[object].style.visibility = 'hidden';
	return false;
}


// form handling
function setFocus(formObject, itemObject, isSelect)
{
	eval("formObject." + itemObject +".focus()");
	if(isSelect)
		eval("formObject."+ itemObject +".select()");
}
function isValidEmail(formObject, itemObject)
{
	var string;
	string = eval("formObject." + itemObject +".value");
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
		return true;
	else
		setFocus(formObject, itemObject, 1);
		return false;
}
function isValidSelect(formObject, itemObject)
{
	var val;
	val = eval("formObject." + itemObject + ".value");
	if(val == 0)
		{
			setFocus(formObject, itemObject, 0)
			return false;
		}
	return true;
}
function isValidString(formObject, itemObject, stringLength)
{
	var my_string;
	my_string = eval("formObject." + itemObject + ".value");
	if((my_string.length) > stringLength)
		return true;
	setFocus(formObject, itemObject, 1);
	return false;
}

function removeText(field) 
{
	  field.value = '';
}

function CompareFields(formObject, itemObjectA, itemObjectB)
{
		var A = eval("formObject." + itemObjectA + ".value");
		var B = eval("formObject." + itemObjectB + ".value");

		if(A == B)
			return true
		return false
}

function isChecked(formObject, itemObject)
{
	if( eval("formObject."+ itemObject +".checked") )
		return true
	return false
}