//***************************************************
//
// Symbiosis Module Version version 1.4.0
// BlueSoap Optimisation Tools 2009 (c)
// PAGE NAME: functions.js
//
//***************************************************

// All the validation process begins here.
/*
function MM_validateForm() { 
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; 
		area = ( args[i+1].indexOf('admin') != -1 ) ? '' : 'admin/' ; 
		argId=args[i];
		val=document.getElementById(argId); 
		wrn=document.getElementById(argId);
		wrnFlag=document.getElementById(argId+"Failed");
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) {
		  	errors+='- '+nm+' must contain an e-mail address.\n';
			//wrn.style.backgroundColor = '#F6E4E4'; 
			//wrn.style.border = '1px solid #990000';
			wrnFlag.className = 'error';
			//wrnFlag.innerHTML = '<img src=\'http://www.bluesoap.com.au/directory/admin/images/error.gif\' />';
			
			};
        } else if (test.indexOf('isSelect')!=-1) {
          if ( val == 0 ) {
		  	errors+='- '+nm+' must contain an e-mail address.\n';
			//wrn.style.backgroundColor = '#F6E4E4'; 
			//wrn.style.border = '1px solid #990000';
			wrnFlag.className = 'error';
			//wrnFlag.innerHTML = '<img src=\'http://www.bluesoap.com.au/directory/admin/images/error.gif\' />';
			};
        }
		else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') { 
	  			errors += '- '+nm+' is required.\n'; 
				//wrn.style.backgroundColor = '#F6E4E4'; 
				//wrn.style.border = '1px solid #990000';
				wrnFlag.className = 'error';
				//wrnFlag.innerHTML = '<img src=\'http://www.bluesoap.com.au/directory/admin/images/error.gif\' />';
			}}
    } //if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

*/

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) {
		  	errors+='- '+nm+' must contain an e-mail address.\n'
			document.getElementById(args[i]).className = 'error'; 
			};
        } else if (test.indexOf('Bot')!=-1) { 
          if (val.length != null) {
		  	errors+='- '+nm+' must contain an e-mail address.\n'
			document.getElementById(args[i]).className = 'success'; 
			};
        } else if (test.indexOf('isSelect')!=-1) {
          if ( val == 0 ) {
		  	errors+='- '+nm+' must contain an e-mail address.\n';
			document.getElementById(args[i]).className = 'error';
			};
		}else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') { 
	  			errors += '- '+nm+' is required.\n'; 
				document.getElementById(args[i]).className = 'error'; 
			}}
    } //if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function validate(obj, area) 
{	
	var text = document.getElementById(obj);
	//var msg = document.getElementById(obj + "Failed");
	area = ( area == 'admin' ) ? '' : 'admin/';
	//msg.style.display = '';
	if (obj.indexOf("email")!=-1)
	{
		if ((val=text.value)!="") {
			p=val.indexOf('@');
			d=val.split("@");
			if (p<1 || p==(val.length-1)) {
				text.className = 'error';
			}
			else {
				co=d[1].indexOf('.');
				if (co<1 || co==(val.length-1)) {
					text.className = 'error';
				}
				else {
					text.className = 'success';
				}
			}
		}
		else {
			text.className = 'error';
		}
	}
	else if (obj.indexOf("category")!=-1) {
		if ( text.selectedIndex == 0 ) {
			text.className = 'error';
		}
		else {
			text.className = 'success';	
		}
	}
	else {
		if ( text.value.length < 1 || text.value == 0 ) {
			text.className = 'error';
		}
		else {
			text.className = 'success';
		}
	}
}

// DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

maxL=250;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) 
	{
	  alert("Error encountered: You have reached the allowed numbers of characters");
	  return false;
	}
	else if (taObj.value.length>maxL)
	{
	  alert("Error encountered: You have exceeded the allowed numbers of characters");
	}
	
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objWrn=createObject(Cnt+"_wrn");
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
		
		if (objVal.length >= 200)
		{
			objWrn.innerText="Reaching your limit";
			objCnt.style.color="#FF0000";
		}
	}
	return true;
}

function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}

// Prepare dynamic menu
function switchMenu(obj, rowArray) {
	var el = document.getElementById(obj);

	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
	if (rowArray!=0) {
		var i=0;
		for (i=0;i<=rowArray;i++)
		{
			if ( obj == i ) {
				document.getElementById(i).style.display = '' ;
			}
			else {
				document.getElementById(i).style.display = 'none' ;
			}
		}
	}
}

function confirmation(ID,Name,Status) {
	if (Status == "approve") {
		message = "You are about to approve '"+Name+"'";
	}
	else if (Status == "online") {
		message = "You are about to switch '"+Name+"' online";
	}
	else if (Status == "offline") {
		message = "You are about to switch '"+Name+"' offline";
	}
	else if (Status == "remove") {
		message = "Please confirm the deletion of "+Name;
	}
	else if (Status == "logout") {
		message = "Are you sure you want to logout?";
		var answer = confirm(message)
		if (answer){
			window.location = "admin_login.php?mode=logout";
		}
		else{
			alert("No action taken")
		}
	}
	
	var answer = confirm(message)
	if (answer){
		window.location = "admin_directory.php?status="+Status+"&directory_id="+ID;
	}
	else{
		alert("No action taken")
	}
}

function logout(Status) {
	if (Status == "logout") {
		message = "Are you sure you want to logout?";
	}
	
	var answer = confirm(message)
	if (answer){
		window.location = "admin_login.php?mode=logout";
	}
}