/*******************************************************************
Globlal Variables and Constants Declarations
*******************************************************************/

var COOAgriculture = 1;
var COOAnimal = 2;
var COONature = 3;
var COOArab = 4;
var COOForiegn = 5;
var COOIndustrial = 6;
var COOUniversity = 7;
var COOOthers = 8
var COOEnglish = 9;

var Member           = 1;
var Individual       = 2;
var RegionalOffices  = 3;
var OtherEntities    = 4;
var ForiegnCompanies = 5;


var strSitePath = "http://appserver/ACC02/";
/*******************************************************************
Returns a String containing a copy of a specified string without leading spaces. 

Parameters:
String - The required string argument is any valid 
         string expression. If string contains null, 
         false is returned.
Returns: String.
*******************************************************************/
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' && String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/*******************************************************************
Returns a String containing a copy of a specified string without trailing spaces. 

Parameters:
String - The required string argument is any valid 
         string expression. If string contains null, 
         false is returned.
Returns: String.
*******************************************************************/
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' && String.substr(j, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/*******************************************************************
Returns a String containing a copy of a specified string without 
both leading and trailing spaces .

Parameters:
String - The required string argument is any valid 
         string expression. If string contains null, 
        false is returned.
Returns: String.
*******************************************************************/
function Trim(String)
{
	if (String == null)
		return (false);
	return RTrim(LTrim(String));
}

/**************************************************************
 Mid: Returns a String containing a specified number of 
      characters from a string

 Parameters:
      String = String expression from which characters are 
               returned. If string contains null, false is 
               returned.
      Start  = Number. Character position in string at which 
               the part to be taken begins. If Start is 
               greater than the number of characters in 
               string, Mid returns a zero-length string ("").
      Length = Number of characters to return. If omitted 
               false is returned. 

 Returns: String
***************************************************************/
function Mid(String, Start, Length)
{
	if (String == null)
		return (false);

	if (Start > String.length)
		return '';

	if (Length == null || Length.length == 0)
		return (false);

	return String.substr((Start - 1), Length);
}

/*******************************************************************
Return boolen value if the passed value is valid number or not.

Parameters:
strValue - string value that will be checked if its number.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function IsNumber(strValue,strAlert)
{
	strval=Trim(strValue)
	test=true;

	number=isNaN(strval);
	if (number == true)
	{
		test=false;
		alert(strAlert);
	}
	return(test);	
}	

/*******************************************************************
Return boolen value if the passed value is nigative number or not.

Parameters:
strValue - string value that will be checked if its nigative number.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function IsNegative(strValue,strAlert)
{
	test=true;
	if ((strValue < 0 ) == true)
	{
		test=false;
		alert(strAlert);
	}
	return(test);	
}	

/*******************************************************************
Return boolen value if the passed value is empty or null string.

Parameters:
strValue - string value that will be checked if its empty string or not.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function IsEmpty(strValue,strAlert)
{
	test = true;
	valtrimed = Trim(strValue);
	testlen = valtrimed.length;

	if (testlen == 0) 
	{
		test = false;
		alert(strAlert);
	}
	return(test);	
}	

/*******************************************************************
Return boolen value if the passed value is Alphabet entries or not.

Parameters:
intFlag  - indicates the state of alphabet. 1-Arabic(Both). 2-English.
strValue - string value that will be checked if its Alphabet entries.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/


function IsAlpha(intFlag,strValue,strAlert)
{
	var r;
	var x;
	
	test=true;
	if (Trim(strValue) != "")
	{
		if (intFlag == 1)
			x="[A-Za-zÃÅÉÆÄÇ-í]+[ ÉÅÃÄÆÇ-íA-Za-z.-/ ]*[a-zÃÅÉÄÁÆÅáÇ-íA-Z]*";
		else if (intFlag == 2)
			x="[A-Za-z]+[A-Za-z.& ]*[A-Za-z.]*";
					
		r=strValue.match(x);
		if (r!=strValue)
		{
			test=false;
			alert(strAlert);
		}
	}
	return(test);	
}	

/*******************************************************************
Return boolen value if the passed value is Alphanumeric data.

Parameters:
intFlag  - indicates the state of alphabet. 1-Arabic(Both). 2-English.
strValue - string value that will be checked if its Alphanumeric data.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function IsAlphaNum(intFlag,strValue,strAlert)
{
	var r;
	var x;
	
	test=true;
	if (Trim(strValue) != "" )
	{
		if (intFlag == 1)
			x="[0-9A-Za-zÃÅÉÆÄÇ-í]+[ÉÅÃÄÆÇ-íA-Za-z0-9_ ]*[a-zÃÅÉÄÁÆÅáÇ-íA-Z0-9]*";
		else
			x="[0-9A-Za-z]+[A-Za-z0-9_., ]*[a-zA-Z0-9]*";
		
		r=strValue.match(x);
		if (r!=strValue) 
		{
			test=false;
			alert(strAlert);
		}
	}
	return(test);	
}	

/*******************************************************************
Return boolen value if the passed value is valid email format or not.

Parameters:
strValue - string value that will be checked if its valid email format.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function IsEmail(strValue,strAlert)
{
	var r;
	var x;
	
	test=true;
	if (Trim(strValue) != "")
	{
		x="[A-Za-z_]+[A-Za-z0-9_-]*[.]?[A-Za-z0-9_-]+[@][A-Za-z0-_-]+[.][A-Za-z0-9_]+[.]?[A-Za-z0-9_]+[.]?[A-Za-z0-9_]+" ;
		r=strValue.match(x);
		if (r!=strValue)
		{
			test=false;
			alert(strAlert);
		}
	}
	return(test);	
}	

/*******************************************************************
 Return boolen value if the passed string had length more than certain
 characters.

Parameters:
strValue - string value that will be checked. 
intLen   - the max no. of characters allowed.
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function checkPasswordLength(strValue,intLen,strAlert)
{
	test=true;
	valtrimed=Trim(strValue)
	testlen=valtrimed.length;
	if ( testlen < intLen )
	{
		test=false;
		alert(strAlert);
	}
	return(test)
} 

/*******************************************************************
Return boolen value if the passed value is valid phone format.

Parameters:
strValue - string value that will be checked. 
strAlert - string value to be message alert.
Returns: Boolean.
*******************************************************************/
function IsTelephone(strValue,strAlert)
{
	var x,r
	test=true
	if (Trim(strValue) != "" )
	{
		x="[+]?[0-9]+[0-9-]*"
		r=strValue.match(x)
		if (r!=strValue) 
		{
			test=false;
			alert(strAlert);
		}
	}
	return(test);	
}

