var activeProduct=1;
var beaniePage=1;

function setStyle(objId, style, value) {
    document.getElementById(objId).style[style] = value;

}


//OK
function shiftBeaniePage(page,cat) {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return
}

url = "roll=" + page + "&cat=" + cat;
url="assets/navBeanies.php?" + url;


xmlHttp.onreadystatechange=function(){
//Check page is completed and there were no problems.
if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	  document.getElementById('beanies').innerHTML = xmlHttp.responseText;
setupZoom();
}
}


xmlHttp.open("GET",url,true);
xmlHttp.send(null);


}


function prevImg(){
	imgCount = imgCount-1;
	if (imgCount>=0 && imgCount <= 7){
	}else{
		imgCount=7;
	}
	var m1 = document.getElementById("showImage");
 	m1.setAttribute('src', 'images/minioomph/image' + imgCount + '.jpg');
}

function nextImg(){
	imgCount = imgCount+1;
	if (imgCount>=0 && imgCount <= 7){
	}else{
		imgCount=0;
	}
	var m1 = document.getElementById("showImage");
	m1.setAttribute('src', 'images/minioomph/image' + imgCount + '.jpg');
}


//OK
function fwDialogBox(text,caption,callback,data){
var dummy="";

	setStyle('DialogBoxFader','display','block');
	var container = document.getElementById("DialogBoxFader");
	var dialogBox=document.createElement('div');
	dialogBox.setAttribute('id', 'dialogBox');
	dialogBox.innerHTML='<br><br>' + text + '<br><br>';
	container.appendChild(dialogBox);
	
	switch (caption){
		
	case "INFO":
	var container = document.getElementById("dialogBox");
	var dialogBox=document.createElement('a');
	dialogBox.href = "javascript:DBClose();";
	dialogBox.innerText="OK";
	container.appendChild(dialogBox);
	break;
	
	case "YESNO":
	var container = document.getElementById("dialogBox");
	var dialogBox=document.createElement('a');
	dialogBox.href = "javascript:" + callback + "('YES'," + data + ");";
	dialogBox.innerText="JA";
	container.appendChild(dialogBox);

	var spanspace=document.createElement('span');
	spanspace.innerText=" | ";
	container.appendChild(spanspace);

	var container = document.getElementById("dialogBox");
	var dialogBox=document.createElement('a');
	dialogBox.href = "javascript:" + callback + "('NO'," + data + ");";
	dialogBox.innerText="NEI";
	container.appendChild(dialogBox);
	break;
	
	case "OKCANCEL":
	
	break;
	
	case "OK":
	var container = document.getElementById("dialogBox");
	var dialogBox=document.createElement('a');
	dialogBox.href = "javascript:" + callback + "('OK'," + data + ");";
	dialogBox.innerText="OK";
	container.appendChild(dialogBox);
	break;
}
	
	
		
}

//OK
function DBClose(){
		setStyle('DialogBoxFader','display','none');
	removeElement('dialogBox');
}

function showProductInfo(varenr, type){

var ScreenWidth=ScreenSizeWidth();
	setStyle('DialogBoxFader','display','block');
	var inBody = document.getElementsByTagName("body").item(0);
	var inProdInfo = document.createElement("div");
	inProdInfo.setAttribute('id', 'produktInformasjon');

	var wHeight, wWidth;
	switch(type)
	{
		case 'beanie':
  			wHeight=350;
 			wWidth=380;
 		 break;
		case 'oomphsuit':
			wHeight=515;
 			wWidth=480;
		break;
		case 'mini':
			wHeight=450;
 			wWidth=460;
		break;
		case 'tee':
  			wHeight=340;
 			wWidth=450;
 		 break;
		
		default:  
			wHeight=400;
			wWidth=300;
	}
	
	//inProdInfo.style.height=(wHeight+'px');
	inProdInfo.style.width=(wWidth+'px');
	inProdInfo.style.left=((ScreenWidth/2)-(wWidth/2)+'px');
	inProdInfo.innerHTML='<center><br><br><br><img src="shared/gfx/load.gif"><br><br><br></center>';
	inBody.insertBefore(inProdInfo, inBody.firstChild);


	loadContent('produktinfo/' + varenr + '.php?varenr=' +  varenr,'produktInformasjon')
	
}

//OK
function hideProductInfo(){
	setStyle('DialogBoxFader','display','none');
	//removeElement('produktInformasjon');
	setStyle('produktInformasjon','display','none');
}


//OK
function subNewsletter(email){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return
}


if (!(verifyEmail(email))){
document.getElementById('nyhetsbrev').value ="Ugyldig adresse";
return 0;
}

url = "assets/subNewsletter.php?email=" + email;

