//
 //
 // Copyright 2000 by Dixite, 
 // 179 Av. Louise, Brussels, Belgium.
 // All rights reserved.
//
//
 // Creation
 //    @Project idixite : Dixite - Internal Development
 //    @Author  "Arnauld Van Muysewinkel" <avm@dixite.com>
 //    @Date    2000-08-29 15:25:54
 // Last Modification
 //    @Author  $Author: rna $
 //    @Date    $Date: 2001-03-17 14:48:52+00 $
 //    @Version $Revision: 1.11 $
 //    @File    $RCSfile: generic.js,v $
 //
 // Revision history at end of file
//

function submit_form(formName) {
	num =  eval("window.document." + formName + ".submit()");
}

function reset_form(formName) {
	num =  eval("window.document." + formName + ".reset()");
}

function edit_object(id,formName,objectName) {		
	num =  eval("window.document." + formName + ".edit_id.value='" + id + "'");
	num =  eval("window.document." + formName + ".action='admin_edit_" + objectName + ".cfm'");
	num =  eval("window.document." + formName + ".submit()");
}

function add_object(formName,objectName) {		
	num =  eval("window.document." + formName + ".action='admin_add_" + objectName + ".cfm'");
	num =  eval("window.document." + formName + ".submit()");
}

function delete_object(formName,objectName,confirmMessage) {
	var idList = "";
	looplen = eval("document." + formName + ".elements.length");
	for (i=0;i<looplen;i++) {
		if( ( eval("window.document." + formName + ".elements[i].checked == true") ) && ( eval("window.document." + formName + ".elements[i].type == 'checkbox'") ) ) {
			if(idList != "")
				num = eval("idList = idList +  \",\" + window.document." + formName + ".elements[i].value");
			else 
				num = eval("idList =  window.document." + formName + ".elements[i].value");
		}
	}
	if(idList != "") {
        if( confirm(confirmMessage) ){
    		num =  eval("window.document." + formName + ".to_delete_id_list.value='" + idList + "'");
    		num =  eval("window.document." + formName + ".action='admin_" + objectName + ".cfm'");
    		num =  eval("window.document." + formName + ".submit()");
		}
	}		
}

function change_subcat_state(cb_id,formName) {
	name = "cb";
	arr = cb_id.split("_");
	for (i=1;i<arr.length - 1;i++) {
		if(arr[i] > 0) {
			name = name + "_" + arr[i];
		}		
	}	
	name = name + "_";
	len = eval("window.document." + formName + ".length");
	res = eval("window.document." + formName + "." + cb_id + ".checked");
    cb_name_test = eval("window.document." + formName + "." + cb_id + ".name");
			
	for (j=0;j<len;j++) {				
		cb_name = eval("window.document." + formName + ".elements[j].name");
		if ( (cb_name != cb_name_test ) && (cb_name.indexOf(name) != -1) && (typeof( eval("window.document." + formName + ".elements[j]") ) != "undefined") )
		{			
		    num = eval("window.document." + formName + ".elements[j].checked = res");														
		}
	}
}
	
function check_existence(fieldName,formName,Message) {
	fieldval = new String(eval("window.document." + formName + "." + fieldName + ".value"));
	RE = /^(\s*)$/g;
	fieldval = fieldval.replace(RE,"");
	if( fieldval == "" || fieldval == null) {
	    if (Message != "" ){
	 	    alert(Message);	
	 	}
	 	return false;	
	}
	else {
		return true;
	}
}

function save (formName,objectName) {
	var data_completed = false;
	num = eval("data_completed = check_" + formName + "_fields(formName)");
	if (data_completed) {		
		num = eval("window.document." + formName + ".action='admin_" + objectName + ".cfm'");
		num = eval("window.document." + formName + ".submit()");
	}	
}	

function save_and_next (formName,objectName) {
	var data_completed = false;
	num = eval("data_completed = check_" + formName + "_fields(formName)");
	num = eval("window.document." + formName + ".next.value=\"true\"");
	if (data_completed) {		
		num = eval("window.document." + formName + ".action='admin_add_" + objectName + ".cfm'");
		num = eval("window.document." + formName + ".submit()");
	}	
}	

function set_drop_down_list_size (select_object, values_object) {
	len = eval( select_object + ".length");
	for(i=1;i<len;i++) {		
		eval(select_object + ".options[i].text= " +  values_object +  "_" + i  + ".value")
	}
}

function escape_single_quotes(string) {
	RE = /\'/g;
	nstring = string.replace(RE,"\\\'");
	return nstring;
}

function return_string_in_simplequotes(string) {
	ret = "'" + escape_single_quotes(string) + "'";
	return ret;
}

function check_fileformat_vs_fileextension(indexedformats,indexedformatsextension,separator,format,filename,err_msg) {
    //this fucntion is used to verify if the file format of the file to be indexed correspond to the extension.
    //this in order to warn the user of a potential error.
    ret = true;
    indexedformats.toUppercase;
    format.toUppercase;
	if (indexedformats.indexOf(format) != -1){
	format_arr      = indexedformats.split(separator);
        formatext_arr   = indexedformatsextension.split(separator);
        //Suppposed that the 2 arrays have the same length
        for (i=0;i<format_arr.length;i++) {
    	    if (format_arr[i] == format){
    	    copyfilename = filename;
    	    RE = /(.*)\.(.*)?/g;
    	    rep1 = copyfilename.replace(RE,"$2");
    	    rep1 = '.' + rep1;
    	    if (rep1 != formatext_arr[i]){
    	        ret = window.confirm(err_msg);
    	        }
    	    i = format_arr.length + 1;
    	    }
    	}
   }
return ret;
}
function check_mail(from_address,formName,from_err_msg) {
	var ret = false;
	from_address_value = eval("window.document." + formName + "." + from_address + ".value")
	if(from_address_value != "" && from_address_value != null) {
		RE = /^(.*)@(.*)\.(.*)$/g;
		var res = RE.test(from_address_value);
		if(res) {
			ret = true;
		}
		else {
			 alert(from_err_msg);
			 ret = false;
		}
	}
	return ret;
}
