// Form Field Types
var FIELD_TYPE_cHEcKBOX = 1;
var FIELD_TYPE_SELEcT = 2;

var DEFAuLT_VALIDATOR_cLASS_NAME = "validator"; // Default class name
var VALIDATOR_cLASS_NAME = DEFAuLT_VALIDATOR_cLASS_NAME; // current class name


var is_valid = true; // Main Flag
var highlighted_errors = false; // Note: when using this feature, don't use <td style="background-color: ...">
								// Note: the validator DIV must be located directly inside the TD (validtor_div.parent. ...)
var highlighted_errors_color = ""; // color to use as background in cells which have errors.
var validation_language = "he"; // Default language for error messages

function initErrorStrings()
{	
	// Hebrew Error Messages
	if (validation_language == "he")
	{
		ERROR_EMPTY = "אנא מלא שדה זה";
		ERROR_SPAcE_NOT_ALLOWED = "סיסמא אינה יכולה להכיל רווחים"
		ERROR_PASSWORDS_NOT_EQuAL = "הסיסמאות אינן זהות"
		ERROR_INVALID_LENGTH = "אנא הקלד מקסימום %1 תווים";
		ERROR_INVALID_LENGTH2 = "אנא הקלד לפחות %1 תווים";
		ERROR_INVALID_EMAIL = "אנא תקן את פורמט האימייל שלך";
		ERROR_INVALID_NuMBER = "אנא הקלד מספר";
		ERROR_INVALID_uSERNAME = "אנא הקלד אותיות אנגליות וספרות בלבד"
		ERROR_INVALID_SELEcTION = "אנא בחר פריט מתוך הרשימה"
		ERROR_INVALID_MuLTI_SELEcTION = "אנא בחר לפחות פריט אחד"
		ERROR_INVALID_cREDIT_cARD_NuM = "אנא הקלד מס' כרטיס אשראי תקין"
		ERROR_INVALID_ID_NuM = "אנא הקלד מס' תעודת זהות תקין"
		ERROR_INVALID_DATE = "אנא בחר תאריך חוקי"
		ERROR_cHEcKBOX_NOT_cHEcKED = "יש לסמן וי בשדה זה"
		ERROR_INVALID_PHONE = "מס' הטלפון שהקלדת אינו תקין"
		ERROR_NOT_EQuAL_NuMBER = "המספרים אינם זהים"
		ERROR_EQuAL_NuMBER = "המספרים זהים"
		ERROR_NOT_SMALL_NuMBER = "המספר הראשון אינו קטן מהשני"
		ERROR_NOT_BIG_NuMBER = "המספר הראשון אינו גדול מהשני"
		ERROR_NOT_SMALL_OR_EQuAL_NuMBER = "המספר הראשון אינו קטן או שווה לשני"
		ERROR_NOT_BIG_OR_EQuAL_NuMBER = "המספר הראשון אינו גדול או שווה לשני"
	}
	
	// English Error Messages
	if (validation_language == "en")
	{
		ERROR_EMPTY = "Required Field";
		ERROR_SPAcE_NOT_ALLOWED = "Password cannot contain spaces"
		ERROR_PASSWORDS_NOT_EQuAL = "Passwords don't match"
		ERROR_INVALID_LENGTH = "Minimum %1 characters required";
		ERROR_INVALID_EMAIL = "Enter a valid E-mail";
		ERROR_INVALID_NuMBER = "Numeric value required";
		ERROR_INVALID_uSERNAME = "Only use english letters and numbers"
		ERROR_INVALID_SELEcTION = "choose an item"
		ERROR_INVALID_MuLTI_SELEcTION = "choose at least 1 item"
		ERROR_INVALID_cREDIT_cARD_NuM = "Invalid credit card Number"
		ERROR_INVALID_ID_NuM = "Invalid personal ID number"
		ERROR_INVALID_DATE = "Invalid date"
		ERROR_cHEcKBOX_NOT_cHEcKED = "Field must be checked"
		ERROR_INVALID_PHONE = "Invalid phone number"
		ERROR_NOT_EQuAL_NuMBER = "The Numbers are not equal"
		ERROR_EQuAL_NuMBER = "The numbers are equal"
		ERROR_NOT_SMALL_NuMBER = "The first number is not smaller then the second one"
		ERROR_NOT_BIG_NuMBER = "The first number is not bigger then the second one"
		ERROR_NOT_SMALL_OR_EQuAL_NuMBER = "The first number is not smaller or equal then the second one"
		ERROR_NOT_BIG_OR_EQuAL_NuMBER = "The first number is not bigger or equal then the second one"
	}
}

