DOM = (document.getElementById) ? true : false;

function newWin(url)
 {
 	eval("myWindow = window.open(\""+url+"\",\"Menu\",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=455,screenx=455,top=190,screeny=190,width=317,height=314');");

 }


function createImage(name) {
	eval("var "+name+"on;");
	eval("var "+name+"of;");
}

function preloadImage(path,name) {
	if (document.images) {
		eval("createImage('"+name+"');");	
		eval(name +"on = new Image();");
		eval(name +"on.src = '"+path+"/"+name+"on.gif';");
		eval(name +"of = new Image();");
		eval(name +"of.src = '"+path+"/"+name+"of.gif';");
	}
}

function preloadImageJpg(path,name) {
	if (document.images) {
		eval("createImage('"+name+"');");	
		eval(name +"on = new Image();");
		eval(name +"on.src = '"+path+"/"+name+"on.jpg';");
		eval(name +"of = new Image();");
		eval(name +"of.src = '"+path+"/"+name+"of.jpg';");
	}
}

function ci(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "on.src");
	}
}

function cib(imgName) {
	if (document.images) {
		document[imgName].src = eval(imgName + "of.src");
	}
}


//form validation

		var digits = "0123456789";
		var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
		var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var whitespace = " \t\n\r";
		
		//electronic addresses
		var validDomainNameChars = digits + uppercaseLetters + lowercaseLetters + "-_.";

			// message
	var msgerror = "";
	var msghead = "";	

	function askForOK(msg) {
		return confirm(msg);
	}	   

	function isEmail (s){
		// message
		msgerror = "";
		msghead = "";

		msghead = "There are errors with the entered e-mail address:\n\n";
    		var i = 1;
    		var sLength = s.length;
    		while ((i < sLength) && (s.charAt(i) != "@"))
    			{ i++ }
    		if ((i >= sLength) || (s.charAt(i) != "@")) msgerror += "- No '@' sign\n";
    		else var atloc = i;
	 	j = i+1; 	 
	 	i += 1;	 
    		while ((j < sLength) && (validDomainNameChars.indexOf(s.charAt(j)) != -1))
    			{ j++ } 
		if (j < sLength) msgerror += "- Invalid character in domain name '" + s.charAt(j) + "'\n";	 	
    		while ((i < sLength) && (s.charAt(i) != "."))
    			{ i++ }
    		if (i == sLength) msgerror += "- No . in domain name \n";
    		if (i == (atloc +1)) msgerror += "- Not enough space between '@' and '.' \n";
    		l = sLength;
    		while ((i < sLength -2) && (l != i) && (s.charAt(l) != "."))
    			{ l = l-1 }
    		if ((i >= sLength - 2) || (s.charAt(i) != ".") || (l >= sLength - 2)) msgerror += "- Not enough characters after '.'\n"; 
	 	k = atloc+1;
		while (k < sLength){
      			if ((s.charAt(k) == ".") && (s.charAt(k+1) == ".")) msgerror += "- Too many '.'s\n";
      			k++
		}
		if (msgerror != "") msgerror = msghead + msgerror;
	 	else return true;
	} 

	function checkEmail (theField) {
      		emailStatus = isEmail(theField.value)
      		if (emailStatus != true) alert(msgerror);
      		else return true;
	}

		function isblank(s) {

			for(var i = 0; i < s.length; i++) {

				var c = s.charAt(i);

				if ((c != ' ') && (c != '\n') && (c != '\t')) return false;

			}

			return true;

		}

		function passwordLength(p) {
			if (p.length < 8) { return false; }
			return true;
		}

		function passwordDigit(p) {
			for (i = 0; i < p.length; i++) {   
        			var c = p.charAt(i);
        			if (digits.indexOf(c) == -1) { 
					continue; 
				} else { 
					return true; 
				}
			}
			return false;
		}

		// this function performs validation, it goes with onSubmit() event handler

		function verify(f, formname)

		{

			var msg;
			var empty_fields = "";
			var errors = "";
			var value_match = "";
				

			// now go through the fields looking for text areas

			// also looks for defined max and min values if defined
			for(var i = 0; i < f.length; i++) {

				var e = f.elements[i];
				
				
					
				if (((e.type == "text") || (e.type == "textarea") || (e.type == "password")) && !e.optional) {

					// first check if the field is empty

					if ((e.value == null) || (e.value == "") || isblank(e.value)) {	
						var field_name = "";

						if (e.rename) field_name = e.rename;					

						if (field_name == "") {		
							empty_fields += "\n           " + e.name;
							continue;
						}
						else {
							empty_fields += "\n           " + field_name;
							continue;
						}

					}
					

					//check for fields that must match

					if (e.match) {
						if (value_match == "") {
							value_match = e.value;
							match_field = e.name; 
						}
						else if (e.value != value_match) { 
						
							if (formname == "user") {
								errors += "-   Password mismatch, please re-type the password again."
							}
							else {
								errors += "-   The value of '" + e.name + "' doesn't match the value of '" + match_field + "'"; }
							}
					}

					// check that the password is sufficient string

					if (e.password) {
						if (passwordLength(e.value)) { 
							if (passwordDigit(e.value)) { continue; }
							else { errors += "-   Password must contain some digits\n"; }
							continue; 
						}
						else { errors += "-   Password must be at least 8 characters long\n"; }
					}

					// check email is valid

					if (e.emailcheck) {
						for (i = 0; i < e.length; i++) {
							var estring = e.value;   
        						var c = estring.charAt(i);
        						if (c != "@") { 
								continue; 
							} else { 
								return true; 
							}
						}
						if ((i >= sLength) || (s.charAt(i) != "@")) return ("no @ sign");
					}

					// now check for numeric fields

					if (e.numeric || (e.min != null) || (e.max != null)) {

						var v = parseFloat(e.value);
						if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) {
						errors += "-   The field " + e.name + " must be a number";
						if (e.min != null)
							errors += " that is greater than " + e.min;
						if (e.max != null && e.min != null)
							errors += "   and less than  " + e.max;
						else if (e.max != null)
							errors += " that is less than " + e.max;

						errors += ".\n";

					}

				}
				
			}
			
	}
			// now display error and prevent form to be processed
			if (!empty_fields && !errors) return true;


			msg = "We are sorry, but we can not process the form becuase of the following error(s).\n";

			msg += "Please correct these error(s) and re-submit.\n\n";



			if (empty_fields) {

				msg += "- The following required field(s) are empty:" + empty_fields + "\n";

			if (errors) msg += "\n";

			}



			msg += errors;
			
			alert(msg);
			return false;

		}
