/* under construction */

function showOnly(nr){
	document.getElementById(nr).style.display = 'block';
}

function hiddeOnly(nr){
	document.getElementById(nr).style.display = 'none';
}

function show_hidde(divId){
	if(document.getElementById(divId).style.display == 'none'){
		document.getElementById(divId).style.display = 'block';
	}else{
		document.getElementById(divId).style.display = 'none';
	}
}

function selectImage(url){
	  var win = tinyMCEPopup.getWindowArg("window");
	  // insert information now
	  win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;
	  // for image browsers: update image dimensions
	  if (win.getImageData) win.getImageData();
	  // close popup window
	  tinyMCEPopup.close();
}

function confirm_action(action, msg) {
	var answer=confirm(msg);
	if(answer==1){
		location=action;
	}
}

function popup2(url, width, height) {
	newwindow=window.open(url,'name','height='+height+' ,width='+width+', scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

/* Clear / recal text field */
function clickclear(idField) {
	document.getElementById(idField).value = "";
}

function clickrecall(idField, defaulttext) {
	if (document.getElementById(idField).value == "") {
		document.getElementById(idField).value = defaulttext;
	}
}

function delItem(mod, id, msg){
	var confirmMsg='The following '+msg+' will be deleted. Proceed?';
    answer = confirm(confirmMsg);
    if(answer==1){
		location="admin.php?s="+mod+"&del="+id;
    }
}

/* Load different image */

function loadImg(img_path){
	//myImage.src
	document.getElementById('thumb').src = img_path;
}


/* SEARCH VALIDATION */
function validate_src(){
	if(document.search.src.value==''){
		document.search.src.focus();
		alert('Search field is empty!');
		return false;
	}
}


/* CAPTCHA refresh */
function new_captcha(){
	var c_currentTime = new Date();
	var c_miliseconds = c_currentTime.getTime();

	document.getElementById('captcha').src = 'captcha.php?x='+ c_miliseconds;
}

/**** PASSWORD STRENGTH CHECK ****/
var numbers     = "0123456789"; 
var lowercase   = "abcdefghijklmnopqrstuvwxyz"; 
var uppercase   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
var punctuation = "!.@$£#*()%~<>{}[]/\|+=-_`^,."; 

function contain(password, validChars){
	var count=0; var i;
	for (i=0; i<password.length; i++){
		var char = password.charAt(i); 
        if (validChars.indexOf(char) > -1) { 
            count++; 
        } 
	}
	return count;	
}

function checkPassword(password, divId, divIdMsg) {  
    var combinations = 0;
	var maxComb      = 0;
	var percent      = 0;
    if (contain(password, numbers) > 0) { 
        combinations += 10; 
    }
	if (contain(password, lowercase) > 0) { 
        combinations += 26; 
    }
	if (contain(password, uppercase) > 0) { 
        combinations += 26; 
    }
	if (contain(password, punctuation) > 0) { 
        combinations += punctuation.length; 
    }
    percent = Math.round(((combinations*password.length)*100)/720);
	if (percent>=100){
		percent=100;
	}
	
	//alert(power+'%');

	var progressBar = document.getElementById(divId); 
    progressBar.style.width = percent + "px"; 

	var progressMsg = document.getElementById(divIdMsg);
    
	if(password.length < 6){
		progressMsg.style.color = "#ff0000";
		progressMsg.innerHTML='Too short';
	}else if(percent >= 70){
		progressBar.style.backgroundColor = "#3bce08";
		progressMsg.style.color = "#666666";
		progressMsg.innerHTML='Strong';
    }else if(percent > 35 && percent < 70) {
		progressBar.style.backgroundColor = "#ffcd54";
		progressMsg.style.color = "#666666";
		progressMsg.innerHTML='Medium';
	}else{
		progressBar.style.backgroundColor = "#ff0000";
		progressMsg.style.color = "#ff0000";
		progressMsg.innerHTML='Weak';
	}

}

// ajax load content

function loadurl(dest) {
	try {
		// Moz supports XMLHttpRequest. IE uses ActiveX.
		// browser detction is bad. object detection works for any browser

		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		// browser doesn't support ajax. handle however you want
    }

	// the xmlhttp object triggers an event everytime the status changes
    // triggered() function handles the events
    
	xmlhttp.onreadystatechange = triggered;

	// open takes in the HTTP method and url.
   
	xmlhttp.open("GET", dest);
    // send the request. if this is a POST request we would have
    // sent post variables: send("name=aleem&gender=male)
    // Moz is fine with just send(); but
    // IE expects a value here, hence we do send(null);
    
	xmlhttp.send(null);
}

	  
function triggered() {
	// if the readyState code is 4 (Completed) and http status is 200 (OK) we go ahead and get the responseText.
	// other readyState codes: 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
    
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		// xmlhttp.responseText object contains the response.
        document.getElementById("thumbnail").innerHTML = xmlhttp.responseText;
    }
}

/******** show /hidde div box floating arround mouse cursor *********/
var cX = 0; 
var cY = 0; 
var rX = 0; 
var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { 
	document.onmousemove = UpdateCursorPositionDocAll; 
}else { 
	document.onmousemove = UpdateCursorPosition; 
}

function AssignPosition(d) {
	if(self.pageYOffset) {
		rX = self.pageXOffset;
		rY = self.pageYOffset;
	}else if(document.documentElement && document.documentElement.scrollTop) {
		rX = document.documentElement.scrollLeft;
		rY = document.documentElement.scrollTop;
	}else if(document.body) {
		rX = document.body.scrollLeft;
		rY = document.body.scrollTop;
	}
	if(document.all) {
		cX += rX; 
		cY += rY;
	}
	d.style.left = (cX+10) + "px";
	d.style.top = (cY+10) + "px";
}

function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
	if(d.length < 1) { return; }
	var dd = document.getElementById(d);
	AssignPosition(dd);
	dd.style.display = "block";
}

/********************************************************************/