initErrorStrings(); // call to initialize

// Sets the validation language and reloads the strings
function setValidationLanguage(lang)
{
	validation_language = lang;
	initErrorStrings();
}

function isExplorer()
{
	return navigator.appName.indexOf("Explorer") > -1;
}
function insertTextt(obj, str) {
(element.hasChildNodes())? element.firstChild.data=str : element.appendChild(document.createTextNode(text));
}

function setInnerText(element, text)
{
	if (isExplorer()) 
			element.innerText = text;
		else
			element.textcontent = text;
}

function setValidatorclassName(class_name)
{
	VALIDATOR_cLASS_NAME = class_name;
}

function restoreValidatorclassName()
{
	VALIDATOR_cLASS_NAME = DEFAuLT_VALIDATOR_cLASS_NAME;
}

// Inits the highlighting variables
function setHighlightedErrors(highlight, color)
{
	highlighted_errors = highlight;
	highlighted_errors_color = color;
}

// clears all errors
function clearErrors()
{
	var divs = document.getElementsByTagName("div");
	var validator_div;
	
	for (i=0;i<divs.length;i++) 
	{
		try {
			if (divs[i].tagName == "DIV")				
				if (divs[i].className == VALIDATOR_cLASS_NAME)
				{
					validator_div = divs[i];
					
					try
					{
						validator_div.style.display = "none";
					
						if (highlighted_errors) validator_div.parentNode.style.backgroundcolor = "";
					}
					catch (e)
					{
						alert("Validator <DIV> not found: " + validator_div); 
					}
				}
		}
		catch (e)
		{
		
		}
	}
}

// clears the validation flag
function clearValidationFlag()
{	
	is_valid = true;
	
	clearErrors();
}

// Returns true if all validators passed
function isValid()
{
	return is_valid;
}

//clear the validator error
function clearError(validator_div)
{
	/* this function is not in use, functionality has been moved to clearErrors
	try
	{
		document.all[validator_div].style.display = "none";
		if (highlighted_errors) document.all[validator_div].parentElement.style.backgroundcolor = "";
	}
	catch (e)
	{
		alert("Validator <DIV> not found: " + validator_div); 
	} */
}

// Set the validtor error message
function setError(validator_div, err_msg)
{
	if (validator_div == "") return; // Exit if empty validator, allows for using the functions without uI error msgs
	
	var div = document.getElementById(validator_div);
	
	is_valid = false;
	
	try 
	{			
		div.style.display = "block";
	
		//if (div.innerHTML == "") setInnerText(div, err_msg);
		if (div.getAttribute("error") == null) 
			setInnerText(div, err_msg);
		else
			setInnerText(div, div.getAttribute("error"));
			
		if (highlighted_errors) div.parentNode.style.backgroundcolor = highlighted_errors_color;
	}
	catch (e)
	{	
		alert("Validator <DIV> not found: " + validator_div);
	}
}
function validat_draw(validator_div)
{
setError(validator_div, ERROR_EMPTY);
		
if (!document.getElementById(validator_div).hasChildNodes()) {

  document.getElementById(validator_div).appendChild(document.createTextNode('.'));

}
document.getElementById(validator_div).firstChild.nodeValue = ERROR_EMPTY;
}



    function LimitAttach(forms, file2, field, validator_div) 
	{
	extArray = new Array(".jpg", ".png", ".bmp", ".gif");
    allowSubmit = false;
    if (!file2) 
	return true;
    //while (file.indexOf("\\") != -1)
	
    file = file.slice(file2.indexOf("\\") + 1);
    ext = file.slice(file2.indexOf(".")).toLowerCase();
    alert (ext)
    for (var i = 0; i < extArray.length; i++) 
	{
    if (extArray[i] == ext) 
		{ 
		allowSubmit = true; break; 
		}
    }
    if (allowSubmit) 
	return true;
    else
	    {

			setError(validator_div, ERROR_EMPTY);
			if (!document.getElementById(validator_div).hasChildNodes()) 
			{
			document.getElementById(validator_div).appendChild(document.createTextNode('.'));
			}
	
			document.getElementById(validator_div).firstChild.nodeValue = "ניתן לעלות קבצי תמונה בלבד";
			return false; // mark as dirty
		} 
    }
    //  End -->