//popUp

function popUp(URL, width, height) { 
	eval("novOkno = window.open(URL, \"popBrand\", 'toolbar=0,scrollbars=1,status=0,location=0,statusbar=0,menubar=0,resizable=1,width="+width+",height="+height+",left=414,top=261');"); 	
}


function popUpEdit(URL, width, height) {
       self.location = URL;
               if (parseInt(navigator.appVersion)>3) {
                        if (navigator.appName=="Netscape") {
                               top.outerWidth=width;
                               top.outerHeight=height;
                       }
               else top.resizeTo(width,height);
               }

}

function resize(width, height) {
               if (parseInt(navigator.appVersion)>3) {
                        if (navigator.appName=="Netscape") {
                               top.outerWidth=width;
                               top.outerHeight=height;
                       }
               else top.resizeTo(width,height);
               }
}

//multiple select boxes

            var conAdd = 'Add';
            var conRemove = 'Remove';
            var delimiter = "|";


                function MoveOption(f, From, To, action) {
                var eFrom = eval('f.msb' + From);
                	var eTo = eval('f.msb' + To);
                	var selection = eFrom.options.selectedIndex;
                	var eAddContainer;
                	var eRemoveContainer;


                    	if (action == conAdd) {
                    		eAddContainer = eval('f.htx' + conAdd + To);
                    		eRemoveContainer = eval('f.htx' + conRemove + To);
                    	}


                        	if (action == conRemove) {
                        		eAddContainer = eval('f.htx' + conRemove + From);
                        		eRemoveContainer = eval('f.htx' + conAdd + From);
                        	}


                            	if (selection == -1) {
					alert("Please select one or more categories to move.");


                                	} else {
                                		eval('f.cmd' + action + '.disabled = true;');


                                    		for (i = 0; i < eFrom.options.length; i++) {


                                        			if(eFrom.options[i].selected) {
                                        				var name = eFrom.options[i].text;
                                        				var ID = eFrom.options[i].value;
                                        				eFrom.options[i] = null;
                                        				eTo.options[eTo.options.length] = new Option (name,ID);
                                        				i = i - 1;
                                        				var rep = new String('\\' + delimiter + ID + '\\' + delimiter + '');
                                        				var repExp = new RegExp(rep);


                                            				if (eRemoveContainer.value.match(repExp) == null) {
                                            					eAddContainer.value = eAddContainer.value + ID + delimiter;


                                                				} else {
                                                					eRemoveContainer.value = eRemoveContainer.value.replace(repExp,delimiter);
                                                				}
                                                			}
                                                		}
                                                	}
                                            }


					    function onChange_msbCategoryPool(f) {
                                                	f.cmdAdd.disabled = (f.msbCategoryPool.selectedIndex == -1);
                                            }


                                                function onChange_msbAssignedCategory(f) {
                                                	f.cmdRemove.disabled = (f.msbAssignedCategory.selectedIndex == -1);
                                            }
function selAll(_v) {
	for (i = 0; i < thisForm.msbCategoryPool.length; i++) {
  
			thisForm.msbCategoryPool[i].selected=_v;
		} 
}

//select all, none

var form='clientBrand' //Give the form name here

function SetChecked(val,chkName) {
dml=document.forms[form];
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements[i].name==chkName) {
dml.elements[i].checked=val;
}
}
}

