﻿function passwordStrength(password)
{
	var desc = new Array();
	desc[0] = "Very Weak";
	desc[1] = "Weak";
	desc[2] = "Better";
	desc[3] = "Medium";
	desc[4] = "Strong";
	desc[5] = "Strongest";

	var score   = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 8) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

    if (password.length == 0)
        document.getElementById("passwordDescription").innerHTML = "Password Strength: Password not entered";
    else
	    document.getElementById("passwordDescription").innerHTML = "Password Strength: " + desc[score];
	
	document.getElementById("passwordStrength").className = "strength" + score;
}

function swapEdge() {
	document.getElementById("menuButtons").className = "menuButtonsIn";
}

function swapBack() {
	document.getElementById("menuButtons").className = "menuButtonsOut";
}

function switchProductImage(id, imgurl) {
    document.getElementById(id).src = imgurl;
}

function switchColourImage(id, imgurl, alt, ddl, itemValue, rpt) {
    document.getElementById(id).src = imgurl;
    document.getElementById(id).alt = alt;
    
    if (document.getElementById(ddl))
    {
        for (i=0; i<document.getElementById(ddl).options.length; i++) {
            if (document.getElementById(ddl).options[i].value == itemValue) {
               document.getElementById(ddl).options[i].selected = true;
            }
        }
    }
    
    var ar_select = document.getElementById(rpt).getElementsByTagName("select");
    
    for (i = 0; i < ar_select.length; i++)
    {
        for (j = 0; j < ar_select[i].options.length; j++) 
        {
            if (ar_select[i].options[j].value == itemValue) 
            {
               ar_select[i].options[j].selected = true;
            }
        }
    }
}

function selectColourImage(id, urlPath, ddl) {
    //alert(ddl.options[ddl.selectedIndex].hex);
    //alert(urlPath);
    
    document.getElementById(id).src = urlPath + ddl.options[ddl.selectedIndex].id.replace(/img_/gi, "");
    document.getElementById(id).alt = ddl.options[ddl.selectedIndex].innerHTML;
}

function popup(url, width, height) {
    newwindow=window.open(url, 'parnellPop', 'width=' + width + ', height=' + height + ',Menubar=1');
}

function toggleDateSelection(startDateId, endDateId) {
    var startDate = document.getElementById(startDateId);
    var endDate = document.getElementById(endDateId);
    
    if (startDate.enabled)
    {
        startDate.value = '';
        startDate.enabled = false;
    }
    else
    {
        startDate.enabled = true;
    }
    
    if (endDate.enabled)
    {
        endDate.value = '';
        endDate.enabled = false;
    }
    else
    {
        endDate.enabled = true;
    }
}

function showOrHide(id, value)
{
    if (value == 0)
        document.getElementById(id).style.visibility='hidden';
    else if (value == 1)
        document.getElementById(id).style.visibility='visible';
}

// Obsolete
var slideInUse = new Array();
var objList = new Array();

function Slide(objId, options) {
	this.obj = document.getElementById(objId);
	this.duration = 1;
	this.height = parseInt(this.obj.style.height);

	if(typeof options != 'undefined') { this.options = options; } else { this.options = {}; }
	if(this.options.duration) { this.duration = this.options.duration; }
		
    this.toggle = function() {
        if(objList[objId] == true || objList[objId] == null) {
            objList[objId] = false;
            this.down();
        }
        else {
            objList[objId] = true;
            this.up();
        }
    }
		
	this.up = function() {
		this.curHeight = this.height;
		this.newHeight = '1';
		if(slideInUse[objId] != true) {
			var finishTime = this.slide();
			window.setTimeout("Slide('"+objId+"').finishup("+this.height+");",finishTime);
		}
	}
	
	this.down = function() {
		this.newHeight = this.height;
		this.curHeight = '1';
		if(slideInUse[objId] != true) {
			this.obj.style.height = '1px';
			this.obj.style.display = 'block';
			this.slide();
		}
	}
	
	this.slide = function() {
		slideInUse[objId] = true;
		var frames = 30 * duration; // Running at 30 fps

		var tIncrement = (duration*1000) / frames;
		tIncrement = Math.round(tIncrement);
		var sIncrement = (this.curHeight-this.newHeight) / frames;

		var frameSizes = new Array();
		for(var i=0; i < frames; i++) {
			if(i < frames/2) {
				frameSizes[i] = (sIncrement * (i/frames))*4;
			} else {
				frameSizes[i] = (sIncrement * (1-(i/frames)))*4;
			}
		}
		
		for(var i=0; i < frames; i++) {
			this.curHeight = this.curHeight - frameSizes[i];
			window.setTimeout("document.getElementById('"+objId+"').style.height='"+Math.round(this.curHeight)+"px';",tIncrement * i);
		}
		
		window.setTimeout("delete(slideInUse['"+objId+"']);",tIncrement * i);
		
		if(this.options.onComplete) {
			window.setTimeout(this.options.onComplete, tIncrement * (i-2));
		}
		
		return tIncrement * i;
	}
	
	this.finishup = function(height) {
		this.obj.style.display = 'none';
		this.obj.style.height = height + 'px';
	}
	
	return this;
}

function showLoading()
{
    alert('Loading...');
}

function isFirefox()
{
    var status = false;
    
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
    { 
        //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
        var ffversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        
        if (ffversion>=3) {}
            //document.write("You're using FF 3.x or above")
        else if (ffversion>=2) {}
            //document.write("You're using FF 2.x")
        else if (ffversion>=1) {}
            //document.write("You're using FF 1.x")
            
        status = true;
    }
    
    return status;
}

function repositionBox(lnk, fly, adjIE, adjFF)
{
    var link = document.getElementById(lnk);
    
    if (isFirefox())
        fly.setRelativePosition(adjFF, 15);
    else
        fly.setRelativePosition(findPosX(link) - adjIE, 15);    
}

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}    