// Validate a non-empty field
function validateNonEmpty(field, validator_div)
{
	var str = trim(field.value);
	var s = new String();
	
	if (str == "" || str=="null" ||  str.length==0 )
	{
		setError(validator_div, ERROR_EMPTY);
		if (!document.getElementById(validator_div).hasChildNodes()) {

  document.getElementById(validator_div).appendChild(document.createTextNode('.'));

}

document.getElementById(validator_div).firstChild.nodeValue = ERROR_EMPTY;
		return false; // mark as dirty
	} 
	else
	{
		clearError(validator_div);
		return true;	
	}
}

function validateNonEmptyEditor(field, validator_div)
{			
	var str = eval("obj_" + field.id + ".getHTMLBody()");
	
	if (str == "" || str=="null" ||  str.length==0 )
	{
		setError(validator_div, ERROR_EMPTY);
		return false; // mark as dirty
	} 
	else
	{	
		clearError(validator_div);
		return true;	
	}
}

// Validate an e-mail address
function validateEmail(field, validator_div)
{
  var Email = field.value;
  
  if (Email.length > 0 )
	  {
		var i   = Email.indexOf("@")
		var j   = Email.indexOf(".",i)
		var k   = Email.indexOf(",")
		var kk  = Email.indexOf(" ")
		var jj  = Email.lastIndexOf(".") + 1
		var len = Email.length
		
		if (!(i > 0 && j > (i + 1) && k == -1 && kk == -1 && (len - jj) >= 2 && (len - jj) <= 3))
		{
			setError(validator_div, ERROR_INVALID_EMAIL);
			return false; // mark as dirty
		}
  }  
  
  clearError(validator_div);
  return true;
}

// Validates a numeric value
function validateNumber(field, validator_div)
{
 	if (isNaN(field.value))
 	{
		setError(validator_div, ERROR_INVALID_NuMBER);
		return false; // mark as dirty
	}
	
	clearError(validator_div);
	return true;
}
// Validates a numeric value is "=" or "!=" or "<" or ">" or ">=" or "<="  to a given number
function validate2Numbers(field, validator_div, gNumber, opretor)
{
 	if (isNaN(field.value))
 	{
		setError(validator_div, ERROR_INVALID_NuMBER);
		return false; // mark as dirty
	}
	var fNumber = field.value;
	
	switch (opretor)
	{
	case '==','=':
	    if (fNumber != gNumber)
	    {
	        setError(validator_div, ERROR_NOT_EQuAL_NuMBER);
		    return false; // mark as dirty
	    }
	    
    case '!=':
        if (fNumber == gNumber)
	    {
	        setError(validator_div, ERROR_EQuAL_NuMBER);
		    return false; // mark as dirty
        }
	    break;
	case '<':
        if (fNumber >= gNumber)
	    {
	        setError(validator_div, ERROR_NOT_SMALL_NuMBER);
		    return false; // mark as dirty
        }
		break;
    case '>':
        if (fNumber <= gNumber)
	    {
	        setError(validator_div, ERROR_NOT_BIG_NuMBER);
		    return false; // mark as dirty
        }
        break;
    case '<=':
        if (fNumber > gNumber)
	    {
	        setError(validator_div, ERROR_NOT_SMALL_OR_EQuAL_NuMBER, ERROR_NOT_BIG_OR_EQuAL_NuMBER);
		    return false; // mark as dirty
        }
    case '>=':
        if (fNumber < gNumber)
	    {
	        setError(validator_div, ERROR_NOT_BIG_OR_EQuAL_NuMBER);
		    return false; // mark as dirty
        }
        break;
	}	
	
	clearError(validator_div);
	return true;
}

// Validates a field is of a minimum length
function validateMinLength2(field, min_length, validator_div)
{
	var err = ERROR_INVALID_LENGTH2;
	
	if (!validateNonEmpty(field, validator_div)) 
		return false; // fail if empty
	
	if (field.value.length < min_length)
	{
		err = err.replace("%1", min_length); // put min_length into the error message
		
		setError(validator_div, err);
		return false; // mark as dirty
	}
	
	clearError(validator_div);
	return true;
}


// Validates a field is of a minimum length
function validateMinLength(field, min_length, validator_div)
{
	var err = ERROR_INVALID_LENGTH;
	
	if (!validateNonEmpty(field, validator_div)) 
		return false; // fail if empty
	
	if (field.value.length < min_length)
	{
		err = err.replace("%1", min_length); // put min_length into the error message
		
		setError(validator_div, err);
		return false; // mark as dirty
	}
	
	clearError(validator_div);
	return true;
}