/*******************************************************************
Add a new item to a SELECT HTML object at runtime.

Parameters:
Object - SELECT Object ID.
Value  - Value of the String ... <option VALUE="?????">....</option>.
String - String to add.
Returns: None.
*******************************************************************/
function ComboAdd(Object, Value, String)
{
	Value = Trim(Value)
	String = Trim(String)

	if (Value.length < 1 || String.length < 1)
		return false

	Object[Object.length] = new Option(String, Value);
	Object.selectedIndex = Object.length;
}



/*******************************************************************
Add a new item to a SELECT HTML object at runtime.

Parameters:
Object - SELECT Object ID.
Value  - Value of the String ... <option VALUE="?????">....</option>.
String - String to add.
Returns: None.
*******************************************************************/
function MultipleListAdd(Source,Distination) 
{
	var  oOption ;
	var c = Source.length;
	var flag;
	
	for(i=0; i<c; i++)
	{
		oOption = new Option();
		if (Source[i].selected) 
		{
			Source[i].selected=false;
			oOption.value= Source.options[i].value;
			oOption.text=Source.options[i].text;
			
			if (Distination.length==0)
			{
				Distination.options[Distination.length]=oOption;
				oOption=null;
			}
			
			if (oOption != null){
				flag=0;
				for(i=0; i<Distination.length; i++)
				{
					if (Distination.options[i].value==oOption.value){
						flag=1;
						oOption=null;
						break
					}
				}
			}

			if (flag==0){
				Distination.options[Distination.length]=oOption;
				oOption=null;
			}
		}
	}
	
}
	

/*******************************************************************
Delete the current/selected item from a SELECT HTML object at runtime.

Parameters:
Object - SELECT Object ID.
Returns: None.
*******************************************************************/
function ComboDel(Object)
{
	var selected_index = Object.selectedIndex
	
	if (selected_index >= 0)
	{
		Length = Object.length
		for (i= Length-1;i >= 0;i--){
		if (Object.options[i].selected)
		{
			Object.options[i] = null;
		}
		
		}
//		if (selected_index >= 0)
//			Object.selectedIndex = selected_index
//		else
//			Object.selectedIndex = 0;
	}
}

/*******************************************************************
Returns a Long specifying the position of the first 
occurrence of one string within another. Is String1
or String2 are null, false is returned.

Parameters:
String1 - String expression being searched.
String2 - String expression sought.
Returns: Integer.
*******************************************************************/
function InStr(String1, String2)
{
	var a = 0;

	if (String1 == null || String2 == null)
		return (false);

	String1 = String1.toLowerCase();
	String2 = String2.toLowerCase();

	a = String1.indexOf(String2);
	if (a == -1)
		return 0;
	else
		return a + 1;
}

