
/************************************************
       Added by Samir Haram, Datamatics Ltd.
*************************************************/

function moveSingle(Source, Target,selected){
	var listboxS = document.getElementById(Source);
	var listboxT = document.getElementById(Target);
	var boxLength = listboxS.length;
	arrSelected = new Array();
	var count = 0;
	if (listboxS.selectedIndex == -1){
		alert('Please make a selection.');
		
		return false;
	}
	for (i = 0; i < boxLength; i++){
		var isNew = true;
		if (listboxS.options[i].selected){
			var selectedText = listboxS.options[i].text;
			var selectedValue = listboxS.options[i].value;
			for (j = 0; j < listboxT.length; j++){
				thisitem = listboxT.options[j].text;
				if (thisitem == selectedText){
					isNew = false;
				}
			}
			if (isNew && selectedValue != -99999){
				newoption = new Option(selectedText, selectedValue, false, selected);
				listboxT.options[listboxT.length] = newoption;
				arrSelected[count] = listboxS.options[i].value;
				count++;
			}
		}
	}
	var x;
	for (i = 0; i < boxLength; i++){
		for (x = 0; x < arrSelected.length; x++){
			if (listboxS.options[i].value == arrSelected[x]){
				listboxS.options[i] = null;
			}
		}
		boxLength = listboxS.length;
	}
}
function moveAll(Source, Target,selected){
	var listboxS = document.getElementById(Source);
	var listboxT = document.getElementById(Target);
	listboxT.remove;
	var boxLength = listboxS.length;
	var choicelength = listboxT.length;
	count = choicelength;
	for (i = 0; i < boxLength; i++){
		var selectedText = listboxS.options[i].text;
		var selectedValue = listboxS.options[i].value;
		if (selectedValue != -99999){
			newoption = new Option(selectedText, selectedValue, false, selected);
			listboxT.options[count] = newoption;
			listboxS.options[i] = null;
			count = count + 1;
			boxLength = listboxS.length;
			i = i - 1;
		}
	}
}
function ShowHide(obj,img,img1,alt1,img2,alt2){
	var o = new Array();
	o = obj.split(',');
	var im
	img == undefined ? im = false : im = true;
	for (var i=0; i<o.length; i++){
		if (document.getElementById(o[i]).style.display == "none"){
			document.getElementById(o[i]).style.display = "";
			if(im){
				img.src = img1;
				img.alt = alt1;
			}
		}
		else{
			document.getElementById(o[i]).style.display = "none";
			if(im){
				img.src = img2;
				img.alt = alt2;
			}
		}
	}
}

function validateForm(v,frm){
	formObj = document.forms[frm];
	var checkList = v.split(",");
	//alert(checkList.length)
	for(var i=0; i<=checkList.length-1; i++){
		if(checkList[i] == "customValidation"){
			if(!customValidation()){
				return false;
			}
			break;
		}else{
			if(!validate(checkList[i])){
				return false;
			}
		}
	}
	return true;
}
function validate(v){
	//alert(v);
	var check = v.split(":");
	var pos = check[2].search("="); 
	if(pos>=0){
		if(!validateData(check[0],check[1],check[2])){
			formObj[check[0]].focus();
			return false;
		}
	}else{
		var a = check[2].length;
		(a>1)?isCon=true:isCon=false;
		var c = check[2].charAt(0);
		var noCon = 1;
		var con = new Array();
		con[0] = c;
		if(isCon){
			con[1] = check[2].substring(1,a);
			noCon = 2;
		}
		for(var x=0; x<noCon; x++){
			if(!validateData(check[0],check[1],con[x])){
				formObj[check[0]].focus();
				return false;
			}
		}
	}
	return true
}
function validateData(field,title,check){
	var epos = check.search("="); 
	var checkStr  = ""; 
	var checkVal = ""; 
	if(epos >= 0) { 
		checkStr  = check.substring(0,epos); 
		checkVal = check.substr(epos+1); 
	} 
	else { 
		checkStr = check; 
	}
	
	switch(checkStr){
		case "N":
			break;
		case "R": 
			if(formObj[field].value ==""){
				alert(title+": Required field.");
				return false;
			}
			break;
		case "isAlpha":
			var charpos = formObj[field].value.search("[^A-Za-z]"); 
			if(charpos >=0){
				alert(title+": Only alphabetic characters allowed.");
				return false;
			}
			break;
		case "isNum":
			var charpos = formObj[field].value.search("[^0-9]");
			if(charpos >= 0){
				alert(title+": Only digits allowed.")
				return false;
			}
			break;
		case "isAlphaNum":
			var charpos = formObj[field].value.search("[^ A-Za-z0-9\ ]");
			if(charpos >= 0){
				alert(title+": Only alpha-numeric characters allowed.")
				return false;
			}
			break;
		case "S":
			if(formObj[field].selectedIndex == checkVal){
				alert(title+": Please Select one option.");
				return false;				
			}
			break;
		case "Max":
			if(formObj[field].value.length > checkVal){
				alert(title+": "+ checkVal+" characters maximum.");
				return false;				
			}
			break;
		case "Min":
			if(formObj[field].value.length < checkVal){
				alert(title+": "+ checkVal+" characters minimum.");
				return false;				
			}
			break;
		case "isEmail":
			if(formObj[field].value !=""){
				if(!validateEmail(formObj[field].value)){
					alert(title+":  Enter a valid Email address.");
					return false;
				}
			}
			break;
	}
	return true;
}
function validateEmail(str){
	//alert(str)
	var splitStr = str.match("^(.+)@(.+)$");
	if(splitStr == null) return false;
	if(splitStr[1] != null ){
	  var regexp_user=/^\"?[\w-_\.]*\"?$/;
	  if(splitStr[1].match(regexp_user) == null) return false;
	}
	if(splitStr[2] != null){
	  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
	  if(splitStr[2].match(regexp_domain) == null) {
		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
		if(splitStr[2].match(regexp_ip) == null) return false;
	  }// if
	  return true;
	}
return false;
}

function confirmMessage(msg){
	var agree=confirm(msg);
	if (agree){
		document.DeleteListForm.submit();
	}else{
		return false ;
	}
}