// Validates a field is of a minimum length
function validateMaxLength(field, min_length, validator_div)
{
	var err = ERROR_INVALID_LENGTH;
	
	
	if (field.value.length > min_length-1)
	{
		err = err.replace("%1", min_length); // put min_length into the error message
		
		setError(validator_div, err);
		return false; // mark as dirty
	}
	
	clearError(validator_div);
	return true;
}

// Validates a User name (english letter and numbers)
function validateuserName(field, validator_div)
{
 	var valid_chars = "abcdefghijklmnopqrstuvwxyzABcDEFGHIJKLMNOPQRSTuVWXYZ0123456789";
 	var str = field.value;
 	
 	if (validateNonEmpty(field, validator_div))
 	{
 		for (var i=0;i<=str.length;i++)
 		{
 			//alert(str.indexOf(str.charAt(i), valid_chars));
			if (valid_chars.indexOf(str.charAt(i)) == -1)
			{
				setError(validator_div, ERROR_INVALID_uSERNAME);
				return false; // mark as dirty
			}
		}
		
		clearError(validator_div);
		return true;
	}
	else
	{
		return false; // validateNonEmpty failed so we fail too.
	}	
}

// Validates a password field
function validatePassword(field, min_length, validator_div)
{
	if (validateMinLength2(field, min_length, validator_div))
 	{
 		if (field.value.indexOf(" ") > -1)
 		{
			setError(validator_div, ERROR_SPAcE_NOT_ALLOWED);
			return false; // mark as dirty
		}
	
		clearError(validator_div);
		return true;
	}
	else
		return false; // validateMinLength failed so we fail too.
}

// Validates both password fields match
function validatePasswordsEqual(field1, field2, validator_div)
{
	if (field1.value != field2.value)
	{
		setError(validator_div, ERROR_PASSWORDS_NOT_EQuAL);
		return false; // mark as dirty
	}
	else
	{
		clearError(validator_div);
		return true;
	}
}

// Validate that a selection was made in a combobox (that the first item is not the selected one
function validateSelection(field, validator_div)
{
	if (field.selectedIndex == 0) 
	{
		
		
	{
		setError(validator_div, ERROR_INVALID_SELEcTION);
		if (!document.getElementById(validator_div).hasChildNodes()) {

  document.getElementById(validator_div).appendChild(document.createTextNode('.'));

}

document.getElementById(validator_div).firstChild.nodeValue = ERROR_INVALID_SELEcTION;
		return false; // mark as dirty
	}	
		
		
		
	}

	clearError(validator_div);

	return true;
}

function validateSelection2(field, validator_div)
{
	if (field.options[field.selectedIndex].value == -1) 
	{
		
		
	{
		setError(validator_div, ERROR_INVALID_SELEcTION);
		if (!document.getElementById(validator_div).hasChildNodes()) {

  document.getElementById(validator_div).appendChild(document.createTextNode('.'));

}

document.getElementById(validator_div).firstChild.nodeValue = ERROR_INVALID_SELEcTION;
		return false; // mark as dirty
	}	
		
		
		
	}

	clearError(validator_div);

	return true;
}

function validateSelection_more(field, field2, validator_div)
{
	if ((field2.value <field.value) && (field2.value!=0) && (field.value!=0)) 
	{
		setError(validator_div, "תאריך קטן מתאריך התחלה");
		return false; // mark as dirty
	}


	return true;
}

function validateSelection_less(field2, field, validator_div)
{
	if ((field2.value >field.value) && (field2.value!=0) && (field.value!=0))
	{
		setError(validator_div, "תאריך קטן מתאריך התחלה");
		return false; // mark as dirty
	}


	return true;
}

// Validate that a selection was made in a multiline select (at least 1 item must be selected)
function validateMultiSelection(field, validator_div)
{	
	if (field.selectedIndex == -1) 
	{
		setError(validator_div, ERROR_INVALID_MuLTI_SELEcTION);
		return false; // mark as dirty
	}
	
	clearError(validator_div);
	return true;
}