/**************************************************************
Returns a Boolean value indicating whether an 
expression contains symbols such as
@#$%^&|\_+-*="!?,/.:;'(){}<>[].

Parameters:
String1 - the string being searched.
String2 - Variant containing a numeric expression or 
		  string expression.
Returns: Boolean.
***************************************************************/
function IsSpecialChars(String1, String2)
{
	if (String1 != "")
	{
		Expression = String1.toLowerCase();
		if(String2 !="" || String2 == false)
			RefString  = String2;
		else
			RefString ="\"\'";

		if (Expression.length < 1) 
			return (false);

		for (var i = 0; i < Expression.length; i++) 
		{
			var ch = Expression.substr(i, 1)
			var a = RefString.indexOf(ch, 0)
			if (a != -1)
			{
				alert("The following characters are not allowed " + RefString +" .");
				return (false);
			}
		}
	}
	return(true);
}

/*******************************************************************
Returns if a specific string reaches the min. size.

Parameters:
String1 - the string you want to check.
Length  - the min. lenght you want.
String2 - the error message.
Returns: Boolean
*******************************************************************/
function IsMinSize(String1,Lenght,String2)
{
	var StringVal = Trim(String1);
	var StringLength = StringVal.length ;

	if (StringVal != "")
	{
		if ( parseInt(StringLength) < parseInt(Lenght) )
		{
			alert(String2);
			return false;
		}
	}
	return true;
}

/*******************************************************************
Returns if a specific string reaches the max. size.

Parameters:
String1 - the string you want to check.
Length  - the min. lenght you want.
String2 - the error message.
Returns: Boolean
*******************************************************************/
function IsMaxSize(String1,Lenght,String2)
{
	var StringVal = Trim(String1);
	var StringLength = StringVal.length ;
	if (StringVal != "")
	{
		if ( parseInt(StringLength) > parseInt(Lenght) )
		{
			alert(String2);
			return false;
		}
	}
	return true;
}

/*******************************************************************
Returns a referance to a spcified form .

Parameters:
String1 - The name of the form. 
Returns: form object.
*******************************************************************/
function GetForm(String1)
{
	
	if (String1 == null)
		return null;
	else
		return eval("document.forms." + String1);
}

/*******************************************************************
submits a form. 

Parameters:
formName - form name string.
Returns: none.
*******************************************************************/
function SubmitForm(formName)
{
	var obj_form= GetForm(formName);
	if(obj_form)
	{
		obj_form.submit();
	}
}

/*******************************************************************
resets a form. 

Parameters:
formName - form name string.
Returns: none.
*******************************************************************/
function ResetForm(formName)
{
	var obj_form= GetForm(formName);
	if(obj_form)
	{
		obj_form.reset();
	}
}

/*******************************************************************
Gets an element refernce.  

Parameters:
FormElement - element name you want to get.	
Form		- form object.
Returns: object. 
*******************************************************************/
function GetElement(FormElement,Form)
{
	var form_length = Form.elements.length;
	var myform = Form;
	var Element = null;
	for (var i = 0; i < form_length; i++)
	{
		if(myform.elements[i].name == FormElement)
		{
			Element=myform.elements[i];
			return 	Element;
		}
	}
	alert("Element not found "+ FormElement);
}

/*******************************************************************
Returns the element value.

Parameters:
CheckedElement = element object you want to return it's value.
Returns: String. 
*******************************************************************/
function GetElementValue(CheckedElement)
{
	var ElementValue ="";
	if (CheckedElement == null)
	{
		alert("Null element");
		return false;
	}
				
	var ElementType = CheckedElement.type ;
	ElementType = ElementType.toLowerCase();
	if (
		ElementType == 'text' || ElementType == 'hidden' || 
		ElementType == 'password' || ElementType == 'textarea' || 
		ElementType == 'select-one' || ElementType == 'checkbox' || 
		ElementType == 'radio' || ElementType == 'select-multiple'
		)
		{
					
		if (
			ElementType == 'text' || ElementType == 'hidden' ||
			ElementType == 'password' || ElementType == 'textarea'
			)
			ElementValue = Trim(CheckedElement.value);
					
		else if (ElementType == 'select-one' || ElementType == 'select-multiple')
			ElementValue =  Trim(CheckedElement[CheckedElement.selectedIndex].value);
		}
	return ElementValue;
}

/*******************************************************************
select and focus of an element. 

Parameters:
CheckedElement - element object you want to select.
Returns: none.
*******************************************************************/
function selectElement(CheckedElement)
{
	var ElementType = CheckedElement.type ;
	ElementType = ElementType.toLowerCase();
			
	if (ElementType == 'text'  || ElementType == 'password'  || ElementType == 'textarea')
	{
		CheckedElement.select();
		CheckedElement.focus();
	}
					
	else if (ElementType == 'checkbox' || ElementType == 'radio' || 
			 ElementType == 'select-one' || ElementType == 'select-multiple')
		CheckedElement.focus();
		CheckedElement.selectedIndex=0;
}

