var objFormsAndCookiesArray = new Array();
	
	function objFormsAndCookies(formName,cookieName,cookieStrArray){
		this.formName = formName;
		this.cookieName = cookieName;
		this.cookieStr = cookieStr;
		this.cookieStrArray = cookieStrArray;
	}

	function cookieStr(){
		str = Get_Cookie(this.cookieName);
		return str;
	}
		
	function fcFillTheForms(){
		for(i=0 ; i<objFormsAndCookiesArray.length ; i++){
			for(j=0 ; j<document.forms[objFormsAndCookiesArray[i].formName].elements.length ; j++){
			//alert(document.forms[objFormsAndCookiesArray[i].formName].elements[j].name)
				for (jj=0 ; jj<objFormsAndCookiesArray[i].cookieStrArray.length ; jj++){
					//alert(document.forms[objFormsAndCookiesArray[i].formName].elements[j].type);
					if(document.forms[objFormsAndCookiesArray[i].formName].elements[j].name == objFormsAndCookiesArray[i].cookieStrArray[jj][0] && document.forms[objFormsAndCookiesArray[i].formName].elements[j].type != 'select-one'){
					//replace "+" with space
						var re = /\+/g; // /\+/g
						var tempvalue = objFormsAndCookiesArray[i].cookieStrArray[jj][1];
						var afterReplace = tempvalue.replace(re," ");
						if (document.forms[objFormsAndCookiesArray[i].formName].elements[j].type != 'radio'){
							if (document.forms[objFormsAndCookiesArray[i].formName].elements[j].refill != 'false'){
								document.forms[objFormsAndCookiesArray[i].formName].elements[j].value = afterReplace;
							}
						}
						if (document.forms[objFormsAndCookiesArray[i].formName].elements[j].type == 'checkbox'){
							if (document.forms[objFormsAndCookiesArray[i].formName].elements[j].refill != 'false'){
								document.forms[objFormsAndCookiesArray[i].formName].elements[j].checked = true;
							}
						}
						if (document.forms[objFormsAndCookiesArray[i].formName].elements[j].type == 'radio'){
							if (afterReplace == document.forms[objFormsAndCookiesArray[i].formName].elements[j].value){
								document.forms[objFormsAndCookiesArray[i].formName].elements[j].checked = true;
							}
						}
					}
					if(document.forms[objFormsAndCookiesArray[i].formName].elements[j].name == objFormsAndCookiesArray[i].cookieStrArray[jj][0] && document.forms[objFormsAndCookiesArray[i].formName].elements[j].type == 'select-one'){
						for(k=0;k<document.forms[objFormsAndCookiesArray[i].formName].elements[j].options.length;k++){
							if(objFormsAndCookiesArray[i].cookieStrArray[jj][1] == document.forms[objFormsAndCookiesArray[i].formName].elements[j].options[k].value){
								document.forms[objFormsAndCookiesArray[i].formName].elements[j].options[k].selected = true;
							}
						}
					}
				}
			}
		}
	}
	
	function createCookieObject(){
		var objcount = 0;
		for(i=0;i<arguments.length;i++){
			if(Get_Cookie(arguments[i]) != ""  && Get_Cookie(arguments[i]) != null){
				objFormsAndCookiesArray[objcount] = new objFormsAndCookies();
				objFormsAndCookiesArray[objcount].formName = arguments[i];
				objFormsAndCookiesArray[objcount].cookieName = arguments[i];
				objcount++
			}
		}
			if(objFormsAndCookiesArray.length>0){
				createCookieStrArray();
				fcFillTheForms();
			}
	}
	
	function createCookieStrArray(){
		for(jj=0; jj<objFormsAndCookiesArray.length ; jj++){
			tempstr =objFormsAndCookiesArray[jj].cookieStr();
				temparray = tempstr.split("&");
					for(i=0; i<temparray.length ; i++){
						temparray[i] = temparray[i].split("=");
						//alert(temparray[i][0]+ ' ' +temparray[i][1])
					}
		objFormsAndCookiesArray[jj].cookieStrArray = temparray;
		}
	}
	
/*##################################################*/
/*###### fill user form ############################*/

function fncFillUserFormValues(formname,cookieName){
	var str
	str = Get_Cookie(cookieName);
	str = str.split('&');
	for(i=0;i<str.length;i++){
		str[i] = str[i].split('=')
	}
	var re = /\+/g; // /\+/g
	for(i=0;i<str.length;i++){
		if(ajrIs.ns6){
			if(str[i][1] != undefined){
				str[i][1] = str[i][1].replace(re," ");
			}
			else{
				str[i][1] = '';
			}
		}
		else{
			str[i][1] = str[i][1].replace(re," ");
		}
	}
	
	for(i=0;i<document.forms[formname].elements.length;i++){
		for(j=0;j<str.length;j++){
			if(document.forms[formname].elements[i].name.indexOf(str[j][0]) != -1 && document.forms[formname].elements[i].type == 'radio'){
					if(document.forms[formname].elements[i].value == str[j][1]){
						document.forms[formname].elements[i].checked = 1;
					}
			}
			if(document.forms[formname].elements[i].name.indexOf(str[j][0]) != -1 && document.forms[formname].elements[i].type == 'text')
				document.forms[formname].elements[i].value = str[j][1];
				
		}
	}

}