// Validates that at least 1 checkbox in a checkbox list (group) is checked. 
// checkboxes must have id=<field name><option number> attribute e.g. id=hobbies1 id=hobbies2
/*function validateStatus(field, num_of_opt, validator_div)
{
	for (var i=1; i<=num_of_opt; i++)
	{
		if (document.getElementById(field + i).checked) 
		{	
			clearError(validator_div);
			return true;
		}
	}
	
	setError(validator_div, ERROR_INVALID_MuLTI_SELEcTION);
	return false; // mark as dirty
}*/	

// Validates that at least 1 checkbox in a checkbox list (group) is checked. 
function validateRadioList(field, validator_div)
{
	clearError(validator_div);
	
	for (var i=0; i<field.length; i++)
	{		
		if (field[i].checked) return true;
	}
	
	setError(validator_div, ERROR_INVALID_MuLTI_SELEcTION);
	return false; // mark as dirty
}

// Validates a credit card is a numeric field with minimum 8 digits
function validatecreditcardNum(field, validator_div)
{
	var err = ERROR_INVALID_LENGTH;
	var r;
	
	if (field.value == "") return true; // empty is valid. 
	if (!validateNumber(field, validator_div)) return false; // not a number, invalid				
	if (field.value.length < 8)
	{
		err = err.replace("%1", 8); // put 8 into the error message
		
		setError(validator_div, err);
		return false; // mark as dirty
	}
	
	if (field.value.length < 10)
		r = checkShortIsracard(field.value);
	else
		r = checkLuHN(field.value);
	
	if (!r) 
	{
		setError(validator_div, ERROR_INVALID_cREDIT_cARD_NuM);
		return false;
	}
}	

function validatePersonalIdNum(field, validator_div)
{
	
	if (field.value == "") return true; // empty is valid. 
	if (!validateNumber(field, validator_div)) return false; // not a number, invalid
	if (field.value.length < 8) return false; // not empty but too short
	
	if (!checkLuHN(field.value)) 
	{
		setError(validator_div, ERROR_INVALID_ID_NuM);
		return false;
	}
	
	
	clearError(validator_div);
	return true;
}	

function validatechecked(field, validator_div)
{
	if (!field.checked) {
		setError(validator_div, ERROR_cHEcKBOX_NOT_cHEcKED);
		return false; // mark as dirty
	}
	
	clearError(validator_div);
	return true;
}

function validateDate(field, validator_div)
{
    //alert("day :" + day)
    //alert("month :" + month)
    //alert("year :" + )
	
	var dateStr = field.value;
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	var matchArray = dateStr.match(datePat); 

	if (dateStr == "")
	{		
		setError(validator_div, ERROR_INVALID_DATE);
		return false;
	}

	if (matchArray == null) 
	{
		setError(validator_div, ERROR_INVALID_DATE);
		return false;
	}

	day = matchArray[1];
	month = matchArray[3]; 
	year = matchArray[4];
    if (month < 1 || month > 12) 
	{ 
		setError(validator_div, ERROR_INVALID_DATE);
		return false;
	}

	if (day < 1 || day > 31) 
	{
		setError(validator_div, ERROR_INVALID_DATE);
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		setError(validator_div, ERROR_INVALID_DATE);
		return false;
	}

	if (month == 2) // check for february 29th
	{ 
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		
		if (day>29 || (day==29 && !isleap)) 
		{
			setError(validator_div, ERROR_INVALID_DATE);
			return false;
	   }
	}
	
	clearError(validator_div);
	return true;
}


function validatecheckboxList(field, validator_div)
{
	clearError(validator_div);
	
	for (var i=0; i<field.length; i++)
	{
		if (field[i].checked) return true;
	}
	
	if (field.checked) return true; // incase there's only one checkbox, it's not an array
	
	setError(validator_div, ERROR_INVALID_MuLTI_SELEcTION);
	return false; // mark as dirty
}

// Validates a User name (english letter and numbers)
function validatePhone(field, validator_div)
{
 	var valid_chars = "0123456789- ";
 	var str = field.value;
 	
 	for (var i=0;i<=str.length;i++)
 	{
 		//alert(str.indexOf(str.charAt(i), valid_chars));
		if (valid_chars.indexOf(str.charAt(i)) == -1)
		{
			setError(validator_div, ERROR_INVALID_PHONE);
			return false; // mark as dirty
		}
	}
	
	clearError(validator_div);
	return true;
}