xmlHttp.onreadystatechange=function(){
 //Check page is completed and there were no problems.
 if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
  if(xmlHttp.responseText=='FAILED'){
   document.getElementById('nyhetsbrev').value="Din forespørsel mislykkast";
  }else{
    if(xmlHttp.responseText==1){
     document.getElementById('nyhetsbrev').value="Takk, du vil motta våre nyhetsbrev";
	}else{
     document.getElementById('nyhetsbrev').value="Du er fjerna fra vår liste";
    }
  }
 }
}

xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

//OK
function verifyEmail(addr){
var status = false;     
var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

     if (addr.search(emailRegEx) == -1) status = false;
     else status = true;
  
     return status;
}

function removeElement(el) {
  var d = document.getElementById('DialogBoxFader');
  var oldel = document.getElementById(el);
  d.removeChild(oldel);
}

//OK
function ScreenSizeWidth(){
	 var vertPost=0;
	 var viewportwidth;
	 var viewportheight;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }

	 // older versions of IE
	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }

return viewportwidth;

}

function shiftProduct(pnr,varenr,count){
	var millisec=100;
	var speed = Math.round(millisec / 100); 
    var timer = 0;
	var id="teeScroll";
    var obj = document.getElementById(id);

	if(pnr > activeProduct)	fact=(pnr-activeProduct);
	else if(pnr < activeProduct) fact=-(activeProduct-pnr);
	else fact=0;

	for(i = 1; i <= count; i++ ){ 
		setTimeout("doShift(" + fact + ",'" + id + "')",(timer * speed)); 
        timer++;
	}
	
	//sett fade på småskjortene


	fadeOut('t'+activeProduct,100,40);
	activeProduct=pnr;
	fadeIn('t'+activeProduct,40,100);

	changeName(varenr);

}

function shiftBeanie(dir){
	var millisec=100;
	var speed = Math.round(millisec / 100); 
    var timer = 0;
	var count=800;
	var id="beanieScroll";
    var obj = document.getElementById(id);
	var fact=0;

	if(dir<beaniePage) fact=-1;
	else if (dir>beaniePage) fact=1;

	for(i = 1; i <= count; i++ ){ 
		setTimeout("doShift(" + fact + ",'" + id + "')",(timer * speed)); 
        timer++;
	}
	
	//sett fade på småskjortene
	beaniePage=dir;

}

function changeName(varenr){

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return
}

url = "varenr=" + varenr;
url="assets/getProductName.php?" + url;


xmlHttp.onreadystatechange=function(){
//Check page is completed and there were no problems.
if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	  document.getElementById('productName').innerHTML = xmlHttp.responseText;
	changeBuyParam(varenr);
}
}


xmlHttp.open("GET",url,true);
xmlHttp.send(null);



}

function changeBuyParam(varenr){

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request")
	 return
}

url = "varenr=" + varenr;
url="assets/getProductInfo.php?" + url;


xmlHttp.onreadystatechange=function(){
//Check page is completed and there were no problems.
if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	  document.getElementById('productBuy').innerHTML = xmlHttp.responseText;

}
}


xmlHttp.open("GET",url,true);
xmlHttp.send(null);



}


function fadeOut(id,fV,tV){
	var millisec=800;
	var speed = Math.round(millisec / 100); 
    var timer = 0;
   	for(i = 0; i <= fV-tV; i++ ){  	
		setTimeout("doFade(" + ( fV-i ) + ",'" + id + "')",(timer * speed)); 
        timer++;
	}
	}

function fadeIn(id,fV,tV){
	var millisec=800;
	var speed = Math.round(millisec / 100); 
    var timer = 0;
	for(i = fV; i <= tV; i++ ){ 
		setTimeout("doFade(" + (fV+i) + ",'" + id + "')",(timer * speed)); 
        timer++;
	}
}

function doFade(value, id){
var obj = document.getElementById(id).style;
obj.opacity = (value/100);
obj.filter="alpha(opacity="+value+")";

//obj.opacity = (0.2);
//obj.filter="alpha(opacity=20)";

}

function doShift(count, id) { 

    var obj = document.getElementById(id);
    var object = document.getElementById(id).style; 
    newPos=parseInt(getStyle(obj, "left")) - count;
    object.left = newPos + "px";
}

/*********************************************************
*	getStyle
*	Gets style(Style) from an object(el) 
*	required toCamelCase
**********************************************************/

function getStyle(el, style) {
   if(!document.getElementById) return;

     var value = el.style[toCamelCase(style)];

    if(!value)
        if(document.defaultView)
            value = document.defaultView.
                 getComputedStyle(el, "").getPropertyValue(style);

        else if(el.currentStyle)
            value = el.currentStyle[toCamelCase(style)];

     return value;
}


/*********************************************************
*	toCamelCase
*	???
**********************************************************/

function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)    
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ? 
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}