/*******************************************************************
checks an element for the various validation conditions. 

Parameters:
FormElement  - form element's name.
Form		 - the form object.
Empty		 - to check if the field is empty.
Alpha		 - to check if the field is alpha.
Number		 - to check if the field is numeric.
Negative	 - to check if the field is negative.
AlphaNum	 - to check if the field is alphanumeric.
Email		 - to check if the field is formatted as an email.
Telephone	 - to check if the field is formatted is a phone.
MinSize		 - to determine the minimum size of the field.
MaxSize		 - to determine the maximum size of the field.
SpecialChars - to check if the element contains a special characters.

Notes:-
The other parameters can be either false(is the validation condition is not required)
or an error message(string) if the validation condition is required.
	   
note :1- The last two parameters maxsize and minsize of char's in a field, in case 
it's required the number of char's should be contcatenated with a $ and with 
also with the error message.
			
2- When its needed to check for spcial characters the SpecialChars variable
should equal a string that contains the spcial characters
			
	   
Ex. you need to make shur the minimum of char's in a password field is 6.
The function should be called as follows
CheckElement(FormElement,Form,Empty,Alpha,Number,Negative,Alphanum,Email,Telephone,
"6$"+ ErrorMessage,MaxSize,SpecialChars)
Where ErrorMessage is a string that contains the actual error message.
	   
Ex.
CheckElement(FormElement,Form,Empty,Alpha,Number,Negative,Alphanum,Email,Telephone,
MinSize,MaxSize,"[]{}+-\\*\'=\"")

Returns: none
*******************************************************************/
function CheckElement(FormElement,Form,Empty,Alpha,Number,Negative,Alphanum,Email,Telephone,MinSize,MaxSize,SpecialChars)
{
	var CheckedElement=GetElement(FormElement,Form);
	var ElementValue="";
	var status;
	
	if(CheckedElement==null)
	{
		alert("element not found. " + ' '+ FormElement);
		return false;
	}
	else
	{
		ElementValue = GetElementValue(CheckedElement);
		if (Empty!=false)
		{
			if (IsEmpty(ElementValue,Empty)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Alpha!=false)
		{
			if (IsAlpha(2,ElementValue,Alpha)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Number!=false)
		{
			if (IsNumber(ElementValue,Number)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
	
		if (Negative!=false)
		{
			if (IsNegative(ElementValue,Negative)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Alphanum!=false)
		{
			if (IsAlphaNum(2,ElementValue,Alphanum)==false)
			{
				selectElement(CheckedElement);
				return false;	
			}
		}
		
		if (Email!=false)
		{
			if (IsEmail(ElementValue,Email)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Telephone!=false)
		{
			if (IsTelephone(ElementValue,Telephone)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (MinSize!=false)
		{
			var Message =MinSize.substr(MinSize.indexOf("$")+1);
			MinSize=MinSize.substr(0,MinSize.indexOf("$"));
				
			if (IsMinSize(ElementValue,MinSize,Message +" "+MinSize+".")==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (MaxSize!=false)
		{
			var Message =MaxSize.substr(MaxSize.indexOf("$")+1);
			MaxSize=MaxSize.substr(0,MaxSize.indexOf("$"));
				
			if (IsMaxSize(ElementValue,MaxSize,Message +" "+MaxSize+"." )==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}

		if (SpecialChars!=false)
		{
			if (IsSpecialChars(ElementValue,SpecialChars)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
				
		return true;
	}
}




/*******************************************************************
checks an element for the various validation conditions. 

Parameters:
FormElement  - form element's name.
Form		 - the form object.
Empty		 - to check if the field is empty.
Alpha		 - to check if the field is alpha.
Number		 - to check if the field is numeric.
Negative	 - to check if the field is negative.
AlphaNum	 - to check if the field is alphanumeric.
Email		 - to check if the field is formatted as an email.
Telephone	 - to check if the field is formatted is a phone.
MinSize		 - to determine the minimum size of the field.
MaxSize		 - to determine the maximum size of the field.
SpecialChars - to check if the element contains a special characters.

Notes:-
The other parameters can be either false(is the validation condition is not required)
or an error message(string) if the validation condition is required.
	   
note :1- The last two parameters maxsize and minsize of char's in a field, in case 
it's required the number of char's should be contcatenated with a $ and with 
also with the error message.
			
2- When its needed to check for spcial characters the SpecialChars variable
should equal a string that contains the spcial characters
			
	   
Ex. you need to make shur the minimum of char's in a password field is 6.
The function should be called as follows
CheckElement(FormElement,Form,Empty,Alpha,Number,Negative,Alphanum,Email,Telephone,
"6$"+ ErrorMessage,MaxSize,SpecialChars)
Where ErrorMessage is a string that contains the actual error message.
	   
Ex.
CheckElement(FormElement,Form,Empty,Alpha,Number,Negative,Alphanum,Email,Telephone,
MinSize,MaxSize,"[]{}+-\\*\'=\"")

Returns: none
*******************************************************************/
function CheckElementA(FormElement,Form,Empty,Alpha,Number,Negative,Alphanum,Email,Telephone,MinSize,MaxSize,SpecialChars)
{
	var CheckedElement=GetElement(FormElement,Form);
	var ElementValue="";
	var status;
	
	if(CheckedElement==null)
	{
		alert("element not found. " + ' '+ FormElement);
		return false;
	}
	else
	{
		ElementValue = GetElementValue(CheckedElement);
		if (Empty!=false)
		{
			if (IsEmpty(ElementValue,Empty)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Alpha!=false)
		{
			if (IsAlpha(1,ElementValue,Alpha)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Number!=false)
		{
			if (IsNumber(ElementValue,Number)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
	
		if (Negative!=false)
		{
			if (IsNegative(ElementValue,Negative)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Alphanum!=false)
		{
			if (IsAlphaNum(1,ElementValue,Alphanum)==false)
			{
				selectElement(CheckedElement);
				return false;	
			}
		}
		
		if (Email!=false)
		{
			if (IsEmail(ElementValue,Email)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (Telephone!=false)
		{
			if (IsTelephone(ElementValue,Telephone)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (MinSize!=false)
		{
			var Message =MinSize.substr(MinSize.indexOf("$")+1);
			MinSize=MinSize.substr(0,MinSize.indexOf("$"));
				
			if (IsMinSize(ElementValue,MinSize,Message +" "+MinSize+".")==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
		
		if (MaxSize!=false)
		{
			var Message =MaxSize.substr(MaxSize.indexOf("$")+1);
			MaxSize=MaxSize.substr(0,MaxSize.indexOf("$"));
				
			if (IsMaxSize(ElementValue,MaxSize,Message +" "+MaxSize+"." )==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}

		if (SpecialChars!=false)
		{
			if (IsSpecialChars(ElementValue,SpecialChars)==false)
			{
				selectElement(CheckedElement);
				return false;
			}
		}
				
		return true;
	}
}

/*******************************************************************
compare the value of two elemets in the form.

Parameters:
String1 - compared Element name.
String2 - comparable Element name.
String3 - show Error Message. 
Object  - Form Object.           
Returns: Boolean
*******************************************************************/
function CheckPasswordsMatch(String1,String2,String3,Object)
{
	if(GetElementValue(GetElement(String1,Object))!=GetElementValue(GetElement(String2,Object)))
	{
		alert(String3);
		selectElement(GetElement(String1,Object));
		return false;
	}
	else
		return true;
}

/*******************************************************************
checks if the first option is selected in a DDL. 

Parameters:
String1 - Element name.
String2 - index value.
String3 - Error Message.
Object  - Form Object.
Returns: Boolean.
*******************************************************************/
function SelectedIndex(String1,String2,String3,Object)
{
	var SelectElement= GetElement(String1,Object);
	if( SelectElement.selectedIndex <=0  )
	{
		alert(String3);
		selectElement(SelectElement);
		return false;
	}
	else
		return true;
}

/*******************************************************************
checks if the options are selected in a DDL, and the first option
is not 0. 

Parameters:
String1 - Element name.
String2 - index value.
String3 - Error Message.
Object  - Form Object.
Returns: Boolean.
*******************************************************************/
function SelectedMultipleWithoutZero(String1,String2,String3,Object)
{
	var SelectElement= GetElement(String1,Object);
	
	if(SelectElement.length > 1)
	for(i=1;i<SelectElement.length;i++)
	{
		if(SelectElement.options[i].selected == true)
		{
			return true;		
		}
	}	
	alert(String3);
	return false;
}

/*******************************************************************
checks if the options are selected in a DDL, and the first option
is 0. 

Parameters:
String1 - Element name.
String2 - index value.
String3 - Error Message.
Object  - Form Object.
Returns: Boolean.
*******************************************************************/
function SelectedMultipleWithZero(String1,String2,String3,Object)
{
	var SelectElement= GetElement(String1,Object);
	
	if(SelectElement.length > 0)
	for(i=0;i<SelectElement.length;i++)
	{
		if(SelectElement.options[i].selected == true)
		{
			return true;		
		}
	}	
	alert(String3);
	return false;
}

/*******************************************************************
allow you to select in the multi select options up to certain no. 

Parameters:
String1		- Element name.
MaxNumber	- the determined no. (do not exceed).
strAlert	- Error Message.
Object		- Form Object.
Returns: Boolean.
*******************************************************************/
function MaxMultipleSelection(String1,MaxNumber,str_Alert,Object)
{
	var SelectElement= GetElement(String1,Object);
	var int_Counter = 0;
	if(SelectElement.length > 0)
	for(i=1;i<SelectElement.length;i++)
	{
		if(SelectElement.options[i].selected == true)
		{
			int_Counter++;
			if (int_Counter > MaxNumber)				
			{
				alert("The Maximum number of selections is " + MaxNumber + " in the "+str_Alert+".");
				for(i=1;i<SelectElement.length;i++)
				{
					if(SelectElement.options[i].selected == true)
						SelectElement.options[i].selected = false ;
					return false;	
				}	
				return false;
			}
		}
	}	
	return true;
}

/*******************************************************************
checks the lenght of a DDL. 

Parameters:
String1		- Element name.
Number1		- length value.
String3		- Error Message.
Object		- Form Object.
Returns: Boolean.
*******************************************************************/
function SelectedLength(String1,Number1,String3,Object)
{
	var SelectElement= GetElement(String1,Object);
	if (SelectElement.length < parseInt(Number1))
	{
		alert(String3);
		selectElement(SelectElement);
		return false;
	}
	else
	{
		return true;
	}
}

/*******************************************************************
checks if the first option is selected in a DDL. 

Parameters:
strSelectName	- Select object Name.
objForm			- the From object.
strAlert		- string to appear in the alert error message.
intCheckFor		- integer value to check the value of selected index equal it.
Returns: Boolean.
*******************************************************************/
function CheckDropDown(strSelectName,objForm,strAlert,intCheckFor)
{
	if (GetElementValue(GetElement(strSelectName,objForm)) == intCheckFor)
	{		
		alert(strAlert);
		selectElement(GetElement(strSelectName,objForm));
		return false;
	}
	return true;
}

/*******************************************************************
return the month number.

Parameters:
strMonthName - Month Name.
Returns: Integer.
*******************************************************************/
function GetMonthNumber(strMonthName)
{
	var intNumber = 0;
	
	switch (strMonthName)
	{
		case "January":
			intNumber = 1;
			break;
		case "February":
			intNumber = 2;
			break;
		case "March":
			intNumber = 3;
			break;
		case "April":
			intNumber = 4;
			break;
		case "May":
			intNumber = 5;
			break;
		case "June":
			intNumber = 6;
			break;
		case "July":
			intNumber = 7;
			break;
		case "August":
			intNumber = 8;
			break;
		case "September":
			intNumber = 9;
			break;	
		case "October":
			intNumber = 10;
			break;
		case "November":
			intNumber = 11;
			break;
		case "December":
			intNumber = 12;
			break;
	}
	return intNumber;
}

/*******************************************************************
adds the Other... word and it's index to a combobox.

Parameters:
SourceElement - the combo element.
SpecificWord  - the word you want to add.
Index		  - the index of this word.	
*******************************************************************/
function AddOther(SourceElement,SpecificWord,Index)
{
	ComboAdd(SourceElement,Index,SpecificWord);

	if (sourceElement.length == 2) 
		SourceElement[1].selected=true;
	else	
		SourceElement[0].selected=true;
}

/*******************************************************************
to select multiple elements in DDL.

Parameters:
SelectElement - the element you want to select from.
StringText    - the elements you want to select(seperated by ;).
strFormName	  - the form name.
*******************************************************************/
function SelectMultipeOptions(SelectElement,StringText,strFormName)
{
	var Form = "";
	Form = GetForm(str_FormName);
	if (Form == null || Form == "" || Form == "undefined")
		return false;

	var StringTex = StringText;
	var temp="";
	var SelectEle = GetElement(SelectElement,Form);

	while(StringTex.indexOf(";") >0)
	{
		temp=StringTex.substr(0,StringTex.indexOf(";"))
		StringTex=StringTex.substr(StringTex.indexOf(";")+1)	
	
		for(i=0;i<SelectEle.length;i++)
		{
			if(Trim(SelectEle[i].value)==Trim(temp))
			{
				SelectEle[i].selected=true;
			}	
		}
	}
	SelectEle[0].selected=false;
}

/*******************************************************************
to select a certain value from DDL.

Parameters:
SelectElement - the element you want to select from.
StringText    - the string you want to select.
strFormName	  - the form name.
*******************************************************************/
function SelectMonth(SelectElement,StringText,strFormName)
{
	var Form = "";
	Form = GetForm(strFormName);
	if (Form == null || Form == "" || Form == "undefined")
		return false;

	var StringTex = StringText;
	var temp="";
	var SelectEle = GetElement(SelectElement,Form);
	
	temp=StringTex	
	for(i=0;i<SelectEle.length;i++)
	{
		if(Trim(SelectEle[i].value)==Trim(temp))
		{
			SelectEle[i].selected=true;
		}	
	}
}

/*******************************************************************
used with another ASP code to calculate days from seperated DDL's.

Parameters:
String - the element name.
Form   - the form name.
*******************************************************************/
function CalculateDays(String,FORM) {	
			
	var intMonth = GetElement(String + 'Months',FORM);
	var intYear = GetElement(String + 'Years',FORM);
	var intDays = GetElement(String + 'Days',FORM);
	var oldSelectedIndex= intDays.selectedIndex;
	var intMaxDay = 31;
	var intDay = 1;

	if (intMonth.value != 0 && intYear.value != 0) 
	{			
		switch (intMonth.value) 
		{ 
			case "1":
			case "3":
			case "5":
			case "7":
			case "8":
			case "10":
			case "12": 
			{
				intMaxDay = 31;
			}
			break; 
     		case "4":
    		case "6":
    		case "9":
    		case "11": 
			{
				intMaxDay = 30; 
			}
			break; 				
			case "2": 
			{
				if (intYear.value % 4 == 0 && (intYear.value % 1000 == 0 || intYear.value % 100 != 0)) 
				{
					intMaxDay = 29;
				}
				else 
				{
					intMaxDay = 28;
				}
			}
			break; 
			default: 
			{
				intMaxDay = 31;
			}
		}


		while (intDays.length > 1) 
		{
			intDays.options[intDays.length-1] = null;
		}
	
		for (intDay=1; intDay<=intMaxDay; intDay++) 
		{
			var Eintrag = new Option(intDay);
			intDays.options[intDays.length] = Eintrag;
			intDays.selectedIndex = intDay;
			intDays.options[intDays.selectedIndex].value = intDay;	
		}
		if(intMaxDay >=oldSelectedIndex + 1 )
			intDays.selectedIndex = oldSelectedIndex;
		else
			intDays.selectedIndex = intDays.length-1;
	}
}

/*******************************************************************
to construct a hidden field from combo.

Parameters:
Combo	- the combo element.
Hidden	- the hidden control name.
Form	- the form name.
Char	- the seperator character between the elements.
/*******************************************************************
function constructHidden(Combo,Hidden,Form,Char)
{
	var ComboElement = GetElement(Combo,Form);
	var HiddenElement = GetElement(Hidden,Form);
	var text = "";
	
	if(ComboElement.length >= 2)
	{
		for(i=1;i<ComboElement.length;i++)
			text = text + ComboElement[i].value+Char;

		HiddenElement.value = text.substr(0,text.length-1);
	}
	return false;	
}

/*******************************************************************
to check if you use I.E. or Netscape browser.
*******************************************************************/
function CheckBrowser() 
{
	var Name = navigator.appName
	
	if (Name=="Netscape") 
		this.Name = "ns"
	else 
		if (Name=="Microsoft Internet Explorer") this.Name = "ie"
		else
			this.Name = null
	
	this.v = parseInt(navigator.appVersion)
		
	this.ns = (this.Name=="ns" && this.v>=4)
	
	this.ns4 = (this.Name=="ns" && this.v==4)
	
	this.ns5 = (this.Name=="ns" && this.v==5)
	
	this.ie = (this.Name=="ie" && this.v>=4)
		
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	
	if (this.ie5)
	{
		this.v = 5
	}	 
	this.mv =parseFloat(navigator.appVersion)
}

/*******************************************************************
returns a specific cookie.

Parameters:
name	- the name of the cookie.
*******************************************************************/
function Get_Cookie(name) 
{
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	
	if (start == -1) return null;

	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return document.cookie.substring(len,end);
}

/*******************************************************************
checks the length of a DDL.

Parameters:
select		 - the DDL name.
Length		 - do not exceed this length.
ErrorMessage - when error show this message.
*******************************************************************/
function checkLength(select,Length,ErrorMessage)
{
	var selectedElements = 0;

	for(var i=0;i < select.length ;i++)
	{
		if(select[i].selected)
			++selectedElements;
	}

	if (selectedElements > parseInt(Length))
	{
		alert(ErrorMessage);
		for(var i=0;i <select.length ;i++)
		{
			if(select[i].selected)
			{
				select[i].selected=false;
				return false;
			}
		}
	}
}

/*******************************************************************
Move From Source list To Distination one.

Parameters:
Source			 - the source list.
Destination		 - the destination list.
*******************************************************************/
function MoveFromListToList(Source,Distination) 
{
	var  oOption ;
	var c = Source.length;
	var my_array = new Array();
	
	k=0;
 
	for(i=0; i<c; i++)
	{
		oOption = new Option();
		if (Source[i].selected) 
		{
			Source[i].selected=false;
			oOption.value= Source.options[i].value;
			oOption.text=Source.options[i].text;
			Distination.options[Distination.length]=oOption;
			oOption=null;
			my_array[k]=i;
			k=k+1;
		}
	}
	for(i=0; i<k; i++) 
	{
		Source.options[my_array[i]-i]=null;		
	}
}
	
/*******************************************************************
Return Selected Values from list1 to list2.
*******************************************************************/
function ReturnSelectedValues (Source,Distination,StrSelectedValues) 
{
	var St = new String();
	var arr
		 
	St=StrSelectedValues;
	if (St.length==0)
		return;
		   
	St= StrSelectedValues;
	arr=St.split(",");
		 
	var  oOption ;
	var c = Source.length;
	var my_array = new Array();
	var t1,t2
	k=0;
 
	for(i=0; i<c; i++)
	{
		oOption = new Option();
		for (j= 0;j<=arr.length-1;j++)
		{
			t1=TrimString(Source[i].value);
			t2=TrimString(arr[j])
			if( t1 == t2) 
			{
				oOption.value= Source.options[i].value;
				oOption.text=Source.options[i].text;
				Distination.options[Distination.length]=oOption;
				oOption=null;
				my_array[k]=i;
				k=k+1;
			}
		}		
		
	}
	for(i=0; i<k; i++) 
	{
		Source.options[my_array[i]-i]=null;		
	}
	
}
	
/*******************************************************************
to Get the contents of a List in a comma delimeted string.
*******************************************************************/
function GetListContents(List,txtListContents)
{
	var St=new String();
	var c = List.length;
	k=0;
 
	for(i=0; i<c; i++)
	{	        
		St = St + List.options[i].value + ",";
		//if (i != c-1) 
		//	St =St + ","; 
	}
	txtListContents.value = St;
}

/********************************************************
Popup window center in the screen */

function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
 var winleft = (screen.width - popW) / 2;
 var winUp = (screen.height - popH) / 2;
 winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable'
 Win = window.open(theURL, Name, winProp)
  if (parseInt(navigator.appVersion) >= 4)
   { Win.window.focus(); }
 
 }
 
 function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
 var winleft = (screen.width - popW) / 2;
 var winUp = (screen.height - popH) / 2;
 winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable'
 Win = window.open(theURL, Name, winProp)
  if (parseInt(navigator.appVersion) >= 4)
   { Win.window.focus(); }
 
 }// winBRopen END 
 
/*******************************************************************
to Get the contents of a List Text in a comma delimeted string.
*******************************************************************/

function GetListTextContents(List,txtListContents)
{
	var St=new String();
	var c = List.length;
	k=0;
 
	for(i=0; i<c; i++)
	{	        
		St = St + List.options[i].text + ",";
		//if (i != c-1) 
		//	St =St + ","; 
	}
	txtListContents.value = St;
}
/*********************************************************************
*********************************************************************/
function ChangeLang(Lang){
	var test = document.all["UserControl1"];
	test.ChangeLayout(Lang);
}
/*********************************************************************
**********************************************************************
**********************************************************************
*********************************************************************/
	function CardType(N)
			{
			  var i, CheckSum, Prod;
			  var MASK = "2121212121212121";
			  var Num = N;

			  if (Num == "") {
			    return("BLANK");
			}

			// Remove spaces
			  var NumDigits=Num.length;
			  var TempNum="";
			  var Digits="";
			  for(i=1;i<=NumDigits+1;i++) {
			    Digits=Num.substring(i-1,i);
			    if (Digits != " ") TempNum=TempNum+Digits;
			  }

			// Remove dashes

			  var TempNum2="";
			  for(i=1;i<=TempNum.length+1;i++)
			  {
			    Digits=TempNum.substring(i-1,i);
			    if (Digits != "-") TempNum2=TempNum2+Digits;
			  }

			// Check for non-numbers

			  for(i=1;i<=TempNum2.length;i++)
			  {
			    Digits=TempNum2.substring(i-1,i);
			    if (Digits < "0" || "9" < Digits)
			    {
			      return("NONUMBER");
			    }
			  }

			  Num = TempNum2;

			// Make card length = 16

			// Calculate check sum
			  CheckSum = 0;
			  for(i=1;i<=Num.length;i++)
			  {
			    Prod = eval(Num.substring(i-1, i)) * eval(MASK.substring(i-1, i));
					if (9 < Prod) Prod -= 9;
				CheckSum += Prod ;
			  }

			  CheckSum = CheckSum % 10;

			// Invalid card
			  if (CheckSum != 0) return("INVALID");

			  return("VALID");
		}
		
		
   function AddItemToDropDownList(drpdownName, Value,Text)
    {
        // Create an Option object                
        var opt = document.createElement("option");
        // Add an Option object to Drop Down/List Box
        document.getElementById(drpdownName).options.add(opt);        
        // Assign text and value to Option object
        opt.text = Text;
        opt.value = Value;  

    }
		
  function ClearDropDownList(drpdownName)
  {
   document.getElementById(drpdownName).options.length = 0;
  }
   		
  	
	
	
	
	
	
	
	
	
		