function joinField(srcArray, dest, field_type)
{	
	var s = "";

	for (i=0; i < srcArray.length; i++)
	{
		switch (field_type)
		{
			case FIELD_TYPE_cHEcKBOX: if (srcArray[i].checked) s = s + srcArray[i].value + ", "; break;
			case FIELD_TYPE_SELEcT: if (srcArray[i].selected) s = s + srcArray[i].value + ", "; break;
		}
	}
	
	if (s != "") s = s.substr(s, s.length-2);
	
	dest.value = s;
}

function selectByValue(field, val)
{
	for (var i=0; i<field.options.length; i++)
	{
		if (field.options[i].value == val) field.selectedIndex = i;
	}
}

function selectAll(field)
{
	for (var i=0; i<field.options.length; i++)
	{		
		field.options[i].selected = true;
	}
}

function checkByList(field, list)
{
	var arr = list.split(", ");
	
	for (var i=0; i<field.length; i++)
	{
		for (var j=0; j<arr.length; j++)
		{
			if (field[i].value == arr[j]) field[i].checked = true;
		}
	}
	
}

function checkLuHN(num){
 
    var sum = 0;
    var d;
    
    if (parseInt(num) == 0) return false;
    
    while (num.length < 9) num = "0" + num;    
    
    for (var i=0; i<num.length; i++)
    {		
		d = parseInt(num.substring(i, i+1));
		c = (i%2+1)
		
		if (d*c > 9)		
			sum = sum + (d*c)%10+1;
		else
			sum = sum + (d*c);						
	}
            
    if (sum % 10 == 0)
		return true;
	else
		return false;
}

function checkShortIsracard(num){
 
    var sum = 0;
    var d;
    
    if (parseInt(num) == 0) return false;
    
    while (num.length < 9) num = "0" + num;    
    
    for (var i=0; i<num.length; i++)
    {		
		d = parseInt(num.substring(i, i+1));
		c = 9-i
		sum = sum + (d*c);		
	}
            
    if (sum % 11 == 0)
		return true;
	else
		return false; 
}

// clears an HTML form, clears all text fields and selections.
function clearHtmlForm(form)
{
	var e;
	
	for (var i=0; i < form.elements.length; i++)
	{				
		e = form.elements[i];
		
		if ((e.tagName == "INPuT") && (e.type == "text")) e.value = "";
		if ((e.tagName == "INPuT") && (e.type == "password")) e.value = "";
		if ((e.tagName == "INPuT") && (e.type == "checkbox")) e.checked = false;
		if ((e.tagName == "INPuT") && (e.type == "radio")) e.checked = false;
		if (e.tagName == "TEXTAREA") e.value = "";
		if (e.tagName == "SELEcT") e.selectedIndex = 0;
	}
}

function addParam(controlText, paramName, paramValue)
{	
	return "<param name='" + paramName + "' value='" + paramValue + "'>";
}

function createFlash(DivID, ObjectID, WIDTH, HEIGHT, MOVIE)
{  
	var s = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553600000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" + WIDTH + "' height='"+HEIGHT+"' id='"+ObjectID+"'>";
	
	s += addParam(s, "movie", MOVIE);
	s += addParam(s, "uiMode", "none");
	s += addParam(s, "wMode", "transparent");	
	s += "<EMBED wmode='transparent' src='" + MOVIE + "' quality=high width='" + WIDTH + "'height='" + HEIGHT + "' TYPE='application/x-shockwave-flash' "
	  +  "PLuGINSPAGE='http://www.macromedia.com/go/getflashplayer'> </EMBED>";	
	s += "</object>"
	
	document.getElementById(DivID).innerHTML += s;	
}		

function sendToFriend(str)
{
	opencenterWnd('send_to_friend.asp?site_lan='+str+'&url=' + escape(window.location.href), 450, 298, '', true, '');
}	  

function sendMail(str,reciver,responseto,sender)
{
	opencenterWnd('send_mail.asp?site_lan='+str+'&reciver='+ reciver +'&responseto='+ responseto +'&sender='+ sender +'&url=' + escape(window.location.href), 450, 298, '', true, '');
}	  

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b>'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}



// Use this function to save a cookie.
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" +
((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";               
var dc = document.cookie;             
    if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
        if (begin != -1) {           
        begin += cname.length;       
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
return null;
}

// Function to retrieve form element's value.
function getValue(element) {
var value = getCookie(element.name);
    if (value != null) element.value = value;
}

// Function to save form element's value.
function setValue(element) {
setCookie(element.name, element.value, exp);
}

//Sets the exp date to 31 days
var exp = new Date();                                   
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31));

// Use this function to delete a cookie.
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
